Ubuntu 10.1下如何识别多个USB串口适配器

发布于 2024-10-14 10:37:51 字数 304 浏览 5 评论 0原文

我正在 Ubuntu 10.1 下从多个相同的 USB 串行适配器读取数据。

有时,它们的 /dev/tty 路径会发生变化(例如,如果在启动时连接了其他 USB 设备)。

我需要一种通过任何此类更改重复引用同一适配器的方法。

据 udevadm 称,这些设备都具有相同的序列号。

我认为最有可能的选择是识别适配器所连接的端口(它们不会移动)。

我可以找到各种可能有效的有趣 /dev 路径,但是尽管网上有很多关于 udev 的讨论,但我无法找到关于如果设备插入静态端口时这些路径中的某些路径是否是静态的明确声明。

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 startup).

I need a way of repeatedly referring to the same adapter through any such changes.

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).

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

明媚殇 2024-10-21 10:37:51

有一个解决方案。晚做总比不做好 ;)

使用以下 udev 规则将 /dev/ttyUSB{?} 设备映射到 /dev/usb-ports/%bus_id -%port_id 链接。

这是我的 /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 中,格式如下:bus_id-port_id

例如,下一个命令给出以下内容:

$ 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_id3port_id1 并且现在我的 /dev/usb-ports 中有以下内容:

$ ls -al /dev/usb-ports
lrwxrwxrwx  1 root root   10 Май 12 00:26 3-1 -> ../ttyUSB0

问候。

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.

夏尔 2024-10-21 10:37:51

就像 Ilya Matvejchikov 的答案一样,一个好的解决方案是添加 udev 规则来对设备执行您想要的操作。和你一样,我也遇到了类似的问题。我在 USB 转多串行适配器上安装了 UPS,有时系统会切换 /dev/tty 编号。

我的解决方案是创建一个规则,通过驱动程序和端口来匹配设备类型,然后创建一个指向我的 UPS 所连接端口的符号链接。我使用 NUT 来监控 UPS,它始终插入同一个物理端口。

# File contents of /etc/udev/rules.d/75-nut-ups.rules
# Create /dev/nut-ups0 to use as a persistent serial device that can be used
# reliably by nut to communicate with a UPS attached to the system.
# The UPS is attached to the first port of a MosSemiconductor dual USB
# serial adapter.
KERNELS=="ttyUSB*", SUBSYSTEMS=="usb-serial", DRIVERS=="moschip7720", ATTRS{port_number}=="0", SYMLINK+="nut-ups0"

现在,我将 NUT 配置为始终使用常量 /dev/nut-ups0,因为当识别 USB 串行设备时,串行端口和规则会正确处理映射。

您可以使用 lsusb 命令查找插入时要在规则中使用的实际设备名称。

Much like Ilya Matvejchikov's answer, a good solution is to add udev rules to do what you want with the device. Like you, I was having a similar problem. I had a UPS on a USB-to-multi-serial adapter and occasionally the system would switch around the /dev/tty numbers.

My solution was to create a rule to match the type of device by driver and port, then create a symbolic link to the port to which my UPS was attached. I used NUT to monitor the UPS, which was always plugged into the same physical port.

# File contents of /etc/udev/rules.d/75-nut-ups.rules
# Create /dev/nut-ups0 to use as a persistent serial device that can be used
# reliably by nut to communicate with a UPS attached to the system.
# The UPS is attached to the first port of a MosSemiconductor dual USB
# serial adapter.
KERNELS=="ttyUSB*", SUBSYSTEMS=="usb-serial", DRIVERS=="moschip7720", ATTRS{port_number}=="0", SYMLINK+="nut-ups0"

Now I configure NUT to always use a constant /dev/nut-ups0, as the serial port and the rule takes care of mapping properly when the usb-serial device is recognized.

You can use the lsusb command to find out the actual device name to use in the rule when it's plugged in.

淑女气质 2024-10-21 10:37:51

使用 $ udevadm info -n /dev/ttyUSB0 -a 查看您的 USB 设备插入了哪个端口。其中一个父设备的变量 KERNELS 应该类似于 KERNELS=="1-1.2: 1.0”。

创建udev规则:

SUBSYSTEM=="tty", KERNELS=="1-1.2:1.0", SYMLINK+="ttyUSB42"
SUBSYSTEM=="tty", KERNELS=="1-1.3:1.0", SYMLINK+="usb-serial"

并触发udev

$ udevadm trigger

Look with $ udevadm info -n /dev/ttyUSB0 -a which port your USB device is plugged in. The variable KERNELS of one of the parent devices should be something like KERNELS=="1-1.2:1.0".

Create a udev rule:

SUBSYSTEM=="tty", KERNELS=="1-1.2:1.0", SYMLINK+="ttyUSB42"
SUBSYSTEM=="tty", KERNELS=="1-1.3:1.0", SYMLINK+="usb-serial"

and trigger udev

$ udevadm trigger
二智少女猫性小仙女 2024-10-21 10:37:51

我有许多 USB 转串行设备,每个设备都有多个端口和解决方案
上面提到的并没有完全适合我。

USB“KERNEL”对我来说还不够,但我找到了端口号。

我知道我现在提出的建议可能会被认为是疯狂的黑客行为,
但这对我有用..
现在..

我实际上很高兴看到一个更优雅的建议
完成类似的事情..

所以...基于之前的答案 Ilya Matveychikov

文件:/etc/udev/rules.d/usb-parse-devpath.sh

#!/bin/bash

DEVNUM=$(echo "${1}" | rev | cut -d'/' -f4 | rev | tr -d '-' | tr -d '.' | tr -d ':')
PORTNUM=$(/sbin/udevadm info -a --path=${1} | grep "ATTRS{port_number}" | head -1 | cut -d'"' -f2)
PRODUCT=$(/sbin/udevadm info -a --path=${1} | grep "ATTRS{product}" | head -1 | cut -d'"' -f2 | tr -d '/' | tr ' ' '_')

NEWID="ttyUSB_${PRODUCT}_${DEVNUM}${PORTNUM}"

#echo "${NEWID} :: $1" >> /tmp/DEBUG_udev.txt

echo "$NEWID"

和文件:/etc/udev/rules.d/99- usb-serial.rules

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

结果如下所示:

# ls -l /dev/TTYUSBs

lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435100 -> ../ttyUSB20
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435101 -> ../ttyUSB21
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435102 -> ../ttyUSB22
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435103 -> ../ttyUSB23
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435104 -> ../ttyUSB24
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435105 -> ../ttyUSB25
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435106 -> ../ttyUSB26
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435107 -> ../ttyUSB27
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436100 -> ../ttyUSB28
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436101 -> ../ttyUSB29
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436102 -> ../ttyUSB30
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436103 -> ../ttyUSB31
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436104 -> ../ttyUSB32
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436105 -> ../ttyUSB33
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436106 -> ../ttyUSB34
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436107 -> ../ttyUSB35
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport4_4341100 -> ../ttyUSB38
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport4_4341101 -> ../ttyUSB39
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport4_4342100 -> ../ttyUSB36
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport4_4342101 -> ../ttyUSB37
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_421100 -> ../ttyUSB2
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_421101 -> ../ttyUSB3
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_422100 -> ../ttyUSB4
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_422101 -> ../ttyUSB5
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport8_423100 -> ../ttyUSB18
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport8_423101 -> ../ttyUSB19
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_424100 -> ../ttyUSB0
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_424101 -> ../ttyUSB1
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_431100 -> ../ttyUSB6
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_431101 -> ../ttyUSB7
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_431102 -> ../ttyUSB8
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_431103 -> ../ttyUSB9
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_432100 -> ../ttyUSB10
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_432101 -> ../ttyUSB11
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_432102 -> ../ttyUSB12
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_432103 -> ../ttyUSB13
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_433100 -> ../ttyUSB14
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_433101 -> ../ttyUSB15
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_433102 -> ../ttyUSB16
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_433103 -> ../ttyUSB17

I have many USB to Serial devices with each many ports and the solutions
mentioned above did not quite did it for me.

The USB "KERNEL" was not enough in my case, but I found the port number.

I am aware that what I'm proposing now might be considered an insane hack,
but it works for me..
for now..

I would actually be pleased to see a more elegant suggestion
that accomplish something similar..

So... Based on the previous answer form Ilya Matveychikov

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

#!/bin/bash

DEVNUM=$(echo "${1}" | rev | cut -d'/' -f4 | rev | tr -d '-' | tr -d '.' | tr -d ':')
PORTNUM=$(/sbin/udevadm info -a --path=${1} | grep "ATTRS{port_number}" | head -1 | cut -d'"' -f2)
PRODUCT=$(/sbin/udevadm info -a --path=${1} | grep "ATTRS{product}" | head -1 | cut -d'"' -f2 | tr -d '/' | tr ' ' '_')

NEWID="ttyUSB_${PRODUCT}_${DEVNUM}${PORTNUM}"

#echo "${NEWID} :: $1" >> /tmp/DEBUG_udev.txt

echo "$NEWID"

And File: /etc/udev/rules.d/99-usb-serial.rules

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

The result look something like this:

# ls -l /dev/TTYUSBs

lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435100 -> ../ttyUSB20
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435101 -> ../ttyUSB21
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435102 -> ../ttyUSB22
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435103 -> ../ttyUSB23
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435104 -> ../ttyUSB24
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435105 -> ../ttyUSB25
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435106 -> ../ttyUSB26
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_435107 -> ../ttyUSB27
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436100 -> ../ttyUSB28
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436101 -> ../ttyUSB29
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436102 -> ../ttyUSB30
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436103 -> ../ttyUSB31
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436104 -> ../ttyUSB32
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436105 -> ../ttyUSB33
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436106 -> ../ttyUSB34
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport416_436107 -> ../ttyUSB35
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport4_4341100 -> ../ttyUSB38
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport4_4341101 -> ../ttyUSB39
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport4_4342100 -> ../ttyUSB36
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport4_4342101 -> ../ttyUSB37
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_421100 -> ../ttyUSB2
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_421101 -> ../ttyUSB3
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_422100 -> ../ttyUSB4
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_422101 -> ../ttyUSB5
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport8_423100 -> ../ttyUSB18
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Edgeport8_423101 -> ../ttyUSB19
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_424100 -> ../ttyUSB0
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Edgeport8_424101 -> ../ttyUSB1
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_431100 -> ../ttyUSB6
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_431101 -> ../ttyUSB7
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_431102 -> ../ttyUSB8
lrwxrwxrwx. 1 root root 10 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_431103 -> ../ttyUSB9
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_432100 -> ../ttyUSB10
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_432101 -> ../ttyUSB11
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_432102 -> ../ttyUSB12
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_432103 -> ../ttyUSB13
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_433100 -> ../ttyUSB14
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_433101 -> ../ttyUSB15
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_433102 -> ../ttyUSB16
lrwxrwxrwx. 1 root root 11 Jan  5 18:46 ttyUSB_Keyspan_USA-49WG_433103 -> ../ttyUSB17
甜心小果奶 2024-10-21 10:37:51

usb-devices 可以获取端口号和总线/开发枚举。

usb-devices can get you the port number and the bus/dev enumeration.

無處可尋 2024-10-21 10:37:51

我也在这个主题中搜索一种方法来查找哪个物理 USB 设备被分配/连接到逻辑 /dev 设备名称。因此,经过一番尝试和错误后,这对我来说最有效:

查看存在哪些逻辑 ttyUSBx 设备(其中 x 是 0、1、2...):

$ ls /dev

显示所有 USB 串行适配器的总线和设备编号:

$ lsusb 

最后,使用:

$ udevadm info --name=ttyUSBx --attribute-walk | grep num  

现在检查 udevadm 输出以将逻辑设备名称与实际物理设备相匹配。这是我执行此操作时的列表:

$ lsusb
Bus 002 Device 005: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial     (UART) IC
Bus 002 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 002 Device 002: ID 80ee:0021  
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

$ udevadm info --name=ttyUSB0 --attribute-walk | grep num
    ATTRS{port_number}=="0"
    ATTRS{urbnum}=="812"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="5"
    ATTRS{urbnum}=="115"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="1"
    ATTRS{numa_node}=="-1"

$ udevadm info --name=ttyUSB1 --attribute-walk | grep num
    ATTRS{port_number}=="0"
    ATTRS{urbnum}=="465"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="4"
    ATTRS{urbnum}=="115"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="1"
    ATTRS{numa_node}=="-1"

因此,在我的例子中,ttyUSB0 与总线 2 上的设备 device5 关联,该设备是未来技术设备国际 USB 转串行适配器;同样,ttyUSB1 与总线 2 上的设备 device4 关联,该设备是 Prolific Technology, Inc. USB 转串行适配器。

正如已经指出的那样,该命令:

$ usb-devices

将以一行方式为您提供相同的信息。我想我应该发布一些细节来帮助我了解这些东西在幕后是如何工作的......

希望这有帮助:)

I too was searching this topic for a way to find which physical USB device was assigned/connected to a logical /dev device name. So, after some trial and error, this is what worked best for me:

See what logical ttyUSBx devices exist (where x is 0, 1, 2...):

$ ls /dev

Show bus and device numbers for all usb-serial adapters:

$ lsusb 

Finally, use:

$ udevadm info --name=ttyUSBx --attribute-walk | grep num  

Now inspect the udevadm output to match the logical device name to the actual physical device. Here my listing when I did it:

$ lsusb
Bus 002 Device 005: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial     (UART) IC
Bus 002 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 002 Device 002: ID 80ee:0021  
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

$ udevadm info --name=ttyUSB0 --attribute-walk | grep num
    ATTRS{port_number}=="0"
    ATTRS{urbnum}=="812"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="5"
    ATTRS{urbnum}=="115"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="1"
    ATTRS{numa_node}=="-1"

$ udevadm info --name=ttyUSB1 --attribute-walk | grep num
    ATTRS{port_number}=="0"
    ATTRS{urbnum}=="465"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="4"
    ATTRS{urbnum}=="115"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="1"
    ATTRS{numa_node}=="-1"

So, in my case, ttyUSB0 is associated with the device on bus2, device5, which is the Future Technology Devices International USB to Serial Adapter; and likewise, ttyUSB1 is associated with the device on bus2, device4, which is the Prolific Technology, Inc. USB to Serial adapter.

And as has been pointed out, the command:

$ usb-devices

Will get you the same info in a one-line manner. I thought I'd post the details that helped me learn how the stuff worked behind the scenes...

Hope that was helpful :)

洛阳烟雨空心柳 2024-10-21 10:37:51

这些设备都具有相同的序列号 [..]

usb-parse-devpath.pm 通过使用适配器的总线和端口 ID 解决了这个问题。

The devices all have the same serial numbers [..]

The usb-parse-devpath.pm addresses this by using the bus and port id of the adapter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文