USB to Serial
On Linux, do the serial ports of USB-COM get the same names when restarting?
In Microsoft Windows OS the driver for USB-xCOM devices checks the serial numbers of the installed USB-to-serial circuits, and this way always assigns the same name of COMnn to a certain port.
This function is not implemented in the driver software for Linux.
Usually, as long as you attach only one USB-xCOM device its /dev/ttyUSBx device name should remain the same across reboots/replugs. But sometimes due to the dynamic nature of USB enumeration, the device names can get messed up, for example the second group of serial ports in USB-8COM Plus may receive names from /dev/ttyUSB0-/dev/ttyUSB3 and the first group gets /dev/ttyUSB4-/dev/ttyUSB7 names. The same might happen when multiple USB-xCOM are connected to the system.
To avoid this, you can dynamically create symlinks based on USB topology using udev [1], [2]:
# 4xx/8xx FTDI mapping
KERNELS=="1-1.2:1.0", SUBSYSTEMS=="usb", ATTRS{interface}=="VScom USB-COM Plus", ATTRS{bInterfaceNumber}=="00", SYMLINK+="ttyVS0"
KERNELS=="1-1.2:1.1", SUBSYSTEMS=="usb", ATTRS{interface}=="VScom USB-COM Plus", ATTRS{bInterfaceNumber}=="01", SYMLINK+="ttyVS1"
KERNELS=="1-1.2:1.2", SUBSYSTEMS=="usb", ATTRS{interface}=="VScom USB-COM Plus", ATTRS{bInterfaceNumber}=="02", SYMLINK+="ttyVS2"
KERNELS=="1-1.2:1.3", SUBSYSTEMS=="usb", ATTRS{interface}=="VScom USB-COM Plus", ATTRS{bInterfaceNumber}=="03", SYMLINK+="ttyVS3"
KERNELS=="1-1.3:1.0", SUBSYSTEMS=="usb", ATTRS{interface}=="VScom USB-COM Plus", ATTRS{bInterfaceNumber}=="00", SYMLINK+="ttyVS4"
KERNELS=="1-1.3:1.1", SUBSYSTEMS=="usb", ATTRS{interface}=="VScom USB-COM Plus", ATTRS{bInterfaceNumber}=="01", SYMLINK+="ttyVS5"
KERNELS=="1-1.3:1.2", SUBSYSTEMS=="usb", ATTRS{interface}=="VScom USB-COM Plus", ATTRS{bInterfaceNumber}=="02", SYMLINK+="ttyVS6"
KERNELS=="1-1.3:1.3", SUBSYSTEMS=="usb", ATTRS{interface}=="VScom USB-COM Plus", ATTRS{bInterfaceNumber}=="03", SYMLINK+="ttyVS7"
Note: This method uses the physical location, i.e. the USB-port where the device is attached to. If you connect the USB-xCOM to an adjacent port the names may change.
You can use the following command to show device's attributes and topology information i.e. which /dev/ttyUSBx corresponds to which physical port:
udevadm info --attribute-walk --path=$(udevadm info --query=path --name=/dev/ttyUSB0)
The relevant part looks like this:
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1.2/1-1.2:1.0':
KERNELS=="1-1.2:1.0" ----> address in the USB tree
SUBSYSTEMS=="usb"
DRIVERS=="ftdi_sio"
ATTRS{authorized}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceClass}=="ff"
ATTRS{bInterfaceNumber}=="00" -----> interface number
ATTRS{bInterfaceProtocol}=="ff"
ATTRS{bInterfaceSubClass}=="ff"
ATTRS{bNumEndpoints}=="02"
ATTRS{interface}=="VScom USB-COM Plus" -----> product name string
ATTRS{supports_autosuspend}=="1"
Custom udev rules should be placed under: /etc/udev/rules.d/
[1] https://en.wikipedia.org/wiki/Udev
[2] https://wiki.archlinux.org/index.php/Udev
Tags: -
Related entries:
Last update: 2019-10-11 11:53
Author: Support
Revision: 1.1
You cannot comment on this entry