LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 05-26-2014, 07:14 PM   #1
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
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
 
Old 05-26-2014, 09:10 PM   #2
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Original Poster
Rep: Reputation: 141Reputation: 141
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

Last edited by Quakeboy02; 05-26-2014 at 09:48 PM. Reason: Added an example of output
 
Old 05-26-2014, 09:29 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,748

Rep: Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927
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
 
Old 05-26-2014, 09:44 PM   #4
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Original Poster
Rep: Reputation: 141Reputation: 141
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?

Last edited by Quakeboy02; 05-26-2014 at 09:46 PM.
 
Old 05-26-2014, 09:54 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,748

Rep: Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927Reputation: 5927
The first link shows how to determine the hub.
 
Old 05-26-2014, 10:01 PM   #6
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Original Poster
Rep: Reputation: 141Reputation: 141
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.
 
Old 07-12-2014, 02:48 PM   #7
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Original Poster
Rep: Reputation: 141Reputation: 141
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting USB device names from /dev/disks/ kushalkoolwal Programming 8 01-30-2009 06:14 PM
PL2303 & Pl2303x usb serial device alokm Linux - Newbie 1 02-09-2008 09:56 PM
USB HD being assigned different device names neddis Linux - Hardware 1 11-11-2007 11:22 AM
Making usb stick with device names mrsolo Linux - Hardware 0 11-16-2004 06:00 PM
usb device names geomatt Linux - Hardware 2 09-05-2004 01:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 07:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration