How to identify multiple USB-serial adapters under Ubuntu 10.1

后端 未结 7 1336
无人共我
无人共我 2020-12-29 13:54

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 s

相关标签:
7条回答
  • 2020-12-29 14:33

    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:

    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.

    0 讨论(0)
提交回复
热议问题