1

I have more than 2 serial devices enumerated by FTDI driver as /dev/ttyUSB0, /dev/ttyUSB1, /dev/ttyUSB2 etc. On reboot, these may get jumbled up in any other order. Also, I may replace/swap these devices physically among these or with some other similar device.

Now, I want a persistent enumeration for these. I want the device names to be enumerated according to the physical USB port (I may connect to the USB ports on the motherboard of the PC directly or use a USB hub) that the device is connected to - say if the devices are connected to the USB hub, port 1 should be reserved to named as ttyUSB0, port 2 as ttyUSB1 and so on.

After some basic reading, I figured (as mentioned here) that /dev/serial/by-path/ lists the devices as sort of a symlink. So, I created a file /etc/udev/rules.d/101-usb-serial.rules with the following:

KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", DRIVERS=="ftdi_sio", PATH=="pci-0000:00:14.0-usb-0:10.1:1.0", SYMLINK+="ttyUSB000"
KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", DRIVERS=="ftdi_sio", PATH=="pci-0000:00:14.0-usb-0:10.2:1.0", SYMLINK+="ttyUSB001"
KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", DRIVERS=="ftdi_sio", PATH=="pci-0000:00:14.0-usb-0:10.3:1.0", SYMLINK+="ttyUSB002"

But this doesn't work. On doing ls /dev/ttyUSB* I'm unable to see the new symlinks I have created. What could possibly be going wrong?

  • 1
    There is no PATH key. Look at the output for udevadm info /dev/ttyUSB0 while it is plugged in. You can then probably use the ID_PATH value. Since this is prefixed by E: you need to look for it with ENV{...}. – meuh Sep 11 at 19:09
  • I tried replacing PATH with ENV{ID_PATH}. It didn't work as well. – skrowten_hermit Sep 12 at 4:59
2

Taking cues from the comment above I managed to find a solution to the above.

udevadm info /dev/ttyUSB0 | grep "ID_PATH="

The above lists the the sysfs path for the port that /dev/ttyUSB0 is connected to. Use this value to create rules for as many devices (ttyUSB1, ttyUSB2....) as you want in the rules file, say /etc/udev/rules.d/101-usb-serial.rules as follows:

SUBSYSTEM=="tty",ENV{ID_PATH}=="pci-0000:00:14.0-usb-0:10.1:1.0",SYMLINK+="ttyUSB001"
SUBSYSTEM=="tty",ENV{ID_PATH}=="pci-0000:00:14.0-usb-0:10.2:1.0",SYMLINK+="ttyUSB002"
SUBSYSTEM=="tty",ENV{ID_PATH}=="pci-0000:00:14.0-usb-0:10.3:1.0",SYMLINK+="ttyUSB003"

Once done making changes or creating the file, run the following:

sudo udevadm control --reload-rules
sudo /etc/init.d/udev restart

P.S. : The above example scenario (the one that I am using) is using a 4-port Belkin USB hub. Device 1 is connected to the port 1 of the hub Device 2 is connected to the port 2 and so on.

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.