如果系统中同时接入多个USB设备,比如多个USB串口,当每一次系统启动的时候,系统会为每一个插入的USB设备自动升序命名,例如:ttyUSB0、ttyUSB1…,但因为系统枚举USB设备的顺序是不一定的,而应用程序不可能每次去修改读写的设备名,因此就需要用到将USB端口和设备进行绑定。
droid@droid:~$ lsusb
Bus 008 Device 003: ID 2207:1808
Bus 008 Device 004: ID 2207:1808
Bus 008 Device 002: ID 0bda:0411 Realtek Semiconductor Corp.
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 002: ID 0bda:5411 Realtek Semiconductor Corp.
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 002: ID 174c:1153 ASMedia Technology Inc. ASM2115 SATA 6Gb/s bridge
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 1ff7:0408 CVT Electronics.Co.,Ltd
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
droid@droid:~$ udevadm info --attribute-walk --name=/dev/bus/usb/008/003
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/usb1/fe900000.dwc3/xhci-hcd.9.auto/usb8/8-1/8-1.2':
KERNEL=="8-1.2"
SUBSYSTEM=="usb"
DRIVER=="usb"
ATTR{
authorized}=="1"
ATTR{
avoid_reset_quirk}=="0"
ATTR{
bConfigurationValue}=="1"
ATTR{
bDeviceClass}=="00"
ATTR{
bDeviceProtocol}=="00"
ATTR{
bDeviceSubClass}=="00"
ATTR{
bMaxPacketSize0}=="9"
ATTR{
bMaxPower}=="504mA"
ATTR{
bNumConfigurations}=="1"
ATTR{
bNumInterfaces}==" 1"
ATTR{
bcdDevice}=="0404"
ATTR{
bmAttributes}=="80"
ATTR{
busnum}=="8"
ATTR{
configuration}==""ntb""
ATTR{
devnum}=="3"
ATTR{
devpath}=="1.2"
ATTR{
idProduct}=="1808"
ATTR{
idVendor}=="2207"
ATTR{
ltm_capable}=="no"
ATTR{
manufacturer}=="rockchip"
ATTR{
maxchild}=="0"
ATTR{
product}=="rk3xxx"
ATTR{
quirks}=="0x0"
ATTR{
removable}=="unknown"
ATTR{
serial}=="0123456789ABCDEF"
ATTR{
speed}=="5000"
ATTR{
urbnum}=="13"
ATTR{
version}==" 3.00"
looking at parent device '/devices/platform/usb1/fe900000.dwc3/xhci-hcd.9.auto/usb8/8-1':
KERNELS=="8-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{
authorized}=="1"
ATTRS{
avoid_reset_quirk}=="0"
ATTRS{
bConfigurationValue}=="1"
ATTRS{
bDeviceCla