24

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?

15

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.

| improve this answer | |
  • did you do anything to make it list also the PRODUCT ? – Igor Stoppa Mar 6 '15 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 '17 at 20:15
12

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

| improve this answer | |
  • Can you add some clarifications, examples, etc. Oneline answer do not count as good in SE – Romeo Ninov Jul 21 '17 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 '17 at 11:27
  • 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 '18 at 8:40
6

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.

| improve this answer | |
  • 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 '18 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 '18 at 12:59
4

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
| improve this answer | |
1

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.

| improve this answer | |

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.