howwhykid
Posts: 1
Joined: Mon Aug 20, 2018 4:26 am

QR scanner output using HID

Mon Aug 20, 2018 4:31 am

I'm reading a simple QR code with json text, using a raspberry pi and Aibecy mp2600 QR scanner (handsfree):
{test:Hi}
Image

Code: Select all

    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]"
1) What is the output format? is it in numpy format?

2) How can I convert the above output into string?
{test:Hi}

[1]: https://i.stack.imgur.com/9M4OC.png

mikerr
Posts: 2825
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: QR scanner output using HID

Mon Aug 20, 2018 7:57 am

Well that's not ASCII ... but I can "see" the letters there in the 3rd field, seem to be

ascii code = 3rd code + 93

[0, 0, 23, 0, 0, 0, 0, 0] => 23 => 23 + 91 => 116 = 't'

Code: Select all

codes = 23,8,22,23 
for code in codes:
    print chr(93 + code)
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: QR scanner output using HID

Mon Aug 20, 2018 8:09 am

You're getting HID data as documented on page 53 of http://www.usb.org/developers/hidpage/Hut1_12v2.pdf

The first byte is a bit string (the 0x2 bit means shift). The third byte is "usage ID" (as in the PDF).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

mikerr
Posts: 2825
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: QR scanner output using HID

Mon Aug 20, 2018 9:00 pm

Android app - Raspi Card Imager - download and image SD cards - No PC required !

Return to “Python”