1
votes

I want send AT commands to USB modem connected to raspberry pi. I have found some helps mentioning that USB modem is usually connected as ttyACM or ttyUSB device, but I have no ttyACM or ttyUSB device. I have devices from tty1 to tty63, but I do not know how to identify which one is used by the modem.

I have tried to find the device by storing devices list with the modem unconnected and then compare device list after the modem is pluged in:

ls /dev/ > dev_list_1.txt
(plug the modem in)
ls /dev/ | diff --suppress-common-lines -y - dev_list_.txt

returns to me:

bsg                               <
sda                               <
sg0 

I have tried to connect the modem with cu tool:

sudo cu -l sda
sudo cu -l sg0

but both returns:

cu: open (/dev/sg0): Permission denied
cu: sg0: Line in use

So I tried also use minicom and configure serial communication to /dev/sg0 or /dev/sda but it does not work either.

So I think I need to find right tty device used by the modem to be able to communicate with it. But how to find it?

1
Using the command lsusb -vvv will show you much information relating to USB devices connected to the machine you are running. Additionally, you may physical USB device hierarchy as a tree. Verbosity can be increased twice with v option... as the manual page says.brw
Thanks, it says many informations, unfortunately it does not say anything abut /dev/tty. I have tried lsusb -t already and it gives me info, that the modem is running on port 4, Dev 6. I also know idVendor and idproduct of the modem. but I do not know if it can be used for serial communication with the modem as every manual on net says "write to /dev/ttyACM0"Myk
You have used sudo raspi-config and enabled the interface?brw
Have you tried ls -l /dev/serial/by-id ?Mark Setchell

1 Answers

0
votes

You can look for /sys/class/tty/*/device entries and ignore all the links that points to serial8250 since those are not USB devices.

With shell script:

for device in /sys/class/tty/*/device
do
    case $(readlink $device) in
        *serial8250)    # e.g. ../../../serial8250
            ;;
        *)              # e.g. ../../../1-3:3.1
            echo $device | rev | cut -d/ -f2 | rev
            ;;
    esac;
done | sed 's@^@/dev/@'

which produces

/dev/ttyACM0
/dev/ttyACM1
/dev/ttyS0

with my phone connected. You might get more than the usb devices (e.g. ttyS0) but at least this should give you all the usb serial devices the kernel know about (and if the device does not populate /sys/class/tty/ it almost certainly is not a serial device).

This is based on the list_ports function logic in the libserialport library.