I am trying to use a USB barcode scanner with a BBB on a Python project. The scanner works like a keyboard: you scan a barcode and it appears as if you had typed it in. I can even verify this works with a 4D Systems display connected to the BBB and an open terminal window on the display. Scan a barcode and it appears in the terminal window (followed by a "command not found" error or similar, but that's just a humorous aside).
The problem is, since I don't like developing on a 4.3" display, I SSH into the BBB. But then sdin is tied to the keyboard at the far end of the shell connection, so the Python input function won't read the barcode scanner. So my questions are:
• Is there a way to point the Python input function to another device in the tree rather than stdin? The scanner does appear in /dev/input/by-id as usb-13ba_Barcode_Reader-event-kbd.
• If that doesn't work, what other lower-level methods can I use to read the keyboard output from the barcode scanner? I did a sudo cat on that device I named above and it did put out some seemingly orderly gibberish. There must be some way to interpet that?
One last note - this scanner does have a "serial" mode, but I think it is not a serial USB emulator. I think it wants to be connected to an actual serial port at that point.
Thanks in advance!
Don
Python on BBB - Reading a 2nd Keyboard (Barcode Scanner)
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- dpancoe
- Posts: 18
- Joined: Thu Sep 06, 2012 10:28 am
- drewfustini
- Posts: 944
- Joined: Sat Dec 26, 2015 1:19 pm
Re: Python on BBB - Reading a 2nd Keyboard (Barcode Scanner)
this post shows how to interept the input stream:
https://thehackerdiary.BANNED.com/ta ... ut-python/
You might also want to use the evdev module:
https://python-evdev.readthedocs.io/en/ ... orial.html
https://thehackerdiary.BANNED.com/ta ... ut-python/
You might also want to use the evdev module:
https://python-evdev.readthedocs.io/en/ ... orial.html
- dpancoe
- Posts: 18
- Joined: Thu Sep 06, 2012 10:28 am
Re: Python on BBB - Reading a 2nd Keyboard (Barcode Scanner)
Thank you for this great information!
Just by following the "quick start" in the evdev docs, I was able to capture the output below. The barcode I was attempting to scan is "000101-4919-01". It will take more work from here, of course, but this is a great start.
Don
Just by following the "quick start" in the evdev docs, I was able to capture the output below. The barcode I was attempting to scan is "000101-4919-01". It will take more work from here, of course, but this is a great start.
Don
Code: Select all
debian@beaglebone:/dev/input$ sudo python
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import evdev
>>> device = evdev.InputDevice('/dev/input/event1')
>>> print(device)
device /dev/input/event1, name "Barcode Reader ", phys "usb-musb-hdrc.1-1/input0"
>>> for event in device.read_loop():
... if event.type == evdev.ecodes.EV_KEY:
... print(evdev.categorize(event))
...
key event at 1572732079.660701, 11 (KEY_0), down
key event at 1572732079.664670, 11 (KEY_0), up
key event at 1572732079.666663, 11 (KEY_0), down
key event at 1572732079.670642, 11 (KEY_0), up
key event at 1572732079.672668, 11 (KEY_0), down
key event at 1572732079.674651, 11 (KEY_0), up
key event at 1572732079.678680, 2 (KEY_1), down
key event at 1572732079.680712, 2 (KEY_1), up
key event at 1572732079.684680, 11 (KEY_0), down
key event at 1572732079.686688, 11 (KEY_0), up
key event at 1572732079.690679, 2 (KEY_1), down
key event at 1572732079.692649, 2 (KEY_1), up
key event at 1572732079.694662, 12 (KEY_MINUS), down
key event at 1572732079.698649, 12 (KEY_MINUS), up
key event at 1572732079.700667, 5 (KEY_4), down
key event at 1572732079.704666, 5 (KEY_4), up
key event at 1572732079.706662, 10 (KEY_9), down
key event at 1572732079.710648, 10 (KEY_9), up
key event at 1572732079.712666, 2 (KEY_1), down
key event at 1572732079.716665, 2 (KEY_1), up
key event at 1572732079.718661, 10 (KEY_9), down
key event at 1572732079.722648, 10 (KEY_9), up
key event at 1572732079.724678, 12 (KEY_MINUS), down
key event at 1572732079.726648, 12 (KEY_MINUS), up
key event at 1572732079.730678, 11 (KEY_0), down
key event at 1572732079.732654, 11 (KEY_0), up
key event at 1572732079.736678, 2 (KEY_1), down
key event at 1572732079.738648, 2 (KEY_1), up
key event at 1572732079.742676, 28 (KEY_ENTER), down
key event at 1572732079.744653, 28 (KEY_ENTER), up
- dpancoe
- Posts: 18
- Joined: Thu Sep 06, 2012 10:28 am
Re: Python on BBB - Reading a 2nd Keyboard (Barcode Scanner)
As a follow-up to this thread, I found this additional sample code that converts the keyboard events into a usable text string.
https://raspberrypi.stackexchange.com/q ... -to-python
Don
https://raspberrypi.stackexchange.com/q ... -to-python
Don
Please be positive and constructive with your questions and comments.