0

I'm reading a simple QR code with json text:

{test:Hi}

enter image description here

import hid
import time

h = hid.device()
h.open(0x1eab, 0x8003)

print("Manufacturer: %s" % h.get_manufacturer_string())
print("Product: %s" % h.get_product_string())
print("Serial No: %s" % h.get_serial_number_string())

try:
    while True: 
        d = h.read(64)
        if d: 
            print('read: "{}"'.format(d))
finally:
    print("Closing the device")
    h.close()

However, in the console it's returning this:

Manufacturer: YK
Product: YK-2D PRODUCT HID KBW
Serial No: MS001-000000000
read: "[2, 0, 47, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
read: "[0, 0, 23, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
read: "[0, 0, 8, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
read: "[0, 0, 22, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
read: "[0, 0, 23, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
read: "[2, 0, 51, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
read: "[2, 0, 11, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
read: "[0, 0, 12, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
read: "[2, 0, 48, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
read: "[0, 0, 40, 0, 0, 0, 0, 0]"
read: "[0, 0, 0, 0, 0, 0, 0, 0]"
user1872384
  • 6,886
  • 11
  • 61
  • 103
  • The documentation for the device you're using should describe what it returns - that'll give you a clue on how to make it meaningful... – Jon Clements Aug 19 '18 at 08:17
  • @JonClements, unfortunately there's no documentation for the device. It's a plug and play QR scanner. Or is there a standard way to make it meaningful? – user1872384 Aug 19 '18 at 08:21
  • Guess you could have a look at existing qrcode libraries/specifications and go from there... Appears there's also quite an extensive HID spec as well... – Jon Clements Aug 19 '18 at 08:29
  • Thanks for your suggestion. Search around and most of them accept image as input. Perhaps need to convert it to image before decoding it? Will take a look at the HID spec as well – user1872384 Aug 19 '18 at 08:48
  • Thx @Jon Clements, managed to get it to work using evdev instead – user1872384 Aug 23 '18 at 05:47
  • Can you post a self answer? – Jon Clements Aug 23 '18 at 08:23

1 Answers1

0

this is pretty sure keyboard output, meaning the scanner sends keystrokes.

First byte is modifier flags (shift, cntrl, .) Second always 0. 3rd is key usage (you can call it scancode). The rest is always 0 for barcode readers since the order of the keys is not guarantied by the OS.

In python3 you can read it with the input() function. Better is to use other interfaces. Keyboard emulation should be the last interface you try to use (I am Mr. Keyboard :-) in my company - one of the major players in barcode readers).

Good barcode scanners can be switched to other USB interfaces like HidPos or CDC-ACM (ComPort Emulation).

DieterF
  • 21
  • 1