I have a following code which I use to catch input from bar code scanner. The problem is in that I want to save whole scanned code in database, but every character of code prints on new line:
#!/usr/bin/env python
from evdev import InputDevice, ecodes, list_devices
from select import select
keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX"
dev = InputDevice("/dev/input/event10")
barcode = ""
while True:
r,w,x = select([dev], [], [])
for event in dev.read():
if event.type == 1 and event.value == 1:
barcode += (keys[event.code])
print barcode
# sudo ./bar-code-test.py
#0
#00
#00
#000
#001
#1001
#0017
#70017
#00170
#000170
#001708
#8001708
#0017085
#50017085
#00170853
#300170853
#001708531
#1001708531
#0017085316
#60017085316
#00170853160
#000170853160
#001708531601
#1001708531601
#0017085316013
#30017085316013
#00170853160131
#100170853160131
#00170853160131X
#00170853160131X
I Am newbie with python, so any help will be appreciated.
Found a solution. Bar code scanner after each scanned code send 42 scan code (Enter key), so we need check scan code:
What about if you read the length of the string, and until it reaches your desired value or length, you exit the loop and print out the barcode read.
I modified the code like this and it just prints one line:
I tried it in Arduino Yun, with OpenWrt, and it worked just fine: