18

In Linux (Ubuntu) I am trying to send AT commands to a modem at /dev/ttyACM0. I tried to do it as:

sudo socat - /dev/ttyACM0

but when typing anything I just get a line repeating this command (I expect an OK).

When I do

sudo minicom modem1

it seems to work. I type an AT and get an OK. I type some crap, I get an ERROR.

It seems that modem1 for minicom is somehow configured to use the modem at /dev/ttyACM0.

How can I use socat to send AT commands? Do I need to configure something? Maybe I can use configurations for modem1 of minicom (I do not know how to find/see this configuration)?

Additional information

Is the given socat command correct? Should I play with some options? With the -v option I see the following:

AT
> 2013/10/23 17:10:28.917413  length=3 from=0 to=2
AT
< 2013/10/23 17:10:28.921598  length=3 from=0 to=2
AT
AT
ksjdhfjdgfhjkdfh
> 2013/10/23 17:10:30.244923  length=17 from=3 to=19
ksjdhfjdgfhjkdfh
< 2013/10/23 17:10:30.251383  length=29 from=3 to=31
ksjdhfjdgfhjk\b \bd\b \bf\b \bh\b \b
ksjdhfjdgfhj 

The device itself is found with the following dmesg output:

[5983726.808063] usb 2-1: USB disconnect, device number 3
[5983730.800021] usb 2-1: new full-speed USB device number 4 using uhci_hcd
[5983730.920014] usb 2-1: device descriptor read/64, error -71
[5983733.629524] usb 2-1: New USB device found, idVendor=0572, idProduct=1329
[5983733.629533] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[5983733.629539] usb 2-1: Product: USB Modem
[5983733.629544] usb 2-1: Manufacturer: Conexant
[5983733.629549] usb 2-1: SerialNumber: 24680246
[5983733.632673] cdc_acm 2-1:1.0: ttyACM0: USB ACM device

And the tty is configured as follows:

speed 57600 baud; line = 0;
eof = ^A; min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -echo -echoe
4
  • maybe you can get it working playing with these TERMIOS options but I never checked.
    – Alex
    Commented Oct 23, 2013 at 14:11
  • Search through this website looking for "socat modem" there are 5 hits, see if any of them are helpful. I do not have a setup to try these out on so I can't really help beyond that. (unix.stackexchange.com/search?q=socat+modem)
    – slm
    Commented Oct 23, 2013 at 14:32
  • The hints are not useful. I seem to have a real basic problem, because socat should work. It worked before. But I do not know what the problem is. Is the above command correct is my first question.
    – Alex
    Commented Oct 23, 2013 at 15:03
  • This may help Serial-port thermal printer communication
    – user.dz
    Commented May 2, 2014 at 19:28

5 Answers 5

18

Try socat - /dev/ttyUSB2,crnl

This tells socat to send a carriage return as well as a line feed.

Clarification - this goes back to the dark days of electric typewriters, where you would have to tell it to roll the carriage back to position 0 on the page - ergo, a carriage return - as well as telling it to move the paper up one line.

7

The best way to send AT commands to a modem in Linux is to use the program atinout which is written with the sole purpose of sending AT commands to a modem from the command line.

You can use it to test if a modem is up and running, make a backup of the phone book:

$ atinout - /dev/ttyACM0 ten_first_phonebook_entries.txt <<EOF
at+cscs="UTF-8"
at+cpbs="SM"; +cpbr=1,10
at+cpbs="ME"; +cpbr=1,10
EOF
$

or any other things you make use of AT commands for.

4

I came across this Chromium project post that shows what you want. It's titled: Debugging a cellular modem.

excerpt from that page

Communicating directly with a modem with the AT command set

Most modems support AT commands which control the modem and query for information. On a Chromium OS device with the developer mode enabled, you can use the socat command to communicate with the modem. You need a Chromium OS device with a test image installed (or you can use gmerge socat if you are familiar with the dev server) . For example:

  • Type CTRL+ALT+T to enter the crosh shell.
  • Type shell to enter the bash shell.
  • Figure you which USB device to use with: ls /dev/ttyACM* /dev/ttyUSB*
  • Stop modem manager if it is running: sudo stop modemmanager
  • Type sudo socat - /dev/ttyACM1,crnl or sudo socat - /dev/ttyUSB0 to communicate with the modem.
  • Ensure that the modem is enabled with the command: "AT+CFUN=1"

For example:

    crosh> shell
    chronos@localhost ~ $ sudo stop modemmanager
    chronos@localhost ~ $ ls /dev/ttyACM* /dev/ttyUSB*
    /dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2
    chronos@localhost ~ $ socat - /dev/ttyUSB1
    ATZ
    OK
    AT+CFUN=1
    OK
    ATI
    Manufacturer: Qualcomm Incorporated
    Model: ......
    Revision:....
    ESN: 0x80d...
    +GCAP: +CIS707A, ....

    chronos@localhost ~ $ 

Depending on the modem, you can try different AT commands, e.g. "AT+CGMI", "AT+CGSN", etc.

3
  • 1
    No AT command at all is working! This is my problem! Do I need to configure something? Is the commmand line ok? Do I do some big mistake?
    – Alex
    Commented Oct 23, 2013 at 15:09
  • @Alex - as I said I do not have any of this hardware so it's difficult to assist you beyond providing information like this. You'll have to debug it. I'd try power cycling the devices in question and see if they're in a hung state, look in the dmesg log for information. Sorry I can't assist you more than this.
    – slm
    Commented Oct 23, 2013 at 15:13
  • 1
    Can't you just echo "AT+DONTREMEMBERZMODEM" > /dev/modemtty?
    – mikeserv
    Commented Mar 24, 2014 at 1:05
2

Try this:

echo AT |  socat - /dev/ttyUSB1,crnl

This sends an AT command, returns the output and finally exits.

The linux command can be used for several AT commands in script with a delay of 1 second after each command. enter image description here

3
  • It does not return. It is the same as echo -ne "AT\r\n" > /dev/serial0 I will never see output "OK".
    – mikep
    Commented Aug 18, 2021 at 8:35
  • They are not the same . For my solution " echo AT | socat - /dev/ttyUSB1,crnl " there is always an output provided the serial port used is accurately selected and not under use.
    – james.s
    Commented Sep 6, 2022 at 3:07
  • This command must run with root user.
    – EsmaeelE
    Commented Sep 20, 2022 at 9:46
1

#TIL you could use screen for this purpose. Try

screen /dev/ttyACM0 57600,cs8,-parenb,-cstopb,-hupcl

From https://apple.stackexchange.com/a/318280/84497

1
  • I am not 100% sure screen in Mac OS is the same as screen in linux. Reading the screen manpage, it can act as a zmodem, but not fully.
    – number9
    Commented Jun 17, 2021 at 13:02

You must log in to answer this question.

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