I have a tiny shell script that writes to a serial device:
#!/usr/bin/ruby
require 'rubygems'
require 'serialport'
@sp = SerialPort.new "/dev/tty.usbserial-A6004cNN", 19200
@sp.write ["\x01\x01\x04\x00", "n", "\xff\xff\xff"]
This doesn't write to the serial device when I run ./script.sh
in that directory. However when I jump into IRB and run:
require 'serialport' #=> true
@sp = SerialPort.new "/dev/tty.usbserial-A6004cNN", 19200 #=> #<SerialPort:0x1016bd698>
@sp.write ["\x01\x01\x04\x00", "n", "\xff\xff\xff"] #=> 8
This way works... I'm baffled. Could it be the way i'm outputting my byte array? That doesn't seem right, its just raw ruby here, doesn't have an dependancies that are obvious. Also the script doesn't throw an exception, it executes just fine, however the device just doesn't respond.
How would I go about debugging this? I'm not sure where to start.