If your ruby serial port doesn’t read what’ you’re sending…
For that, I needed Serial communication within ruby. Thanks to ruby-serialport first steps went quite well. I could write OR read from and to Arduino easily. But for some reasons, writing AND reading using the same instance didn’t work out.
I used a simple ‘send-input-back’ sketch on the Arduino side. So every byte I’m sending is returned back. I checked with the Arduino IDE Serialmonitor and a simple Processing script – everything worked alright. But using ruby it was different. Writing to serial port worked okay, but reading from it was just random. Sometimes I read the response, sometime I didn’t – really, really weird. Some headaches and a lot of time testing I finally found the solution: just open two instances of the serial port. One for sending, one for reading – and, surprise, surprise – it works perfect! Who would have guessed that!? Strange..
// To be completed
port_write = Serialport.new()
port_read = Serialport.new()
Ok, continuing hacking, more soon…