Redirecting AT commands to microcom command under Linux

Alex picture Alex · Aug 28, 2012 · Viewed 13.2k times · Source

in the BusyBox command for Linux exists the command microcom to communicate with a serial modem:

BusyBox v1.13.2 (2012-05-10 17:13:08 CEST) multi-call binary

Usage: 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

Instead of using stdin to type the AT commands I want to place them insise a text file and redirect the content of that file as the stdin for the above command. For example, I have a file

/tmp/at.txt

with the AT command AT, which usually gets confirmed by the TTY with an OK. A standard session with stdin looks like:

microcom -t 3000 -X /dev/ttyS5                                 
at
OK

in which the string at was entered directly on the keyboard. In order to use the content of the file /tmp/at.txt (contains just 'at\n'). To do this,. I have tried the following variations:

microcom -t 3000 -X /dev/ttyS5  < /tmp/at.txt   
microcom -t 3000 /dev/ttyS5  < /tmp/at.txt 
cat /tmp/at.txt |  microcom -t 3000 /dev/ttyS5
tail -f  /tmp/at.txt |  microcom -t 3000 /dev/ttyS5
cat /tmp/at.txt |  microcom -t 3000 /dev/ttyS5 -X
tail -f  /tmp/at.txt |  microcom -t 3000 /dev/ttyS5 -X

and none of them worked, i.e. none of those commands did return the text 'OK' on the screen. I therefore conclude that there is some problem redirecting the content of the file /tmp/at.txt as stdin for the command microcom. Maybe is has to do with how the end-of-line is interpreted or the end-of-file. If someone has some idea, I would appreciate some help.

Thanks,

Alex

Answer

albertoiNET picture albertoiNET · Sep 15, 2015

You need end AT COMMANDS with special character \r

echo "AT+CIMI\r" | microcom -t 2000 /dev/ttyS5

With \n it doesn't work

Grettings