3

I have problem sending AT commands to my USB modem. At first I tried php-serial class, but when I was reading data, I got endless loop with strange data. Then I tried to debug problem and opened putty terminal, made command

cat /dev/ttyUSB0

and then sent command echo "AT" > /dev/ttyUSB0 after that I always got never ending loop from cat /dev/ttyUSB0 like this:

AT
AT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^JAT^

and this loop never ends. On Windows all works just fine. I can connect to USB modem via virtual COM port and send command / get answer.

Question is why can't I just receive "OK" message from console, but instead of this I got this data loop?

Tried different huawei USB modems, and different stty settings and also default settings for huawei modems:

Baud rate: 9600 / 115200
Parity: none
Data bits = 8
Stop bits = 1
Flow control = none


test dev # uname -a
Linux test 3.5.7-gentoo #3 SMP Sun Feb 17 04:58:22 EET 2013 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ AuthenticAMD GNU/Linux

compiled newer kernel: 3.6.11-gentoo and now when sending command:

echo "AT" > /dev/ttyUSB0

got result like:

OK
AT
OK
AT
OK
AT

it never ended, I terminated cat command, then sent other ( make call command ):

echo "ATDT 27789388;" > /dev/ttyUSB0

and got answer from cat without loop.

systest ~ # cat /dev/ttyUSB0
ATDT 27789388;


OK

so why tty terminal is acting so strange? maybe I don't know something about sending/reading data on serial ports?

if it can help then output of stty -a -F /dev/ttyUSB0 command is:

speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

5 Answers 5

2

Doing AT command communication from the command line with just plain shell operations is rather unreliable. I suggest that you try to use the program atinout which is specifically written to issue AT command from the command line:

$ echo AT | atinout - /dev/ttyUSB0 -
AT
OK
$
2

Use "ATE0" Before

echo "ATE0" > /dev/ttyUSB0

1

Check to see if modem-manager is running -- and kill it if it is.

If it thinks that the device is a modem, it will step in and try to dial the modem also. This fixed as similar problem for me recently.

3
  • Looked in active processes, and there are nothing like this. in what package modem-manager is shipped ? I only have compiled kernel support for usb modems, and also installed "usb_modeswitch" so that it can switch usb device to modem state and open a /dev/ttyUSB* port. If i use kermit application to dial a number everything works fine in kermit, output is like it needs to be. I dont understand why lower level write/read isn't working
    – user991
    Commented Feb 20, 2013 at 4:07
  • 2
    Looks like the modem is echoing the command back to you (expected) but then the tty port is sending the command back to the modem and creating your endless loop. Try: stty -echo to prevent the port from echoing the commands back to the modem.
    – MikeV
    Commented Apr 16, 2013 at 23:34
  • If you're looking for it, modemmanager is closely linked to networkmanager - I think it's an extension to it or maybe part of the default package. On my systemd system I killed by symlinking /dev/null over the /etc/systemd/system modemmanager rule counterpart to /usr/share/systemd's default one...
    – mikeserv
    Commented Mar 18, 2014 at 21:43
1

Definitely look like your terminal setup is messed up. Check and play with these stty settings:

echo echoe echok -echonl -echoprt echoctl echoke

EDIT: The reason you got the AT - OK loop, is that you have enabled local terminal echo in both your terminal and on the modem side in the AT interpreter. To turn off echo in the AT interpreter, issue: ATE0 (that's a zero) as your first command.

0
0

The command:

stty -echo -F /dev/ttyUSB3

worked for me

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .