cbashhyperlinkttylsusb

How can I link the result of lsusb devices to /dev/ttyUSB*


I have the vendor and product code of a USB product: 0403:6001

I would like to know how can I link easily the result of lsusb command with the determination of a device on /dev/ttyUSB*

lsusb give me

Bus 001 Device 004: ID 065a:a001 First device 

Bus 001 Device 003: ID 0403:6001 Second device FT232 USB-Serial (UART) 

Bus 001 Device 002: ID 05e3:0610 Genesys Logic, Inc. 4-port hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

How can I know if this device is on /dev/ttyUSB0 or 1 or 2 If I have several USB Devices on my PC

Thanks in advance

Background def : The configuration is not the same at everytime

The USB Device can be plugged or unplugged and others devices too ...


Solution

  • Assuming you have udev:

    shopt -s nullglob
    for i in /dev/ttyUSB*; do 
      udevadm info -r -q all "$i" | awk -F= '
         /DEVNAME/{d=$2}
         /ID_VENDOR_ID/{v=$2}
         /ID_MODEL_ID/{m=$2}
         d&&v&&m{print d,v":"m;d=v=m=""}
      '
    done
    

    udevadm is the command to get all information about the usb device. The awk command just filters the USB path and class.