Serial USBport number change after restart

Hi

I have a Huawei mPCIe modem with 5 USB ports, ttyUSB0 - ttyUSB4.
Then I installed a FTDI USB to serial adapter, ttyUSB5.
But after I restarted the router the FTDI adapter "steals" ttyUSB0 and my modem scrips fails.

Can I map my Huawei modem so it always use ttyUSB0 - ttyUSB4, or do I need to solves this in my script?

I think this topic has been discussed in an other thread, but I can´t find the thread.

No, the ttyUSBx order is dependent on the Linux kernel and the order of enumeration. You cannot change this behavior to have fixed ids.

Instead, the best way to handle the situation is to us lsusb or other similar tools to prove the PID/VID of each usb device and then talk to the one you want based on that info.

2 Likes

Ok

Is there any "best practice" how to find out which USBport number is used to a specific device?
Or is it just to run grep on dmesg?

[    6.959310] cdc_ether 2-1:2.0 wwan0: register 'cdc_ether' at usb-0000:00:13.2-1, Mobile Broadband Network Device, 02:1e:10:1f:00:00
[    7.000929] usbserial: USB Serial support registered for GSM modem (1-port)
[    7.008395] option 2-1:2.2: GSM modem (1-port) converter detected
[    7.014760] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB0
[    7.021776] option 2-1:2.3: GSM modem (1-port) converter detected
[    7.028071] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB1
[    7.035082] option 2-1:2.4: GSM modem (1-port) converter detected
[    7.041387] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB2
[    7.048381] option 2-1:2.5: GSM modem (1-port) converter detected
[    7.054683] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB3
[    7.061691] option 2-1:2.6: GSM modem (1-port) converter detected
[    7.067981] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB4

It´s the first USBport I should use in my script.
dmesg | grep 'GSM modem' | grep 'usb ' | awk 'NR==1' | awk -F 'ttyUSB' '{print $NF}' -> 0