Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting AT commands to microcom command under Linux

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

like image 841
Alex Avatar asked Aug 28 '12 14:08

Alex


2 Answers

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

like image 88
albertoiNET Avatar answered Sep 18 '22 14:09

albertoiNET


Im running the microcom in BusyBox v1.18.4 under SliTaz 4.0 & I duplicated the problem & then solved it. If youre going to emulate keyboard input at this level the takefile has to have a full CRLF after every line because the keyboard key transmits a ^M (0x0D). The Linux standard 0x0A written by most ASCII editors is not sufficient.

There are many ways to do it but I just created the takefile with an extra byte at the end of every line then used the ncurses-hexedit program to zap the byte to a 0x0D. I tested the above commands & got an OK response with the input taken from such a file.

Hope this helps.

like image 32
crabmelt Avatar answered Sep 16 '22 14:09

crabmelt