Ruby SerialPorts Gem
Posted
by Seth Archer
on Stack Overflow
See other posts from Stack Overflow
or by Seth Archer
Published on 2010-03-28T17:57:31Z
Indexed on
2010/03/29
5:03 UTC
Read the original article
Hit count: 616
Using Ruby SerialPorts Gem to interact with hardware. When I write a byte array to the hardware using a program called "Serial Port Monitor" the hardware responds correctly.
However, when I write the same byte array using ruby it doesn't work unless I do a read request just before the write request.
This device doesn't respond correctly with this
sp = SerialPort.new(args)
sp.write [200.chr, 30.chr, 6.chr, 5.chr, 1.chr, 2.chr, 0.chr, 244.chr]
But it does if I add a read request before the write. Like this
sp SerialPort.new(args)
sp.read
sp.write [200.chr, 30.chr, 6.chr, 5.chr, 1.chr, 2.chr, 0.chr, 244.chr]
This works, but I'm at a loss as to why. I should also add that the first snippet does work occasionally maybe 1/10 of the time.
© Stack Overflow or respective owner