they intends to swap names /dev/ttyUSB0 <=> /dev/ttyUSB1. Is there some way to prevent this
Yes, by creating a custom udev rule file (but i suggest you don't directly mess with the device names).
I can't post the solution, but hopefully I can post a walkthrough for the technique to obtain one.
The trick is to distinguish the two different usb devices, which can be problematic for two identical devices (same Vendor:Model) that do not provide serial numbers.
Determine the differences.
[email protected]:~# udevadm info -a -n /dev/ttyUSB0 >catch0
[email protected]:~# udevadm info -a -n /dev/ttyUSB1 >catch1
[email protected]:~# diff catch0 catch1
8,9c8,9
< looking at device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0/tty/tt
yUSB0':
< KERNEL=="ttyUSB0"
---
> looking at device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB1/tty/tt
yUSB1':
> KERNEL=="ttyUSB1"
13,14c13,14
< looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.0/ttyUSB0
':
< KERNELS=="ttyUSB0"
---
> looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB1
':
> KERNELS=="ttyUSB1"
19,20c19,20
< looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.0':
< KERNELS=="1-1.2:1.0"
---
> looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.3/1-1.3:1.0':
> KERNELS=="1-1.3:1.0"
32,33c32,33
< looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.2':
< KERNELS=="1-1.2"
---
> looking at parent device '/devices/platform/orion-ehci.0/usb1/1-1/1-1.3':
> KERNELS=="1-1.3"
38c38
< ATTRS{devpath}=="1.2"
---
> ATTRS{devpath}=="1.3"
45c45
< ATTRS{devnum}=="7"
---
> ATTRS{devnum}=="8"
The one useful differing attribute above (there being no device serial number) is the devpath, which is related to the physical USB port our 'devices' are plugged into.
As long as we do not physically change where the USB devices are connected, this will remain consistent.
Create a suitably named rule file, e.g. '/etc/udev/rules.d/99-custom-usb-serial.rules'
SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", ATTRS{devpath}=="1.2", SYMLINK+="gadget0"
SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", ATTRS{devpath}=="1.3", SYMLINK+="gadget1"
You can use 'lsusb' to help fill in the idVendor and idProduct information above.
[email protected]:~# lsusb
Bus 001 Device 008: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 007: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 004: ID 0d8c:013c C-Media Electronics, Inc.
Bus 001 Device 003: ID 05e3:0726 Genesys Logic, Inc.
Bus 001 Device 002: ID 1a40:0101 TERMINUS TECHNOLOGY INC. USB-2.0 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Now regardless of the ttyUSB0/ttyUSB1 device designation you will get two symbolic links '/dev/gadget0' and '/dev/gadget1'
which will always be associated with the same physical usb device connection, simply use these as the device names for the serial ports in your application.
(use something more appropriate than 'gadgetX' in your setup

).