Ruby SerialPorts Gem
- by Seth Archer
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.