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,
This one-liner udev rule will give a fixed name (e.g. /dev/ttyUSB_A9YL5BJJ) based on serial number for any device with vendor/product ids as given.
Put this into a udev rules file e.g. /etc/udev/rules.d/60-ftdi-serial-names.rules
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ENV{ID_SERIAL_SHORT}=="?*", SYMLINK+="ttyUSB_%E{ID_SERIAL_SHORT}"
You can use udev to assign a stable symbolic link to each FTDI dongle. Use device and vendor to match the type, and then the serial number for the specific device. Then use the symbolic link in the script.
I named my dongles ttyFTDI0 etc., and wrote the numbers on the dongles with a marker:
$ cat /etc/udev/ftdi.rules SUBSYSTEMS=="usb", KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="FTDEN97D", SYMLINK+="ttyFTDI0" SUBSYSTEMS=="usb", KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A600b30P", SYMLINK+="ttyFTDI1" SUBSYSTEMS=="usb", KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A600bexU", SYMLINK+="ttyFTDI2" SUBSYSTEMS=="usb", KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="FTFMSA54", SYMLINK+="ttyFTDI3" SUBSYSTEMS=="usb", KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="FTFMUW4A", SYMLINK+="ttyFTDI4"
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
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'