How do assign specific nodes to 2-port USB-to-serial adapter?
Greetings,
My USB-to-serial adapter (gives me 2 serial ports) is currently being named ttyUSB0 and ttyUSB1. I would like to change the name of the nodes to test0 and test1, for example.
I understand how to normally accomplish this, except this device shares the same serial number and ID, according to "udevinfo -a -p /sys/class/tty/ttyUSB0" and "udevinfo -a -p /sys/class/tty/ttyUSB1".
I don't know how to tell udev/hotplug how to differentiate between the two serial ports.
The best I can come up with is the following, which only gives me a test0 node (and no ttyUSB nodes):
BUS="usb", SYSFS{serial}="V32408622-0", NAME="test0"
BUS="usb", SYSFS{serial}="V32408622-0", NAME="test1"
I'm thinking that one of the "simple printf-like string substitutions" will do the trick but none have worked thus far.
Any suggestions?
Thanks in advance,
J McBane
jmcbane a grandecom.net
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Hey J,
Quoted 10 lines · J McBane
Greetings,
My USB-to-serial adapter (gives me 2 serial ports) is currently being named ttyUSB0 and ttyUSB1. I would like to change the name of the nodes to test0 and test1, for example.
I understand how to normally accomplish this, except this device shares the same serial number and ID, according to "udevinfo -a -p
/sys/class/tty/ttyUSB0" and "udevinfo -a -p/sys/class/tty/ttyUSB1".
Quoted 8 lines
I don't know how to tell udev/hotplug how to differentiate between the two serial ports.
The best I can come up with is the following, which only gives me a test0 node (and no ttyUSB nodes):
BUS="usb", SYSFS{serial}="V32408622-0", NAME="test0"
BUS="usb", SYSFS{serial}="V32408622-0", NAME="test1"
You could try a little something like this:
BUS="usb", SYSFS{serial}="V32408622-0", NAME="%k", SYMLINK="test%n"
Or if you're feeling cheeky, maybe you could:
BUS="usb", SYSFS{serial}="V32408622-0", NAME="%k", SYMLINK="%s{serial}% n"
With a bit of digging around in sysfs, I'm sure you could find something more meaningful to put in the symlink name than 'serial'.
You're probably being a bit restrictive by putting the whole serial in there. It'd be better to use something like model number.
Have a look at the udev manual page. All sorts of fun stuff in there :0)
Check the version of udev you're running too - I know the '%s' stuff was patched a bit some time ago - v0.75ish, IIRC ?
Also note that the rules will (I think) stop at the first match. This is why your test1 device never gets created.
Hope this helps.
Cheers,
-Oli
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 62 lines · J McBane
Quoted 47 lines · Oli
Hey J,
Quoted 10 lines · J McBane
Greetings,
My USB-to-serial adapter (gives me 2 serial ports) is currently being named ttyUSB0 and ttyUSB1. I would like to change the name of the nodes to test0 and test1, for example.
I understand how to normally accomplish this, except this device shares the same serial number and ID, according to "udevinfo -a -p
/sys/class/tty/ttyUSB0" and "udevinfo -a -p/sys/class/tty/ttyUSB1".Quoted 10 lines
I don't know how to tell udev/hotplug how to differentiate between the two serial ports.
The best I can come up with is the following, which only gives me a test0 node (and no ttyUSB nodes):
BUS="usb", SYSFS{serial}="V32408622-0", NAME="test0"
BUS="usb", SYSFS{serial}="V32408622-0", NAME="test1"You could try a little something like this:
BUS="usb", SYSFS{serial}="V32408622-0", NAME="%k", SYMLINK="test%n"
Or if you're feeling cheeky, maybe you could:
BUS="usb", SYSFS{serial}="V32408622-0", NAME="%k", SYMLINK="%s{serial}% n"
With a bit of digging around in sysfs, I'm sure you could find something more meaningful to put in the symlink name than 'serial'.
You're probably being a bit restrictive by putting the whole serial in there. It'd be better to use something like model number.
Have a look at the udev manual page. All sorts of fun stuff in there :0)
Check the version of udev you're running too - I know the '%s' stuff was patched a bit some time ago - v0.75ish, IIRC ?
Quoted 13 lines
Also note that the rules will (I think) stop at the first match. This is why your test1 device never gets created.
Hope this helps.
Cheers,
-Oli
Quoted 2 lines
Oli,
Hi J,
Quoted 1 line
I hope you don't mind me replying directly to you, as to not spam the list.
Not a problem :0) I've put the list back on this reply though, so everyone can jump in and give you some better advice :0)
Quoted 3 lines
I noticed %s in the udev man page but wasn't sure how to "use it". There were no examples of %s (I like examples).
Yeah, the examples for that one are a bit thin on the ground. It works exactly like the sysfs{attribute} rule, except it substitutes the value into the name or symlink.
Quoted 3 lines
Something I didn't mention is that my device actually has 4 serial ports (two 2-port devices in one box).
Righto.
Quoted 4 lines
udev/hotplug sees two devices, each with a separate serial number, but the same "model number", so I don't think I'll be able to use the model number.
If the device is well behaved, it should initialise the ports in the same order each time. When you use %k, it substitutes the kernel device number - eg, 1 for hda1, 2 for hda2 etc - and they'll always refer to the same port.
You can use the model number with a %k on the end to get different devices/symlinks created from the same rule. The trick is finding a sysfs attribute that is meaningful to you - maybe the make of the board..?
Or forget that, and use usbserial%k to get usbserial1, usbserial2 etc
Quoted 2 lines
Thanks for the prompt reply and suggestion!
No probs :0)
Quoted 4 lines
Cheers,
J McBane
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoting Oli <[email protected]>:
Quoted 107 lines · J McBane
Quoted 10 lines
Quoted 8 lines · Oli
Hey J,
Quoted 3 lines · J McBane
Greetings,
My USB-to-serial adapter (gives me 2 serial ports) is currently being
named
Quoted 1 line
Quoted 1 line
Quoted 1 line
ttyUSB0 and ttyUSB1. I would like to change the name of the nodes to
test0 and
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
test1, for example.
I understand how to normally accomplish this, except this device shares
the same
Quoted 1 line
Quoted 1 line
Quoted 1 line
serial number and ID, according to "udevinfo -a -p
/sys/class/tty/ttyUSB0" andQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
"udevinfo -a -p
/sys/class/tty/ttyUSB1".I don't know how to tell udev/hotplug how to differentiate between the
two
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
serial ports.
The best I can come up with is the following, which only gives me a test0
node
Quoted 41 lines
Quoted 28 lines
Quoted 6 lines
(and no ttyUSB nodes):
BUS="usb", SYSFS{serial}="V32408622-0", NAME="test0" BUS="usb", SYSFS{serial}="V32408622-0", NAME="test1"You could try a little something like this:
BUS="usb", SYSFS{serial}="V32408622-0", NAME="%k", SYMLINK="test%n"
Or if you're feeling cheeky, maybe you could:
BUS="usb", SYSFS{serial}="V32408622-0", NAME="%k", SYMLINK="%s{serial}% n"
With a bit of digging around in sysfs, I'm sure you could find something more meaningful to put in the symlink name than 'serial'.
You're probably being a bit restrictive by putting the whole serial in there. It'd be better to use something like model number.
Have a look at the udev manual page. All sorts of fun stuff in there :0)
Check the version of udev you're running too - I know the '%s' stuff was patched a bit some time ago - v0.75ish, IIRC ?
Quoted 13 lines
Also note that the rules will (I think) stop at the first match. This is why your test1 device never gets created.
Hope this helps.
Cheers,
-OliQuoted 2 lines
Oli,
Hi J,
Quoted 1 line
I hope you don't mind me replying directly to you, as to not spam the list.
Not a problem :0) I've put the list back on this reply though, so everyone can jump in and give you some better advice :0)
Quoted 3 lines
I noticed %s in the udev man page but wasn't sure how to "use it". There were no examples of %s (I like examples).
Yeah, the examples for that one are a bit thin on the ground. It works exactly like the sysfs{attribute} rule, except it substitutes the value into the name or symlink.
Quoted 3 lines
Something I didn't mention is that my device actually has 4 serial ports (two 2-port devices in one box).
Righto.
Quoted 4 lines
udev/hotplug sees two devices, each with a separate serial number, but the same "model number", so I don't think I'll be able to use the model number.
If the device is well behaved, it should initialise the ports in the same order each time. When you use %k, it substitutes the kernel device number - eg, 1 for hda1, 2 for hda2 etc - and they'll always refer to the same port.
You can use the model number with a %k on the end to get different devices/symlinks created from the same rule. The trick is finding a sysfs attribute that is meaningful to you - maybe the make of the board..?
Quoted 13 lines
Or forget that, and use usbserial%k to get usbserial1, usbserial2 etc
Quoted 2 lines
Thanks for the prompt reply and suggestion!
No probs :0)
Quoted 4 lines
Cheers,
J McBane
"If the device is well behaved, it should initialise the ports in the same order each time."
That's just it. I guess the device is not well behaved. Sometimes serial ports 1&2 are named ttyUSB0&ttyUSB1 and serial ports 3&4 are named ttyUSB2&ttyUSB3 (as one would expect). But sometimes the opposite happens, where serial ports 3&4 are named ttyUSB0&ttyUSB1 and serial ports 1&2 are named ttyUSB2&ttyUSB3.
For some reason, udev/hotplug is not consistently seeing/naming each of these 2-port "sub devices".
Because of this behavior, I don't think your suggestions will help, because it's based on the order the devices are seen/named. I actually just tried them and they didn't work. I know that the serial number ending with "-0" is the device with serial ports 1&2, so I'm basically trying to find a way to tell udev/hotplug "work with the device ending with serial number "-0" first".
I will try your latest suggestion "usbserial%k to get usbserial1, usbserial2 etc" and let you know what happens.
What mechanism controls the order of which devices are detected/seen/named? It seems that this is what the issue boils down to.
Thanks again for your help, Oli.
J McBane
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel