LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   USB (PL2303) reliable device names (https://www.linuxquestions.org/questions/linux-hardware-18/usb-pl2303-reliable-device-names-4175506134/)

Quakeboy02 05-26-2014 07:14 PM

USB (PL2303) reliable device names
 
The USB devices are proliferating on my machine; particularly PL2303 serial port devices. I would like to write a rule so that reliable device names are created using the bus and device numbers for these devices. For example, with the following two devices I would like to see something like /dev/ttyUSB4.4 and /dev/ttyUSB1.5. Could someone give me a hand with this?

Code:

Bus 004 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port


Quakeboy02 05-26-2014 09:10 PM

As often happens, I keep searching and find something that is at least close. I found an example at this webpage and modified it slightly. However, it doesn't separate devices on hubs. Any ideas to fix that?

http://stackoverflow.com/questions/4...er-ubuntu-10-1

File: /etc/udev/rules.d/70-persistent-usb.rules
Code:

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

#!/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;
    }
}


Added:
An example of what it does. I haven't pulled USB0 out and reinserted it since adding the code.
Code:

crw-rw---- 1 root dialout 188, 0 May 26 14:13 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1 May 26 21:23 /dev/ttyUSB1
lrwxrwxrwx 1 root root        7 May 26 21:22 /dev/ttyUSB1-2 -> ttyUSB1


michaelk 05-26-2014 09:29 PM

Most of the PL2303 USB serial adapters that I have used have the same attributes and none have serial numbers. The following links will help write a rule based upon the device's port.

http://askubuntu.com/questions/49910...erial-adapters

http://stackoverflow.com/questions/4...er-ubuntu-10-1

Quakeboy02 05-26-2014 09:44 PM

Hi Michael,

I guess you missed my second post. I did finally find both of those pages and came up with the above. Any ideas on what to do about USB hubs? I'm not at that point yet, but it could happen.

Added:
Hmm, looking at the rule again, it may be a mistake to use the same name. Could a device be reparsed multiple times by the rule?

michaelk 05-26-2014 09:54 PM

The first link shows how to determine the hub.

Quakeboy02 05-26-2014 10:01 PM

It looks to me like what he did was specific to his needs. I don't understand enough about this to make it generic to all hubs on all the devices. Well, when/if it happens, I'll refer back to this and see if I can figure it out.

Quakeboy02 07-12-2014 02:48 PM

I finally needed to plug multiple PL2303s into a hub, so I'd like to follow up on this with what I think is a fix. I've made changes to the usb-parse-devpath.pm file so that it handles USB hubs. In my testing, I am using USB Bus 007.

If a PL2303 is plugged directly into USB Bus 7, it will get the usual incremental /dev/ttyUSBx, and there will be a link created: /dev/ttyUSB7-1.

However, if a hub is plugged into bus 7, e.g.
Code:

Bus 007 Device 101: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
and a PL2303 is plugged into that, the created link will delineate which port on the hub it's plugged into. For example: "/dev/ttyUSB7-1.3". I've done simple testing with "gtkterm -p /dev/ttyUSB7-1.3" (and for /dev/ttyUSB7-1.4) to verify it works.

File: /etc/udev/rules.d/usb-parse-devpath.pm
Code:

#!/usr/bin/perl -w

@items = split("/", $ARGV[0]);
for ($i = 0; $i < @items; $i++) {
    if ($items[$i] =~ m/^usb[0-9]+$/) {

        if ($items[$i + 2] =~ m/:/) {
            print $items[$i + 1] . "\n";
        } else {
            print $items[$i + 2] . "\n";
        }

        last;
    }
}

I have not (nor do I intend to) looked into the possibility of hubs plugged into hubs.


All times are GMT -5. The time now is 07:17 AM.