Sunday, September 21, 2008

reading and writing to a serial port

i am using an embedded board (x86) running dd-wrt, with a serial port connected to a counter see here .

I needed to send a command and collect its response, but normal cat and echo of ttyS0 didn't work, either giving me permission denied or missing the response.

this worked

/usr/local/usr/bin/socat gopen:/tmp/input.txt!!create:/tmp/output.txt /dev/tts/0,echo=0

where tts/0 is the serial port, and /tmp/input.txt has the command to elicit the response, and /tmp/output.txt catches the response. the create: clause makes it overwrite the output.txt each time you run the command

or explicitly for my board

socat exec:'echo ACA'\!\!- /dev/ttyUSB0,echo=0 | cut -b2-

No comments:

load testing