3

So, after searching a little bit... have found the following way to capture the input from my USB QR code scanner.

import sys
pipe = open('/dev/input/event3', 'r')
while 1:
        for character in pipe.read():
                print(character)

It works, but I still have 2 questions regarding the method above.

I'm on a Raspberry device with Debian Wheezy and a GUI, and can confirm Question 2 happening on a GUI... don't know yet the output on a system without GUI

  1. Any better way of doing it?
  2. The method above, when I click right the script cancels and outputs all the entries that have been scanned, at once. Why is that?

UPDATE

I think I have miss interpreted the result for the code above, as it finally it outputs ASCII characters, so I ended up doing the following:

sys.stdin = open('/dev/tty')
a = raw_input('Scan: ')

1 Answer 1

1

Question 1 really depends on your QR scanner. I think you are lucky this works like this, since much of the time, usb devices have complex protocols to communicate with hosts. For example, with a mouse, how would you differentiate between clicks and mouse movement? You need some kind of data format to exchange.

Question 2 is probably because your method blocks at pipe.read(), waiting for input. Somehow, only the right click ends the read() function and allows the print to work out

Sign up to request clarification or add additional context in comments.

6 Comments

well... the QR scanner, without any thing done by me, it outputted the result by its self to where it could (mostly terminal, as it's always opened)... so it was only a matter of grabbing that output
my guess is that your linux distro somehow loaded a driver for the scanner
you could try getting more information about it with either lsmod or lsusb, which should show which driver was loaded. This would allow you to find more documentation about it
this USB devices, gets identified as soon as plugged in. lsusb => Bus 001 Device 007: ID 05f9:2216 PSC Scanning, Inc. The complex thing it's done inside the scanner (converting the code) and then it's simple output... so no big mystery or heavy driver codding to get it to work
You need to understand that while the scanner probably does a good deal of processing, having a usb compatible device is a pretty complex task. usb.org/developers/devclass_docs/HID1_11.pdf. The driver will hide a lot of that complexity and present you with a nice /dev interface that you can use afterwards.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.