I am reading data from multiple identical USB-serial adapters under Ubuntu 10.1.
On occasion, their /dev/tty path changes (eg if other USB devices are connected on startup).
I need a way of repeatedly referring to the same adapter through any such changes.
The devices all have the same serial numbers, according to udevadm.
I think the most likely option is to identify an adapter by which port it is connected to (they don't get moved around).
I can find all sorts of interesting /dev paths that might work, but despite all the discussion about udev online, I can't locate a definitive statement about whether some of these paths are static if the device is plugged into a static port.
There is a solution. It's better late then never ;)
Use the following
udev
rule to map/dev/ttyUSB{?}
devices into the/dev/usb-ports/%bus_id-%port_id
link.Here is my
/etc/udev/rules.d/usb-parse-devpath.rules:
And the
usb-parse-devpath.pm
script:As you can see this helps us to create named links to
/dev/ttyUSB{?}
devices and place them at/dev/usb-ports
in the following format:bus_id-port_id
.For example, the next command gives me the following:
So, the
bus_id
is3
andport_id
is1
and now I have following in my/dev/usb-ports
:Regards.
Much like Ilya Matvejchikov's answer, a good solution is to add udev rules to do what you want with the device. Like you, I was having a similar problem. I had a UPS on a USB-to-multi-serial adapter and occasionally the system would switch around the /dev/tty numbers.
My solution was to create a rule to match the type of device by driver and port, then create a symbolic link to the port to which my UPS was attached. I used NUT to monitor the UPS, which was always plugged into the same physical port.
Now I configure NUT to always use a constant /dev/nut-ups0, as the serial port and the rule takes care of mapping properly when the usb-serial device is recognized.
You can use the lsusb command to find out the actual device name to use in the rule when it's plugged in.
Look with
$ udevadm info -n /dev/ttyUSB0 -a
which port your USB device is plugged in. The variable KERNELS of one of the parent devices should be something like KERNELS=="1-1.2:1.0".Create a udev rule:
and trigger udev
I have many USB to Serial devices with each many ports and the solutions mentioned above did not quite did it for me.
The USB "KERNEL" was not enough in my case, but I found the port number.
I am aware that what I'm proposing now might be considered an insane hack, but it works for me..
for now..
I would actually be pleased to see a more elegant suggestion that accomplish something similar..
So... Based on the previous answer form Ilya Matveychikov
File: /etc/udev/rules.d/usb-parse-devpath.sh
And File: /etc/udev/rules.d/99-usb-serial.rules
The result look something like this:
I too was searching this topic for a way to find which physical USB device was assigned/connected to a logical /dev device name. So, after some trial and error, this is what worked best for me:
See what logical ttyUSBx devices exist (where x is 0, 1, 2...):
Show bus and device numbers for all usb-serial adapters:
Finally, use:
Now inspect the udevadm output to match the logical device name to the actual physical device. Here my listing when I did it:
So, in my case, ttyUSB0 is associated with the device on bus2, device5, which is the Future Technology Devices International USB to Serial Adapter; and likewise, ttyUSB1 is associated with the device on bus2, device4, which is the Prolific Technology, Inc. USB to Serial adapter.
And as has been pointed out, the command:
Will get you the same info in a one-line manner. I thought I'd post the details that helped me learn how the stuff worked behind the scenes...
Hope that was helpful :)
The usb-parse-devpath.pm addresses this by using the bus and port id of the adapter.