Problem to assign 2 identical serial ports

i have two identical usb-2-serial devices that i wanna assigned to fixed ports.

Bus 001 Device 025: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port / Mobile Phone Data Cable
  idVendor           0x067b Prolific Technology, Inc.
  idProduct          0x2303 PL2303 Serial Port / Mobile Phone Data Cable
  bcdDevice            3.00
  iManufacturer           1 Prolific Technology Inc.
  iProduct                2 USB-Serial Controller
  iSerial                 0 

  Bus 001 Device 022: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port / Mobile Phone Data Cable
  idVendor           0x067b Prolific Technology, Inc.
  idProduct          0x2303 PL2303 Serial Port / Mobile Phone Data Cable
  bcdDevice            3.00
  iManufacturer           1 Prolific Technology Inc.
  iProduct                2 USB-Serial Controller
  iSerial                 0 

the problem is how to assign them fixed to “ttyUSB1” and the other to “ttyUSB2” with an udev rule or something else. has someone a solution ?

i appreciate your help

You will have to identify a unique property for earch device.

 $ udevadm info /dev/ttyUSB0 
P: /devices/pci0000:00/0000:00:03.1/0000:02:00.0/0000:03:08.0/0000:04:00.1/usb3/3-3/3-3:1.0/ttyUSB0/tty/ttyUS>
M: ttyUSB0
R: 0
U: tty
D: c 188:0
N: ttyUSB0
L: 0
S: serial/by-path/pci-0000:04:00.1-usbv2-0:3:1.0-port0
S: serial/by-path/pci-0000:04:00.1-usb-0:3:1.0-port0
S: serial/by-id/usb-1a86_USB_Serial-if00-port0
E: DEVPATH=/devices/pci0000:00/0000:00:03.1/0000:02:00.0/0000:03:08.0/0000:04:00.1/usb3/3-3/3-3:1.0/ttyUSB0/t>
E: DEVNAME=/dev/ttyUSB0
E: MAJOR=188
E: MINOR=0
E: SUBSYSTEM=tty
E: USEC_INITIALIZED=38573650795
E: ID_BUS=usb
E: ID_MODEL=USB_Serial
E: ID_MODEL_ENC=USB\x20Serial
E: ID_MODEL_ID=7523
E: ID_SERIAL=1a86_USB_Serial
E: ID_VENDOR=1a86
E: ID_VENDOR_ENC=1a86
E: ID_VENDOR_ID=1a86
E: ID_REVISION=0264
E: ID_TYPE=generic
E: ID_USB_MODEL=USB_Serial
E: ID_USB_MODEL_ENC=USB\x20Serial
E: ID_USB_MODEL_ID=7523
E: ID_USB_SERIAL=1a86_USB_Serial
E: ID_USB_VENDOR=1a86
E: ID_USB_VENDOR_ENC=1a86
E: ID_USB_VENDOR_ID=1a86
E: ID_USB_REVISION=0264
E: ID_USB_TYPE=generic
E: ID_USB_INTERFACES=:ff0102:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=ch341
E: ID_USB_CLASS_FROM_DATABASE=Vendor Specific Class
E: ID_VENDOR_FROM_DATABASE=QinHeng Electronics
E: ID_MODEL_FROM_DATABASE=CH340 serial converter
E: ID_PATH_WITH_USB_REVISION=pci-0000:04:00.1-usbv2-0:3:1.0
E: ID_PATH=pci-0000:04:00.1-usb-0:3:1.0
E: ID_PATH_TAG=pci-0000_04_00_1-usb-0_3_1_0
E: ID_MM_CANDIDATE=1
E: DEVLINKS=/dev/serial/by-path/pci-0000:04:00.1-usbv2-0:3:1.0-port0 /dev/serial/by-path/pci-0000:04:00.1-usb>
E: TAGS=:systemd:
E: CURRENT_TAGS=:systemd:

This article on udev - ArchWiki is likely what you need to figure this out.

1 Like

unfortunately there is a problem. both are 100% identical, the only difference is the bus (where it is connected). if i unplug one, let’s say ttyUSB1 and plug it in again the previous assignment is not renumbered and the device is assigned to ttyUSB3. i want to prevent this. fyi i’m running several other serial ports actually, this causes some headache if i need to unplug one of them temporarily.

Is it possible to identify a connected device id, or a label, instead (assuming that info is known beforehand)?

1 Like

no because after shutdown the enumeration alters the device id’s. the devices are connected via usb-hubs. depending which connections on the hub are active while booting the id’s get assigned. they are not fixed. bringing up some more trouble by using them in vm’s.

That makes sense as they are identical so systemd increments the devname as the identity cannot be assured.

Assuming the USB hub do not change position and the device is connected to the same port then the DEVPATH will be the same.

Thus you should be able to use the DEVPATH as identifier for your the rule which attach the same DEVPATH using the specified DEVNAME

I have made extensive usage of this excellent page → Writing udev rules