How to bind serial devices to USB port with name?

Whenever we connect our serial device to our machine it get bound to available free USB port for example for first time when we attach a serial device it bind with /dev/USB0 . Next time when we attach the device if USB port 0 is not available then it get bind to /dev/USB1. This create a problem when we write a program to work with Arduino or any other devices.

To overcome this issue we can bind these devices with name so that we don’t have to worry about at which port it got attached. We can access the device with the name we have bind it.

To bind with name we require product id and vendor id of the device. To get the run the below command.

alpha@alpha-UDOO-x86:~$ lsusb
Bus 002 Device 003: ID 0bda:0411 Realtek Semiconductor Corp.
Bus 002 Device 002: ID 0bda:0411 Realtek Semiconductor Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 006: ID 1a2c:2d23 China Resource Semico Co., Ltd
Bus 001 Device 009: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Bus 001 Device 007: ID 16c0:0483 Van Ooijen Technische Informatica Teensyduino Serial
Bus 001 Device 004: ID 0bda:5411 Realtek Semiconductor Corp.
Bus 001 Device 002: ID 0bda:5411 Realtek Semiconductor Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

As we can see it listed all our serial devices attached to machine. So we are going to bind Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC with name my_device. And we can also see that the vendor id is 0403 and product id is 6001.

So to do that lets add some udev rules

alpha@alpha-UDOO-x86:~# cd /etc/udev/rules.d/
alpha@alpha-UDOO-x86:/etc/udev/rules.d# sudo vim 10-local.rules

and add the following to the file and save and exit.

ACTION==”add”, ATTRS{idVendor}==”0403″, ATTRS{idProduct}==”6001″, SYMLINK+=”my_device”

or we can all this with a single command

alpha@alpha-UDOO-x86:~# sudo echo “ACTION==”add”, ATTRS{idVendor}==”0403″, ATTRS{idProduct}==”6001″, SYMLINK+=”my_device”” > /etc/udev/rules.d/10-local.rules alpha@alpha-UDOO-x86:~# udevadm trigger

After doing this run the command udevadm trigger or restart the system now you can access your device with /dev/my_device.

Please leave a comment if you face any problem in doing so.

Leave a Reply

Your email address will not be published. Required fields are marked *