[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Zach Dennis

2/7/2005 3:53:00 PM

Caleb,

This message showed up under another, thread perhaps you replied to a
message and just changed the subject heading. This makes it difficult
for certain mail clients and newsreaders to correctly organize the mail
in threads, next time could you compose a new email messsage to
"ruby-talk@ruby-lang.org", that way more people will see your email,
otherwise people may ignore the thread that this messages shows up under.

thx,

Zach



Caleb Tennis wrote:
> I've got a simple class that writes to a device on a serial port and then
> reads back a response:
>
> class SerialPort
> def write(port, arry)
> file = File.new(port, File::RDWR | File::NOCTTY )
> file.write(arry.pack("C*"))
> file.flush
> str = file.read(50).to_s.unpack("C*")
> file.close
> str
> end
> end
>
> (Usage: response = SerialPort.new.write("/dev/tts/5",
> [some_array_of_bytes]) )
>
> The class works fine for my program, until I go multi-threaded, which is a
> requirement.
>
> As soon as I do something this:
>
> Thread.new do
> response = SerialPort.new.write("/dev/tts/5, [some_array_of_bytes])
> end
>
> The thread hangs at the read() function. If I use the same code in the
> main thread it works fine. I thought at first I had resources that were
> conflicting, but I've written a test case which does nothing other than
> one call like seen above, and the only difference in working/not-working
> is whether the code is invoked in a new thread or not.
>
> Any thoughts on what I might be missing here? The serial port is set to
> raw mode, min 0 time 1, which means that it won't block on reads even if
> no data is present.
>
>
>
>