Linux – How to match a ttyUSBX device to a usb serial device

linuxusb

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?

Best Answer

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.

Related Question