虽然从您的角度来看,您只是将一台设备插入计算机,但 Linux 内核对正在发生的事情有更复杂的看法。内核跟踪设备的层次结构,每个设备都有自己的属性、驱动程序和子设备。层次结构的根通常是代表您的 CPU 的某种根设备,然后(可能间接)连接到 USB 控制器设备,该设备连接到“根集线器”,然后连接到您的物理 USB 设备插入,而 USB 设备公开的每个功能/接口可能都有子设备。
您可以运行man udevadm 以了解有关该命令作用的更多信息。它说:
-a, --attribute-walk
Print all sysfs properties of the specified device that can be used
in udev rules to match the specified device. It prints all devices
along the chain, up to the root of sysfs that can be used in udev
rules.
所以有这个设备链,从 ttyACM0(USB 设备的一个函数)开始,一直到物理 USB 设备,然后是根集线器,然后是 USB 控制器,直到它到达等级制度。 --attribute-walk 选项沿着该链向上走,并沿途打印出每个设备的属性。
您将该命令的输出通过管道传输到grep,因此您看不到完整的输出,这可能是您感到困惑的原因。该命令的完整输出实际上是非常有用的:它打印出一个很好的段落来解释它的作用,并且当它从打印一个设备的属性切换到打印其父设备的属性时,还有一些有用的句子可以清楚地说明。以下是我在 Raspberry Pi 上检查 USB 设备时得到的一些输出:
$ udevadm info --name=sda2 --attribute-walk
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2.1/1-1.2.1:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda2':
KERNEL=="sda2"
SUBSYSTEM=="block"
[snip]
looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2.1/1-1.2.1:1.0/host0/target0:0:0/0:0:0:0/block/sda':
KERNELS=="sda"
SUBSYSTEMS=="block"
[snip]
looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2.1/1-1.2.1:1.0/host0/target0:0:0':
KERNELS=="target0:0:0"
SUBSYSTEMS=="scsi"
[snip]
looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2.1/1-1.2.1:1.0':
KERNELS=="1-1.2.1:1.0"
SUBSYSTEMS=="usb"
[snip]
looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2.1':
KERNELS=="1-1.2.1"
SUBSYSTEMS=="usb"
[snip]
[... and so on, up to the root device]
不幸的是,从您的udevadm 命令的输出来看,您的 RFID 适配器似乎没有 USB 序列号,因此将其与相同型号的其他设备区分开来可能会很棘手。要确认它没有序列号,我建议您运行lsusb -v -d 0c27:232a | grep iSerial。如果iSerial后面的数字为0,则表示没有序列号。
我建议查看 Linux 在/dev/serial/by-id 中为您创建的符号链接;也许这些符号链接的名称中将包含足够的详细信息,因此您无需创建新的 udev 规则。 (提示:运行ls -lR /dev/serial/by-id。)
如果您仍然需要更多帮助来查找或创建稳定的符号链接,我认为您应该插入所有四个 RFID 阅读器,然后发布每个命令的完整输出:
ls -lR /dev/serial/by-id
ls /dev/ttyACM*
udevadm info --name=ttyACM0 --attribute-walk