0

I am running Python 3 with Anaconda in a Windows 10 machine.

I am trying to connect to a usb barcode scanner in order to read barcodes and store them in variables in other python routine. I have found an example using PyUSB library and tried it. After a few modifications I was able to run it without raising errors. The program connects to the usb with the following code:

import usb.core
import usb.util

def main():
    # Find usb device
    dev = usb.core.find(idVendor=0x05E0, idProduct=0x1200)

    # Raise error if device not found
    if dev is None:
        raise ValueError('Device not found')

    else:
        # Set configuration of device
        dev.set_configuration()

        endpoint = dev[0][(0,0)][0]

        data = None

        while True:
            try:
                dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize, timeout=1) 
                print(data)

            except usb.core.USBError as e:
                data = None
                if e.args == ('Operation timed out',):
                    print("ERROR")
                    continue

if __name__ == '__main__':
    main()

As I say the program runs correctly and finds the usb. Nonetheless, data (barcode number) is never printed because the program seems to get stuck at following line:

dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize, timeout=1) 

Can you help me?

Thank you very much in advance!

1 Answers1

1

Using PyUSB to read barcodes is too complicated.
It is recommended to set the COM port mode in the following way and communicate with PySerial.

Download the device driver from this page.
USB CDC DRIVER FOR WINDOWS

Set the scanner to COM port mode with the procedure and setting barcode described on this page.
EMULATING A COM/SERIAL PORT OVER USB USING CDC DRIVER

Set both the scanner hardware/software handshaking settings described on pages 80 to 82 of this manual to None.
LS1203 Product Reference Guide - Zebra Technologies

Use PySerial to open and read the COM port assigned to the scanner.

If you scan the barcode with the scanner, you should be able to read the barcode data from the COM port.

This scanner is considered to be ready to read barcodes whenever the power is on.
The Enable/Disable function of reading does not appear to be published.


Based on the result report comment, the following options are considered.

  • Ask Zebra's support desk about whether or not it is possible.
  • Give up control in Python and use it in keyboard input emulation mode.
  • Give up the USB connection and use the RS232C connection cable.
kunif
  • 4,060
  • 2
  • 10
  • 30
  • Thanks a lot for the answer. I tried what you suggested but it did not work out. After installing the driver and scanning the barcode the COM port appears but the driver shows a warning and returns an error (Code 10). Checking the documentation of the driver I found that it is suitble for some devices amongst which my barcode scanner is not included. Do you know what else can I do? Thanks a lot in advance!! – Jesús González Rebordinos Sep 25 '18 at 15:41