So, I'm in a bit over my head, and I feel like I'm very close to a solution, but it's just not working quite yet. Here's my situation:
I'm working with an Arduino microcontroller, and I'm attempting to write two Bash scripts (right now running in Mac OS X 10.6) which will (a) print all serial data coming out of the Arduino unit to the standard output, and (b) allow me to send serial data to the Arduino unit. These scripts will then be called using Adobe AIR's NativeProcess API to allow a tight integration between the Arduino unit and a Flex Adobe AIR application.
My two scripts are very simple -
Here's my WriteToSerial.sh script:
echo $1 > $2
($1 is obviously my string, $2 is the location of the serial port - currently /dev/tty.usbserial-A800eIUj)
And here's my ReadSerialOutput.sh script:
tail -f $1
($1 is the location of my serial port, currently /dev/tty.usbserial-A800eIUj)
When I call either of these scripts (or even if I just type the commands directly into the Bash console), my computer just hangs - I can type characters, but nothing happens until I Ctrl + C out of the process.
However, if I open the Arduino IDE and turn on the Serial Monitor, then tail -f
the port, close the serial monitor, and then echo "test" > serial port, everything works just great.
This suggests to me that opening the Serial Monitor within the Arduino IDE is somehow initializing the serial port, which in turn allows me to tail it with no problem. This in turn suggests to me that I'm simply failing to input some sort of initialization command. However, I've been searching high and low for days and can't seem to find anything that addresses this issue.
What is the solution?
Try / modify ttyecho:
http://www.humbug.in/2010/utility-to-send-commands-or-data-to-other-terminals-ttypts/
Maybe try some serial command line tool similar to serial-1.0.
See: Serial port loopback/duplex test, in Bash or C? (process substitution)
Check to see if sending data to / receiving data from the Arduino unit is working by using a different app such as Cornflake (serial terminal for Mac OS X) - instead of using the Arduino IDE & the Serial Monitor.
In addition, you may want to check out if you could benefit from switching to Xcode (in terms of debugging features, etc.).
See: Setting up Xcode to Compile & Upload to an Arduino ATMega328 (Duemilanove)
Try using the tool stty:
As always, read the manpage before applying the above.
cread
allows you to receive data. You may want to omitclocal
if you are using flow control. If you aren't sure what the above settings are, ask, and I can write up a more complete answer.