如何在Ubuntu 10.1下识别多个USB串行适配器 [英] How to identify multiple USB-serial adapters under Ubuntu 10.1
问题描述
我正在Ubuntu 10.1下从多个相同的USB串行适配器读取数据.
I am reading data from multiple identical USB-serial adapters under Ubuntu 10.1.
有时,它们的/dev/tty路径会更改(例如,如果在启动时连接了其他USB设备).
On occasion, their /dev/tty path changes (eg if other USB devices are connected on startup).
我需要一种通过任何此类更改重复引用同一适配器的方法.
I need a way of repeatedly referring to the same adapter through any such changes.
根据udevadm,所有设备的序列号都相同.
The devices all have the same serial numbers, according to udevadm.
我认为最可能的选择是识别适配器所连接的端口(它们不会四处移动).
I think the most likely option is to identify an adapter by which port it is connected to (they don't get moved around).
我可以找到各种可能有用的/dev路径,但是尽管在线上有很多有关udev的讨论,但是如果将设备插入静态,我无法找到关于其中某些路径是否静态的明确声明端口.
I can find all sorts of interesting /dev paths that might work, but despite all the discussion about udev online, I can't locate a definitive statement about whether some of these paths are static if the device is plugged into a static port.
推荐答案
有一个解决方案.最好迟到再也不要;)
There is a solution. It's better late then never ;)
使用以下udev
规则将/dev/ttyUSB{?}
设备映射到/dev/usb-ports/%bus_id-%port_id
链接.
Use the following udev
rule to map /dev/ttyUSB{?}
devices into the /dev/usb-ports/%bus_id-%port_id
link.
这是我的/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"
和usb-parse-devpath.pm
脚本:
#!/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;
}
}
如您所见,这有助于我们创建指向/dev/ttyUSB{?}
设备的命名链接,并将它们以以下格式放置在/dev/usb-ports
上:.
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
因此,bus_id
是3
,port_id
是1
,现在我在/dev/usb-ports
中有以下内容:
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
致谢.
这篇关于如何在Ubuntu 10.1下识别多个USB串行适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!