dayjaby / zebra-scanner

Read barcodes in python with zebra barcode scanner
MIT License
24 stars 18 forks source link

The scanner.on_barcode is not working used below code #19

Closed yogesh7219 closed 3 years ago

yogesh7219 commented 3 years ago

Used below code to scan the QRcode. The Scanners are getting added and removed but how can I get the actual Scanned code

import time

from zebra_scanner import CoreScanner, Barcode import zebra_scanner

cs = CoreScanner() scanners = []

@cs.on_scanner_added def on_scanner_added(scanner): scanners.append(scanner) scanner.pull_trigger() scanner.fetch_attributes() print("Added : "+scanner.GUID) print(scanner.PID) print(scanner.attributes) @scanner.on_barcode def on_barcode(barcode): print(barcode.code)

@cs.on_scanner_removed def on_scanner_removed(scanner): print("Scanner removed:") scanner.release_trigger() scanner.remove(scanner)

while True: time.sleep(0.1)

do nothing while the scanner is reading in continuous mode

dayjaby commented 3 years ago

Is this callback function not getting called?

@scanner.on_barcode
def on_barcode(barcode):
print(barcode.code)
yogesh7219 commented 3 years ago

Yes, it is not getting called.

HennethAnnun commented 3 years ago

I can confirm the @scanner.on_barcode is not getting called. Installed via setup.py. No errors on install. Would you be so kind and have a look at the issue? Thanks!

Some details of my environment: (zebra-scanner-master) ubuntu@printer01:~$ lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 021: ID 05e0:1200 Symbol Technologies Bar Code Scanner Bus 001 Device 018: ID 04b8:0202 Seiko Epson Corp. Receipt Printer M129C/TM-T70 Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

(zebra-scanner-master) ubuntu@printer01:~$ uname -a Linux printer01 5.4.0-1038-raspi #41-Ubuntu SMP PREEMPT Thu Jun 17 14:14:11 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux

(zebra-scanner-master) ubuntu@printer01:~/installs/zebra-scanner-master$ python --version Python 3.8.10

Tested with pybind11 = "==2.5.0" pybind11 = "*"

As mentioned, I installed your code via setup.py. Previously tried installing via pip3 (pipenv) but I got compile errors.

The device is Raspberry Pi 4 8GB ram with Ubuntu 20.04. gcc swapped to clang version 10.

The CoreScanner .on_scanner_added and .on_scanner_removed seem to work. .fetch_attributes() returns an empty object Some variables in the scanner are not filled: DoM: '' attributes: {} firmware: '' modelnumber: '' serialnumber: ''

I get those variables filled: GUID, PID, VID, scannerID and type.

The SDK from Zebra used: SDK_for_RaspberryPi_v4.4.1-19_Debian_Packages_ARM_64bit.zip installed via dpkg. No errors.

Logs: When attaching the device I get a lot of input. There are some errors though: (zebra-scanner-master) ubuntu@printer01:/var/log/zebra-scanner/corescannerd$ sudo tail -f CORESCANNER_2021.07.12_15-31-14_0002.log | grep "ERROR"

20210712 | 17:24:41:437 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5007 20210712 | 17:24:41:438 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:440 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5007 20210712 | 17:24:41:440 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:486 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5007 20210712 | 17:24:41:487 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:487 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5007 20210712 | 17:24:41:487 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:493 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5007 20210712 | 17:24:41:493 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:497 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5007 20210712 | 17:24:41:497 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:498 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5001 20210712 | 17:24:41:498 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:547 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 2011 20210712 | 17:24:41:547 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:548 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5007 20210712 | 17:24:41:548 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:555 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5007 20210712 | 17:24:41:555 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:556 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5000 20210712 | 17:24:41:556 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:560 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5001 20210712 | 17:24:41:560 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:647 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5001 20210712 | 17:24:41:647 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:652 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 2011 20210712 | 17:24:41:653 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:658 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5000 20210712 | 17:24:41:658 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:41:661 | CORESCANNER | | | 1133 | 281472778318272 | CsDeviceHidkb.cpp [135] | ERROR | | | CommLib don't know how to handle opcode 5001 20210712 | 17:24:41:661 | CORESCANNER | | | 1133 | 281472778318272 | CsDevice.cpp [216] | ERROR | | | Command failed 20210712 | 17:24:42:547 | CORESCANNER | | | 1133 | 281472837067200 | CsDeviceManager.cpp [461] | ERROR | | | A device with ID E55ED1C655B88549B8E41CA8F66B464B has already already been plugged in

dayjaby commented 3 years ago

I have ordered a zebra scanner a few days ago, so I can help with this again :)

HennethAnnun commented 3 years ago

Comment from Lazerkill solved my issue: https://github.com/dayjaby/zebra-scanner/issues/20#issuecomment-871104199

After turning the scanner to USB SNAPI as described in ZEBRA SCANNER SDK FOR LINUX DEVELOPER’S GUIDE, page 4-7, the error is gone. I also receive attributes now. I don't get any segmentation failures. I am scanning QR Codes. Device: DS457

My env: Raspberry Pi 4, 8 GB Ram Ubuntu 20.04 Python 3.8.10 pipenv pybind11 = "==2.5.0" installed via setup.py (not via pip3!) SDK_for_RaspberryPi_v4.4.1-19_Debian_Packages_ARM_64bit

HennethAnnun commented 3 years ago

Cancel that.

Segmentation fault (core dumped)

dayjaby commented 3 years ago

@HennethAnnun can you check master branch? https://github.com/dayjaby/zebra-scanner/pull/21 provides a solution.