I need to read a barcode data using a usb barcode reader (raw data mode). I already know that I can set the reader with the keyboard mode but it just doesn't fit my requirement because I'll be using 4 readers simultaneously and the text will overlap.
I am new to python and i've tried researching it myself to no avail. I got these idea through the documentation and I really don't know what's wrong with it.
Here's the sample code that i've come up so far:
import sys
import usb.core
import usb.util
# got these using the command lsusb -vv
VENDOR_ID = 0x4b4
PRODUCT_ID = 0x100
DATA_SIZE = 1
device = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
if device is None:
sys.exit("Could not find Id System Barcode Reader.")
if device.is_kernel_driver_active(0):
try:
device.detach_kernel_driver(0)
except usb.core.USBError as e:
sys.exit("Could not detatch kernel driver: %s" % str(e))
#not really sure if these are correct configuration.
try:
cfg = device.get_active_configuration()
for i in cfg:
for x in i:
x = x
device.set_configuration()
except usb.core.USBError as e:
sys.exit("Could not set configuration: %s" % str(e))
data = []
swiped = False
#i can't print the data when i try to read a barcode
data = device.read(x.bEndpointAddress, x.wMaxPacketSize, 0, 10000)
print data
After running this and trying out a barcode i get this error.
Traceback (most recent call last):
File "barcodesensor.py", line 37, in <module>
data = device.read(x.bEndpointAddress, x.wMaxPacketSize, 0, 10000)
File "/usr/local/lib/python2.6/dist-packages/usb/core.py", line 654, in read
self.__get_timeout(timeout)
File "/usr/local/lib/python2.6/dist-packages/usb/backend/libusb10.py", line 559, in intr_read
timeout)
File "/usr/local/lib/python2.6/dist-packages/usb/backend/libusb10.py", line 641, in __read
timeout))
File "/usr/local/lib/python2.6/dist-packages/usb/backend/libusb10.py", line 403, in _check
raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 110] Operation timed out.
I am willing to donate via PayPal to anyone who can help me in obtaining the raw data and converting the format to string. Thanks in advance.
EDIT: How do I obtain the correct data from the barcode and convert it to the readable string format?