I keep getting Error when sending AT commands using a USB modem on ubuntu

2.3k Views Asked by At

I've a USB modem and a GSM card plugged in, hoping to communicate with it. I installed minicom and atinout, and used this command in minicom:

AT+CUSD=1,"*137#",15 
ERROR

and on atinout also I did :

$ atinout - /dev/ttyUSB3 - < <(echo "AT+CUSD=1,\"*137#\",15")
ERROR

notes:

  • using modem manager GUI the USSD commands and AT are running well
  • and on atinout it used to work few days ago and then it refused working hardware version :

    Manufacturer: TCT Mobile International Limited Model: HSPA Data Card Revision: IX1B5400XX

1

There are 1 best solutions below

0
On

If a device works in some terminal emulators but not others, then the terminal is probably set up incorrectly ("Incorrectly" meaning "different from how the device on the other side of the connection is configured"; there is no right or wrong.)

Usually the problem is one of baud rate, local echo, or LF vs CRLF line endings. You can configure how linux handles a tty device with stty (or setserial).

Example:

Here I use atinout to talk to a Telit DE910 "AUX" port via a UART.

$ echo 'AT+CREG?' | atinout - /dev/ttyO1 -
AT+CREG?
+CREG: 1,1

OK

So far so good. But this modem has supports multiple physical interfaces for each logical interface, and with my device logical port "AUX" is also available via /dev/ttyUSB2. In general I like to use /dev/ttyUSBn because at least some of the ridiculous number of options that can be set by stty are fixed. But in this case the defaults aren't good enough for atinout even though we are issuing the same commmand to the same logical port:

$ echo 'AT+CREG?' | atinout - /dev/ttyUSB2 -
AT+CREG?


+CREG: 1,1



OK

AT+CREG


ERROR

^C

The extra CRLFs are the give-away in this case, and configuring the terminal with stty raw fixes it. (In my case -icrnl was the only part of raw actually needed.)

$ stty -F /dev/ttyUSB2 raw
$ echo 'AT+CREG?' | atinout - /dev/ttyUSB2 -
AT+CREG?
+CREG: 1,1

OK

The problem with using stty is you've changed the device for everybody else. You can use stty to save the initial configuration so that you can restore it when you are done.

$ OLDSETTINGS=$(stty -g -F /dev/ttyUSB2)
$ stty -F /dev/ttyUSB2 -igncr -icrnl -ixon -ixoff 
$ stty -F /dev/ttyUSB2 "$OLDSETTINGS"

Finally I recommending using timeout with atinout to avoid a hang when the modem doesn't respond the way atinout is expecting.

$ echo 'AT+CREG?' | timeout -t5 atinout - /dev/ttyUSB2 -