How to find out which USB-RS232 device is on which tty?

后端 未结 3 1192
梦如初夏
梦如初夏 2021-01-30 03:36

I have two different USB devices based on the same USB-RS232 chips. When I plug those in the USB they are mounted to /dev/ttyUSB0...3

My problem is how, inside a script,

3条回答
  •  一个人的身影
    2021-01-30 04:14

    Find more info using sysfs:

    $ ls /sys/bus/usb-serial/devices/ -ltrah
    
    lrwxrwxrwx 1 root root 0 2012-02-07 22:17 ttyUSB0 -> ../../../devices/pci0000:00/0000:00:0f.4/usb2/2-2/2-2:1.0/ttyUSB0
    
    $ ls -ltrad /sys//devices/pci0000:00/0000:00:0f.4/usb2/2-2/2-2:1.0/ttyUSB0
    drwxr-xr-x 4 root root 0 2012-02-07 22:17 /sys//devices/pci0000:00/0000:00:0f.4/usb2/2-2/2-2:1.0/ttyUSB0
    
    $ ls -ltrad /dev/ttyUSB0 
    crw-rw---- 1 root dialout 188, 0 2012-02-01 00:17 /dev/ttyUSB0
    

    Of course, the linked devices/... node contains a lot of information

    Adding information based on the OP's comment:

    The device number keeps growing if devices are removed/inserted. lsusb -t can be used to correlate the device numbers with usb bus/port.

    Then, 'lsusb -d devID' can determine what device is on which port. Finally 'ls /sys/bus/usb-serial/devices/ -ltrah' will list (by bus/port) where it was mounted.

    Not very convenient, but it 'works'

提交回复
热议问题