首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过lsusb返回idVendor、idProduct和端点

通过lsusb返回idVendor、idProduct和端点
EN

Stack Overflow用户
提问于 2022-11-20 20:06:15
回答 2查看 58关注 0票数 0

我只想归还一些我可爱的打印机的数据。(名称始终包含STMicroelectronics printer

我可以用lsusb命令打印出所有插入的USB设备。这将给我(第一行显然是打印机):

代码语言:javascript
复制
Bus 001 Device 004: ID 0483:5743 STMicroelectronics printer-80
Bus 001 Device 003: ID 0424:ec00 Microchip Technology, Inc. (formerly SMSC) SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Microchip Technology, Inc. (formerly SMSC) SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub`

我现在可以通过lsusb -vvv -d 0483:5743找到设备的详细信息,它返回:

代码语言:javascript
复制
Bus 001 Device 004: ID 0483:5743 STMicroelectronics printer-80
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x0483 STMicroelectronics
  idProduct          0x5743 
  bcdDevice            1.00
  iManufacturer           1 Printer  
  iProduct                2 printer-80
  iSerial                 3 012345678AB
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0020
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower                2mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         7 Printer
      bInterfaceSubClass      1 Printer
      bInterfaceProtocol      2 Bidirectional
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0001
  Self Powered

现在..。我如何才能通过bash返回这些数据:

代码语言:javascript
复制
idVendor (0x0483)
idProduct (0x5743)
endpointOUT (0x01)
endpointIN (0x81)

一定有一些grep/regex魔法,我就是无法掌握。

谢谢您提前提供帮助!

正在寻找解决方案,以使用regex提取包含打印机描述的行。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-11-20 22:36:38

使用GNU sed

代码语言:javascript
复制
$ sed -En 's/[ \t]*b?(id[vp][^ \t]*|endpoint)(address)?[ \t]+([^ \t]*).* (out|in)?.*/\l\1\4 (\3)/Ip' <(lsusb | awk '$0 ~ /STMicroelectronics printer-80/{print $6}' | xargs -I % sh -c "lsusb -vvv -d %")
idVendor (0x0483)
idProduct (0x5743)
endpointOUT (0x01)
endpointIN (0x81)
票数 0
EN

Stack Overflow用户

发布于 2022-11-20 22:14:09

建议使用以下awk脚本:

代码语言:javascript
复制
awk '/idVendor/||/idProduct/{printf("%s (%s)\n", $1,$2)}/bEndpointAddress/{printf("endpoint%s (%s)\n", $NF, $2)}' <<<$(lsusb -vvv -d 0483:5743)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74511582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档