PyUsb USB Barcode Scanner

前端 未结 2 592
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 11:04

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/m

相关标签:
2条回答
  • 2021-02-01 11:41

    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)
    
    0 讨论(0)
  • 2021-02-01 11:50

    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)
    
    0 讨论(0)
提交回复
热议问题