shinigamionpi
Posts: 2
Joined: Fri Jan 18, 2019 9:19 am

Persistent name(symlink) for USB serial ports

Fri Jan 18, 2019 11:28 am

Hi everyone,

I'm working on Raspberry Pi 2. I'm trying to give permanent names(symlink) to each 4 different usb serial ports independent of devices like '/dev/ttyMyPort0' for first, '/dev/ttyMyPort1' for second, '/dev/ttyMyPort2' for third and '/dev/ttyMyPort3' for fourth when they are active.

I tried to get it through the Udev rules, but I wasn't successful. I still get ttyUSB0 when I plugged DIGITUS USB 2.0 serial adapter to every port. Anybody know the solution? I'm working on raspberry for the first time and my first question on the forum.

If you want, I'll edit the post again for the necessary explanations. Thank you in advance for your help and attention.

Code: Select all


[b]lsusb[/b]
Bus 001 Device 009: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


User avatar
topguy
Posts: 5617
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Persistent name(symlink) for USB serial ports

Fri Jan 18, 2019 1:36 pm

What udev-rule did you try ?
Are you trying to map "name to specific device" or "name to physical USB port" ?? ( the last thing is near impossible btw. )

To give each device unique names its something like this in udev.

Code: Select all

KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{bcdDevice}=="0400", SYMLINK+="gps_int"
This is one I use for a FTDI usb2serial device. I had to differenciate between multiple models of this FTDI chip which is why I have a check on "bcdDevice" also. It may not work for you so you should remove it.

shinigamionpi
Posts: 2
Joined: Fri Jan 18, 2019 9:19 am

Re: Persistent name(symlink) for USB serial ports

Fri Jan 18, 2019 2:59 pm

Firstly, thank you! The gps_int was created under the /dev/ folder with the command you gave an example. But is ttyUSB0 still visible, is it normal?

Yes, I actually want to assign a static name to the each port. I want them to get fixed names when they're active.

Do I need to update the udev rule when the converter changes? Because idVendor and idProduct information may change. "The top left (1.) port is connected to a device and dev/ttyMyPort0 has been activated." How do I get information? I want to do this regardless of device information.

My code will work like this:

Code: Select all

serialLocation = '/dev/gps_int'
            FirstSerial = serial.Serial(
                port=serialLocation,
                baudrate=19200,
                parity=serial.PARITY_NONE,
                stopbits=serial.STOPBITS_ONE,
                bytesize=serial.EIGHTBITS
            )
            print("serial ok")


User avatar
topguy
Posts: 5617
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Persistent name(symlink) for USB serial ports

Fri Jan 18, 2019 4:44 pm

But is ttyUSB0 still visible, is it normal?
Yes. you get both names.. a SYMLINK is just a link from one name to another one. you can change "gps_int" name of course.

Linux doesnt really care much about portnumbers. Are there ways to figure it out ? yes, but I dont know of any that are perfect or even very portable. (someone else might know)

The command "lsusb -t" will give you some information, also the log messages in "dmesg" output gives you messages like this:

Code: Select all

[1406727.936712] usb 1-2: new full-speed USB device number 21 using xhci_hcd
And if I moved that device to another port:

Code: Select all

[1407205.797008] usb 1-1: new full-speed USB device number 22 using xhci_hcd
and in "/sys/bus/usb" or "/sys/bus/usb-serial" there is also a bunch of information that I dont know the exact structure for.

Return to “Troubleshooting”