• 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
  • 相关阅读:
    Writerside添加内嵌视频资源方法
    Mybatis知识点记录
    玫瑰花变蚊子血,自动化无痕浏览器对比测试,新贵PlayWright Vs 老牌Selenium,基于Python3.10
    【定义】排列及其逆序数
    如何在 iPhone 上检索已删除的短信
    Mybatis关联(嵌套)查询与延迟加载
    QT软件开发-基于FFMPEG设计录屏与rtsp、rtmp推流软件(支持桌面与摄像头)(四)
    @CacheInvalidate(name = “xxx“, key = “#results.![a+b]“,multi = true)是什么意思
    四、机器学习基础
    MySQL数据库管理基本操作(一)
  • 原文地址:https://blog.csdn.net/GCQ19961204/article/details/126679789