那个设定

那个设定

那个设定

我需要编写能够使用连接到 USB 端口的多种类型的条形码扫描仪的程序。

所有这些扫描仪都具有“串行端口模拟”类型的模式,其中(根据我的理解)它们的行为应该像简单的字节流设备一样。

但其中一台扫描仪的行为有所不同。它仅发送固定长度(64 字节)的块,其中第一个字节是数据的长度,然后是数据字节并用零填充,直到块的末尾。

每个块只能在设备上的单次读取操作中读取。即使读取一个字节,也会导致整个块从 IO 流中消失。

扫描仪被检测为 HMI 设备(使用 lsusb):

Bus 001 Device 002: ID 05e0:0600 Symbol Technologies
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x05e0 Symbol Technologies
  idProduct          0x0600
  bcdDevice            0.01
  iManufacturer           1 Symbol Technologies, Inc, 2008
  iProduct                2 Symbol Bar Code Scanner
  iSerial                 3 S/N:44F1BF6A7CCE45DEB787C6D4A63A1B62 Rev:PAACLS00-001-R015
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          8 Bus Powered
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      40
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               3
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0002
  (Bus Powered)
  Remote Wakeup Enabled

为了进行比较,下面是另一个扫描仪的 lsusb 输出,它的行为与普通字节流设备相同:

Bus 001 Device 003: ID 067e:0803 Intermec Technologies Corp. VCP, Barcode scanner
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            2 Communications
  bDeviceSubClass         2 Abstract (modem)
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x067e Intermec Technologies Corp.
  idProduct          0x0803 VCP, Barcode scanner
  bcdDevice            2.58
  iManufacturer           1 Intermec
  iProduct                2 SR31T
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           67
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      0
      iInterface              0
      CDC Header:
        bcdCDC               1.10
      CDC ACM:
        bmCapabilities       0x00
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1
      CDC Call Management:
        bmCapabilities       0x00
        bDataInterface          1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             255
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        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     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0

插入条形码扫描仪时的 dmesg 输出:

[19415.108131] usb 1-1: new full-speed USB device number 4 using xhci_hcd
[19415.252278] usb 1-1: New USB device found, idVendor=05e0, idProduct=0600
[19415.252295] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[19415.252305] usb 1-1: Product: Symbol Bar Code Scanner
[19415.252313] usb 1-1: Manufacturer: Symbol Technologies, Inc, 2008
[19415.252321] usb 1-1: SerialNumber: S/N:44F1BF6A7CCE45DEB787C6D4A63A1B62 Rev:PAACLS00-001-R015
[19415.273661] hid-generic 0003:05E0:0600.0008: hiddev0,hidraw6: USB HID v1.10 Device [Symbol Technologies, Inc, 2008 Symbol Bar Code Scanner] on usb-0000:00:10.0-1/input0

问题:

如何配置 Linux 来将此扫描仪作为字节流设备来处理?

答案1

部分答案:如果您确实有此扫描仪的“特殊COM端口驱动程序”,并且您有一台Windows计算机,则可以在驱动程序的初始化阶段监听Windows下的USB流量,并了解它如何切换到串行端口配置。然后可以使用libusbetc在 Linux 中重放该流量。

适用于 Windows 的 USB 监听工具有:USB监听或者USBCAP,谷歌了解更多。

不过,查看 HID 描述符可能会提供更简单的替代方案。

相关内容