Skip to content

Instantly share code, notes, and snippets.

@sirleech
Created May 8, 2012 00:34
Show Gist options
  • Select an option

  • Save sirleech/2631676 to your computer and use it in GitHub Desktop.

Select an option

Save sirleech/2631676 to your computer and use it in GitHub Desktop.
How to identify multiple USB-serial adapters under Ubuntu 10.1

http://forums.opensuse.org/english/other-forums/development/programming-scripting/440104-finding-out-dev-ttyusbn-device.html

http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/

List USB Devices

lsusb

Find serial number of a USB device

udevadm info -n /dev/ttyUSB0 -a

http://stackoverflow.com/questions/4800099/how-to-identify-multiple-usb-serial-adapters-under-ubuntu-10-1

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:

ACTION=="add", KERNEL=="ttyUSB[0-9]*", PROGRAM="/etc/udev/rules.d/usb-parse-devpath.pm %p", SYMLINK+="usb-ports/%c"

And the usb-parse-devpath.pm script:

#!/usr/bin/perl -w

@items = split("/", $ARGV[0]);
for ($i = 0; $i < @items; $i++) {
    if ($items[$i] =~ m/^usb[0-9]+$/) {
        print $items[$i + 1] . "\n";
        last;
    }
}

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:

$ udevadm info --query=path --name=/dev/ttyUSB0
/devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/ttyUSB0/tty/ttyUSB0

So, the bus_id is 3 and port_id is 1 and now I have following in my /dev/usb-ports:

$ ls -al /dev/usb-ports
lrwxrwxrwx  1 root root   10 Май 12 00:26 3-1 -> ../ttyUSB0

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment