Monday, November 18, 2019

Fix USB serial adapters to static device names on Ubuntu

When a USB to serial device adapter are plugged into a computer's USB port, the Ubuntu Linux OS automatically assigns a default system device name to it. Typically, it is /dev/ttyUSB0, /dev/ttyUSB1, and so on. This is convenient but sometimes it may be necessary to fix a specific device name to a specific USB serial adapter. This can be done by defining a rule file as shown in the steps below.

Identify the USB serial adapter's product and vendor codes
  1. Open up a Terminal. Physically plug in the USB serial adapter to the computer's USB port. Type in the following command:

    $ dmesg | grep ttyUSB
    The device messages with the string ttyUSB are displayed.

  2. Note which default device name has been assigned. In this case it is /dev/ttyUSB0.

  3. Type in the following command to print out the attributes of the device.

    $ udevadm info --name=/dev/ttyUSB0 --attribute-walk

    The attributes are printed out.

  4. Scroll and look for the idProduct and idVendor attributes.


  5. Note down the codes for the idProduct and idVendor attributes. In this case, the codes are ea60 and 10c4 respectively.
Define a rule to rename the USB serial adapter device
  1. In a text editor, create a rule file e.g. 50-usb-serial.rules. Type in the following line:

    SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="my_device_name"

    Note: replace the idVendor and idProduct and the my_device_name with the appropriate values.

    An example file listing:

  2. Place the rule file in /etc/udev/rules.d/. Note: you need to place it as the super user.
Activate the rule
  1. This can be done by restarting the computer.
  2. Alternatively, run the following command in a Terminal:

    $ sudo udevadm trigger
  3. To see whether it has been renamed, type in the following command:

    $ ls -l /dev/my_device_name

    Note: replace my_device_name with the name you defined in the rule file.

    The USB serial device has been renamed accordingly as a symbolic link.

No comments:

Post a Comment