Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using two identical USB to serial adapter on my Linux system. So depends on who's inserted first, one of them will be represented with name /dev/ttyUSB0 and the other with /dev/ttyUSB1. Is there a trick I can make the name persistent? I have three USB port. Is it possible to link the name to the physical port?

Thanks,

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

If you run udevadm monitor --properties you should see the various properties you can use to create rules from. The ID_PATH property indicates the port the device was plugged into. Insert the serial to usb device to see what udev sees.

So it should be straightforward to create a udev rule that creates a symlink when the device is plugged in, something like:

SUBSYSTEM=="usb_device", SYSFS{idVendor}=="xxxx", SYSFS{idProduct}=="xxxx", ENV{ID_PATH}=="pci....usb-0:1:0",SYMLINK+="ttyUSBport0"
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="xxxx", SYSFS{idProduct}=="xxxx", ENV{ID_PATH}=="pci....usb-0:1:1",SYMLINK+="ttyUSBport1"

This is done from memory so you'll want to confirm the syntax. Change the idvendor and idproduct to the USB VID and PID, and change the ID_PATH to whatever you found in udevadm monitor.

This should leave the normal /dev/ttyUSB0 device there, but also create a symlink to it depending on which port it was plugged into. If you use the symlink in minicom or whatever you are using, you'll always get the right adapter based on the port you plug it into.

share|improve this answer
    
thanks. Is IDPATH tied to the physical port and doesn't change ever? –  lang2 Nov 23 '11 at 8:22
    
Yeah it is the physical path of the usb controller as it connects to the PCI bus I believe. It could only change if it were a add-on board and you changed the slot it was in I think. –  Paul Nov 23 '11 at 8:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.