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
  • 通过命令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
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值