Serialport script hangs during sp.gets

Hi ruby friends!

I’m using the ruby serialport library. The OS is windows.

I’m sending command strings over serial to an epson projector. The
projector then interprets and executes the command and returns a string
based on the results.

The serial port is receiving my commands when I print them, but the
program hangs and crashes when I call gets, getc, or readline on the
serial port. Example paste here:
http://rafb.net/p/GF6Ehz14.html

This isn’t a problem for commands like PWR ON and PWR OFF, since I can
just run those blindly and assume success. For commands like PWR? or
LAMP?, though, I need to see the return value.

The pastebin snippet isn’t very comprehensive, but I have tried MANY
variations of gets, getc, readline, and with several different
(relevant, not random) record separators.

Any ideas why it is hanging and not returning a string? FYI, it does
return a string when I access the projector from Hyperterminal or
telnet.

Thanks a lot!

Hi

in my experience Ruby serialport library for Windows is in most cases
not usable. I suppose the problem is Ruby’s implementation of threads
(green threads) under Windows.

For serial communication under windows I now use a RS-232/422/485
connections over Ethernet (i.e. Ethernet to serial) - so from windows
(Ruby) perspective I use TCP/IP communication which works fine.

BR Philipp

Jordan Applewhite schrieb:

in my experience Ruby serialport library for Windows is in most cases
not usable. I suppose the problem is Ruby’s implementation of threads
(green threads) under Windows.

Someone was telling me the same thing yesterday in #ruby-lang. He was
shocked that it was working at all with ruby 1.8.6. Nevertheless, it
seems to be working today! All I had to do was set a seemingly
arbitrary read_timeout value. With the timeout, serialport.gets just
returns whatever was in the input buffer.

For serial communication under windows I now use a RS-232/422/485
connections over Ethernet (i.e. Ethernet to serial) - so from windows
(Ruby) perspective I use TCP/IP communication which works fine.

Still, I’m very interested in your solution. Are you describing having
a cable with 8p8c on one end and dsub9 on the other, using ruby
networking lib to send the appropriate data? Could you post a link to
some example code, or perhaps specify the relevant ruby-doc pages?

Thanks! I appreciate your help!

Someone was telling me the same thing yesterday in #ruby-lang. He was
shocked that it was working at all with ruby 1.8.6. Nevertheless, it
seems to be working today! All I had to do was set a seemingly
arbitrary read_timeout value. With the timeout, serialport.gets just
returns whatever was in the input buffer.

Thanks so much for posting the response. You saved my day!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs