3

The setting

I need to write program that to be able to use several types of barcode scanners, connected on USB port.

All these scanners have mode of type "serial port emulation" where (on my understanding) they should behave like simple byte stream device.

But one of the scanners behaves differently. It sends only fixed length (64 bytes) blocks, where the first byte is the length of the data, then the data bytes and padded with zeros up to the end of the block.

Every block can be read only in single read operation on the device. Even one read byte, causes the whole block to disappear from the IO stream.

The scanner is detected (using lsusb) as a HMI device:

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

For comparison, here is the lsusb output about another scanner, that behaves as a normal byte stream device:

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

The dmesg output on plugging in barcode scanner:

[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

The question:

How to configure Linux to handle this scanner as a byte stream device?

6
  • 1
    Not sure I understand the question. If it's a HID device, you should be able to access it through the Linux HID infrastructure. Please edit your question with dmesg output after you plug it in, you should get a hidraw device and probably also a /dev/input/eventX device. Run evtest on this device and see what happens.
    – dirkt
    Commented Mar 6, 2017 at 7:41
  • @dirkt These USB barcode scanners can be configured to act as different devices. The common use is like a keyboard device, but in my case this is not useful. There is another mode "serial port emulation" where the barcode scanner emulates byte stream device. The scanner in the question is configured this way, but is still recognized as a HID device (compare with the second example in the question, where the scanner behaves properly) and can be read only on blocks.
    – johnfound
    Commented Mar 6, 2017 at 8:04
  • @dirkt Also, regardless that the device is recognized as HID device, it does not appear to be handled as a keyboard.
    – johnfound
    Commented Mar 6, 2017 at 8:07
  • 1
    So how do you know this particular scanner can be configured for serial port emulation? Maybe (1) it can't, or (2) it needs vendor specific commands which you can't guess. Anyway, please still provide output of dmesg, and dump the HID descriptor: As root, mount -t debugfs none /sys/kernel/debug, then the first line of /sys/kernel/debug/hid/<dev>/rdesc is the raw descriptor. Parse here or with hidrd, possibly it contains hints how to switch.
    – dirkt
    Commented Mar 6, 2017 at 10:01
  • Also, still try evtest, it will tell you as what the events show up, if not as key presses.
    – dirkt
    Commented Mar 6, 2017 at 10:01

1 Answer 1

2

Partial answer: If you do have the "special com port driver" for this scanner, and you do have a Windows computer, you can snoop the USB traffic under Windows in the initialization phase of the driver and find out how it switches to the serial configuration. That traffic can then be replayed in Linux using libusb etc.

USB snooping tools for Windows are e.g. usbsnoop or usbcap, google for more.

Looking at the HID descriptor may offer a simpler alternative, though.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .