Skip to content Skip to sidebar Skip to footer

PyUsb USB Barcode Scanner

I'm trying to output a string from a barcode or qrcode using a Honeywell USB 3310g scanner in Ubuntu. I have libusb and a library called metro-usb (http://gitorious.org/other/metro

Solution 1:

Grab a Quick Start Guide, scan "USB Serial"-mode barcode, then "Save" barcode to make this setting permanent. Now your 3310g is in serail emulation mode, note new /dev/ttyACM0 or /dev/ttyUSB0 device. Read serial port with simple file operations from python:

f = open('/dev/ttyACM0')
print f.read(13)

Solution 2:

The error you're receiving is from this line:

lecture+=NO_SCAN_CODE[data[n+2]]

and data[n+2] = 11, which equates to doing the following

NO_SCAN_CODE[11]

NO_SCAN_CODE is a dictionary that only contains values for the keys [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40], not 11.

The fact that you're getting this error means that you've received a usb.core.USBError, and len(data) >= DATA_SIZE.


If I was debugging this, I'd add a whole lot more print statements. I suggest trying something simple like this initially, then adding more logic when you figure out what the device is returning:

# Initialise variables
VENDOR_ID = 0x0c2e
PRODUCT_ID = 0x0b61

# Set up device
device = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
print device

# Do more setup things here
# detach_kernel_driver and set_configuration ?
# Perhaps try these in combination with reading the usb.core documentation, and see what happens?

# Loop 10 times (to start with - try more later?)
for i in range(10):
    # Don't catch any errors, just print what the device is returning
    print device.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize)

Post a Comment for "PyUsb USB Barcode Scanner"