29

option driver correctly matched USB ID and loads driver for this device. For example

# lsusb
Bus 001 Device 002: ID 19d2:0031 ONDA Communication S.p.A. ZTE MF636
Bus 001 Device 003: ID 12d1:14ac Huawei Technologies Co., Ltd.

It also creates ttyUSBX devices for managing the hardware

crw-rw---- 1 root uucp 188, 0 Jul  4 13:48 /dev/ttyUSB0
crw-rw---- 1 root uucp 188, 1 Jul  4 13:49 /dev/ttyUSB1
crw-rw---- 1 root uucp 188, 2 Jul  4 13:35 /dev/ttyUSB2
crw-rw---- 1 root uucp 188, 3 Jul  4 13:37 /dev/ttyUSB3
crw-rw---- 1 root uucp 188, 4 Jul  4 13:37 /dev/ttyUSB4
crw-rw---- 1 root uucp 188, 5 Jul  4 13:37 /dev/ttyUSB5
crw-rw---- 1 root uucp 188, 6 Jul  4 13:37 /dev/ttyUSB6
crw-rw---- 1 root uucp 188, 7 Jul  4 13:37 /dev/ttyUSB7

However, I have more then one usb serial devices and I want to know which ttyUSB is for which USBID. Ex. /dev/ttyUSB1 -> 19d2:0031

Do you know any point where I can get this information?

2

5 Answers 5

20

Have a look at the sysfs filesystem. An example for my USB serial:

$ lsusb
Bus 003 Device 016: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
$ ls -l /sys/bus/usb-serial/devices
lrwxrwxrwx 1 root root 0 Jul  4 17:37 ttyUSB0 -> ../../../devices/pci0000:00/0000:00:1c.0/0000:02:00.0/usb3/3-1/3-1:1.0/ttyUSB0
$ $ grep PRODUCT= /sys/bus/usb-serial/devices/ttyUSB0/../uevent
PRODUCT=67b/2303/300

As you can see, ttyUSB0 maps to 067b:2303 on my computer. An other locations worth exploring are /sys/class/tty/. Pay attention to symlinks.

2
  • did you do anything to make it list also the PRODUCT ? Mar 6, 2015 at 10:02
  • @IgorStoppa, Try to cat the uevent file from the result of find /sys -name ttyACM0, for example. Substitute your serial device's node name.
    – sherrellbc
    Mar 29, 2017 at 20:15
20

You can try to see if your device(s) are registered under /dev/serial/by-id/

ls -l /dev/serial/by-id

These names should be consistent and will point (symlink) to the correct ttyUSBx

3
  • Can you add some clarifications, examples, etc. Oneline answer do not count as good in SE Jul 21, 2017 at 20:13
  • @RomeoNinov Ok, I added some clarification as you requested. This is not exactly more difficult than just looking into another directory, so I can't see how making the answer more elaborate than it is will improve anything. Sorry about that.
    – Waxhead
    Jul 22, 2017 at 11:27
  • 2
    I have two identical adapters (two Arduinos) connected to a Raspberry Pi. ls -l /dev/serial/by-id only returns one adapter ../../ttyUSB1, while ls -l /sys/bus/usb-serial/devices shows me both. So I don't think that this is a good answer.
    – Daniel F
    Oct 9, 2018 at 8:40
7

I had a similar problem.

Write this to /etc/udev/rules.d/50-usb.rules

SUBSYSTEM=="tty", ATTRS{idVendor}=="19d2", ATTRS{idProduct}=="0031", SYMLINK+="ONDA"
SUBSYSTEM=="tty", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="14ac", SYMLINK+="HUAWEI"

to the end. Reboot.

Now you can use /dev/ONDA to get to your ONDA device.

If you want non-root users to be able to use these, then add

, MODE="0666"

to the end of each line.

2
  • I did this and checked the files where they link to. the product I have has multiple interfaces, like solid disk, usb serial. While I expected the linkage to /dev/ttyACM0 but it was to /dev/sda. any way to define in rules file which device type the rule should apply? I wrote the rules in /etc/udev/rules.d/99-ftdi.rules
    – nurp
    Sep 26, 2018 at 12:53
  • ok found it: added SUBSYSTEM=="tty" to the rule parameters. this value can be found in the output of udevadm info --name=/dev/ttyACM0
    – nurp
    Sep 26, 2018 at 12:59
5

I would use udev and write some rules which create symlinks for the devices.

To get enough information to distinguish the devices try something like this for all devices:

$ udevadm info --query all --name /dev/ttyUSB0 --attribute-walk
2

The following commands will give me list of ttyUSB device names that are associated with 19d2:0016 (which is the "modem mode" id of a ZTE MF831 LTE stick, yours may differ.):

    for i in $(find -L /sys/bus/usb/devices/ -maxdepth 2 -name "ttyUSB*"); do
        egrep -i "v19d2p0016(.*)in02" $i/../modalias >/dev/null && echo "/dev/${i##*/}"
    done

This will loop through a list of files with filename ttyUSB*, including symlinks, in /sys/bus/usb/devices. Within the results we will search for a file named modalias and look for a string containing the vendor id "v" "19d2" and product id "p" 0016. If the output matches, we will echo a string prefixed with "/dev/" in front of the USB? name. Afaik the first or the usually the last (highest number) is the modem port for ZTE devices. You can echo the results to a file in /tmp/ and head -n1 or tail -n1 the lines accordingly. If you have hubs, you may probably need to increase maxdepth.

This isn't the most elegant way, but it will work on almost any Linux variant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.