From: Brian Candler Date: 2004-10-04T17:23:42+09:00 Subject: Re: Reinventing Telnet Servers for Serial Ports On Sun, Oct 03, 2004 at 01:24:47PM +0900, Siegfried Heintze wrote: > How can I write a similar OS vendor neutral program using ruby, > except, instead reading and writing to a process, I read and write to > serial port? Can I do this with a single thread? How do I read and > write to a serial port? Can anyone point me to some sample code for > serial port I/O? The module ruby-termios from RAA has examples of serial port I/O, and how to set things like the bit rate and start/stop bits. Beware: if you are using Linux, there is a serious bug with serial I/O and Ruby, which means that I/O blocks when it shouldn't. I reported this on ruby-talk and ruby-core, but nothing happened: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/111331 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/111330 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/3366 It works fine under FreeBSD though, so conceivably it's a Linux kernel problem. As for threads etc: it depends on the application. If you're copying data to a socket or to another process on stdin/stdout, then I'd use one thread to read and another to write. Ruby threads are simulated threads, using select() to determine when an FD is ready to read or write. That's as long as you don't get bitten by the thread/serial port bug above, of course. Regards, Brian.