15 January 2014

Talking to your modem under embedded linux

With the right drivers, modems chipsets show up as USB devices under linux, usually /dev/ttyACM*. When everything is working right, pppd just takes care of all of this an you have a nice easy ip layer. But when you are trying to figure out what your device is doing from the datasheet, you just want to type commands to the modem and get back its responses.

Googling for this resulted in approximately one billion ways to read and write from USB modems, including cat, cu, socat, getty, minicom, putty and, god help us, perl. These are distinguished by either a) not being bi-direction or b) not installed on a generic busybox-based embedded system. What you really want to use is microcom. It is built in to busybox, it works, and it's actually easier to use that most of the other options.




microcom
microcom [-d DELAY] [-t TIMEOUT] [-s SPEED] [-X] TTY
Copy bytes for stdin to TTY and from TTY to stdout
Options:
        -d      Wait up to DELAY ms for TTY output before sending every
                next byte to it
        -t      Exit if both stdin and TTY are silent for TIMEOUT ms
        -s      Set serial line to SPEED
        -X      Disable special meaning of NUL and Ctrl-X from stdin


The -t option is actually quite clever; it's very easy to disable control sequences and then get stuck. This bombs you out if nobody talks for x milliseconds. Example:

$ microcom -t 3000 /dev/ttyACM2

*EMRDY: 1
AT+CFUN=?
+CFUN: (0,1,4-6),(0,1)

OK

If you really want to use socat I guess you can. In the below I seem to have forgotten whatever magic option is required to make socat send CRLF instead of just LF, so it doesn't actually work.

D4-11-D6-00-00-16:~ $ socat - /dev/ttyACM2

*EMRDY: 1
AT



AT

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.