• Linux 下 USB 端口和设备的绑定


    一、为什么需要绑定?

    如果系统中同时接入多个USB设备,比如多个USB串口,当每一次系统启动的时候,系统会为每一个插入的USB设备自动升序命名,例如:ttyUSB0、ttyUSB1…,但因为系统枚举USB设备的顺序是不一定的,而应用程序不可能每次去修改读写的设备名,因此就需要用到将USB端口和设备进行绑定。

    二、如何实现USB端口和设备的绑定
    • 将要绑定的设备插入系统中,使用lsusb指令查看设备信息
    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 通过命令udevadm info --attribute-walk --name=/dev/bus/usb/008/003和udevadm info --attribute-walk --name=/dev/bus/usb/008/004来找出两个1808对应的KENERL序号
    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
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
  • 相关阅读:
    自压缩llm 为 超长记忆之随机编码(非进制编码)
    快照隔离,与Percolatory分布式解决方案
    [Android] [ROOT] Magisk(魔术师/面具) 设置以及必装模块的安装
    大四如何稳稳当当的毕业--计算机毕设如何做?
    观察者模式(Observer Pattern)
    编译工具:CMake(八) | cmake 常用指令
    单链表的基本操作
    Bootstrap
    黎曼的几何基础,维度
    【Golang】使用代码绘制图表的开源库对比
  • 原文地址:https://blog.csdn.net/GCQ19961204/article/details/126679789