Closed andrewshvv closed 3 years ago
Using strace I was able to see the write in the zebra-scanner log, the content of the log if:
root@d8cb2364e817:/home/statistics# cat /var/log/zebra-scanner/corescannerd/*
OS name : Ubuntu | OS version : 20.04.1 LTS (Focal Fossa) | kernal version : 4.19.130-boot2docker | system architecture : x86_64 | gcc version : 5.4.0 20160609 | udev version : /lib/x86_64-linux-gnu/libudev.so.1 | java version : openjdk 1.8.0_275 | libusb version : 1.0.9.0 | corescanner version : 4.4.1-15
20201211 | 18:26:52:282 | CLIENTLIB_COMMON | | | 31 | 139755555563328 | CsClientApiCore.cpp [571] | INFO | | | Open calling ConnectN
20201211 | 18:26:52:283 | CLIENTLIB_COMMON | | | 31 | 139755555563328 | CsConnector.cpp [48] | ERROR | | | Can't connect to corescanner. Returned error code : 111
20201211 | 18:26:52:283 | CLIENTLIB_COMMON | | | 31 | 139755555563328 | CsClientApiCore.cpp [574] | INFO | | | Open ConnectN return STATUS_ERROR
20201211 | 18:26:52:283 | CLIENTLIB_COMMON | | | 31 | 139755555563328 | CsClientApiCore.cpp [563] | INFO | | | Open sAppName: legacyXml, iScannerType: 65535
OS name : Ubuntu | OS version : 20.04.1 LTS (Focal Fossa) | kernal version : 4.19.130-boot2docker | system architecture : x86_64 | gcc version : 5.4.0 20160609 | udev version : /lib/x86_64-linux-gnu/libudev.so.1 | java version : openjdk 1.8.0_275 | libusb version : 1.0.9.0 | corescanner version : 4.4.1-15
20201211 | 18:26:52:377 | CLIENTLIB_COMMON | | | 31 | 139755555563328 | CsClientApiCore.cpp [571] | INFO | | | Open calling ConnectN
20201211 | 18:26:52:377 | CLIENTLIB_COMMON | | | 31 | 139755555563328 | CsConnector.cpp [48] | ERROR | | | Can't connect to corescanner. Returned error code : 111
20201211 | 18:26:52:378 | CLIENTLIB_COMMON | | | 31 | 139755555563328 | CsClientApiCore.cpp [574] | INFO | | | Open ConnectN return STATUS_ERROR
20201211 | 18:27:06:148 | CLIENTLIB_COMMON | | | 31 | 139755555563328 | CsClientApiCore.cpp [606] | INFO | | | Close starting
The most useful line for you might be this:
OS name : Ubuntu | OS version : 20.04.1 LTS (Focal Fossa) | kernal version : 4.19.130-boot2docker | system architecture : x86_64 | gcc version : 5.4.0 20160609 | udev version : /lib/x86_64-linux-gnu/libudev.so.1 | java version : openjdk 1.8.0_275 | libusb version : 1.0.9.0 | corescanner version : 4.4.1-15
@Sthing, @dayjaby I would appreciate your feedback. If you think this question is out of your scope of expertise or you just don't have time atm, please notify me. In this case, I will probably move on and would use some other environment setup, cause I run out of problem hypotheses.
Hi @andrewshvv .
Have you tried the linux sample app (/usr/share/zebra-scanner/samples/gui-app/bin/corescanner-gui-app)? That shoud work after installing the Zebra .deb-files. I guess that unless the sample app works there is no chance to get the python-binding working.
@Sthing Thanks for the response!
No, I haven't tried it, I will, thanks!
Seems as if I still haven't setup scanner properly, ::ExecCommand(CMD_RSM_ATTR_GETALL, inXml, outXml, &sId);
returns STATUS_ERROR
.
(gdb) list "Scanner::FetchAttributes()"
204 // in our on_scanner_added callback
205 s.FetchAttributes("0");
206 OnScannerAdded(o);
207 }
208
209 void Scanner::FetchAttributes() {
210 std::string inXml = "<inArgs><scannerID>"+scannerID+"</scannerID></inArgs>";
211 StatusID sId;
212 std::string outXml;
213
(gdb)
214 ::ExecCommand(CMD_RSM_ATTR_GETALL, inXml, outXml, &sId);
215
216 pugi::xml_document outargs;
217 outargs.load_buffer_inplace(&outXml[0], outXml.size());
218 std::string attribute_list;
219 bool first = true;
220 for(pugi::xml_node attr = outargs.child("outArgs").child("arg-xml").child("response").child("attrib_list").child("attribute");
221 attr;
222 attr = attr.next_sibling("attribute")) {
223 if(!first)
(gdb)
224 attribute_list += ',';
225 attribute_list += attr.child_value();
226 first = false;
227 }
228 FetchAttributes(attribute_list);
229 }
230
231 void Scanner::FetchAttributes(std::string attribute_list) {
232 std::string inXml = "<inArgs><scannerID>" + scannerID +
233 "</scannerID><cmdArgs><arg-xml><attrib_list>" +
(gdb) b "/home/statistics/zebra-scanner/src/BoostPythonCoreScanner.cpp:219"
Breakpoint 12 at 0x7ffff7988cec: file /home/statistics/zebra-scanner/src/BoostPythonCoreScanner.cpp, line 219.
(gdb) continue
Continuing.
[Switching to Thread 0x7ffff691e700 (LWP 171)]
Thread 3 "python3" hit Breakpoint 12, Scanner::FetchAttributes (this=0x7fffe80091a0) at /home/statistics/zebra-scanner/src/BoostPythonCoreScanner.cpp:220
220 for(pugi::xml_node attr = outargs.child("outArgs").child("arg-xml").child("response").child("attrib_list").child("attribute");
(gdb) info locals
attr = {_root = 0x7ffff691ccf0}
inXml = "<inArgs><scannerID>1</scannerID></inArgs>"
sId = STATUS_ERROR
outXml = ""
outargs = {<pugi::xml_node> = {_root = 0x7ffff691cc68}, _buffer = 0x0,
_memory = "\250\314\221\366\377\177", '\000' <repeats 18 times>, "\330\177", '\000' <repeats 14 times>, "\001(", '\000' <repeats 38 times>, "h\314\221\366\377\177", '\000' <repeats 18 times>, "@\314\221\366\377\177\000\000\330\177\000\000\000\000\000\000\340\313\221\366\377\177\000\000\000\000\000\000\000\000\000\000\374\202\231\367\377\177\000\000\340\314\221\366\377\177\000\000\000\000\000\000\000\000\000\000\060o\376\365\377\177", '\000' <repeats 18 times>, "@o\376\365\377\177\000"}
attribute_list = ""
first = true
(gdb)
CMD_RSM_ATTR_GETALL = 0x1388 (5000)
Log:
20201217 | 14:38:30:993 | CORESCANNER | | | 20 | 139774719411968 | CsClient.cpp [30] | INFO | | | cmd = 5000, cmd_id = 15, data_length = 4
20201217 | 14:38:30:994 | CORESCANNER | | | 20 | 139774719411968 | CsClient.cpp [234] | INFO | | | Routing Cmd to device
20201217 | 14:38:30:994 | CORESCANNER | | | 20 | 139774719411968 | CsClient.cpp [236] | INFO | | | Cmd Data|(4 bytes) = 00 00 00 01
20201217 | 14:38:30:994 | CORESCANNER | | | 20 | 139774719411968 | CsDeviceManager.cpp [1131] | INFO | | | CMD issued to a base device, device index is: 1
20201217 | 14:38:30:994 | CORESCANNER | | | 20 | 139774719411968 | CsDeviceManager.cpp [1135] | INFO | | | Addressed Device found
20201217 | 14:38:30:994 | CORESCANNER | | | 20 | 139774727804672 | CsOneConsumerManyProducersQ.h [80] | INFO | | | OneConsumerManyProducersQ::Consume: time_wait returns true
20201217 | 14:38:30:994 | CORESCANNER | | | 20 | 139774727804672 | CsOneConsumerManyProducersQ.h [105] | INFO | | | OneConsumerManyProducersQ::Consume: m_Queue.size(): 1
20201217 | 14:38:30:995 | CORESCANNER | | | 20 | 139774727804672 | CsDeviceHidkb.cpp [126] | ERROR | | | CommLib don't know how to handle opcode 5000
20201217 | 14:38:30:995 | CORESCANNER | | | 20 | 139774727804672 | CsDevice.cpp [216] | ERROR | | | Command failed
Okay.... completely accidentally I have installed an extension for Virtualbox, and turned on USB 2.0, instead of USB 1.0. Now I receive all information, but I scan the QR code it ends with segmentation fault:
root@86e40ac01a45:/home/statistics# python3 main.py
cat: write error: Broken pipe
New scanner found: <F6041394E2C0499E8DE4625340FC109A>
None
dict_items([(0, <zebra_scanner.Attribute object at 0x7fa053da8e70>)])
{'datatype': 'F', 'id': 0, 'permission': 7, 'value': True}
Registering scanner -F6041394E2C0499E8DE4625340FC109A-
Start
New scanner found: <F6041394E2C0499E8DE4625340FC109A>
None
dict_items([(0, <zebra_scanner.Attribute object at 0x7fa053da8070>)])
{'datatype': 'F', 'id': 0, 'permission': 7, 'value': True}
Registering scanner -F6041394E2C0499E8DE4625340FC109A-
None
Scanned:
pSHPs0924B381501JX 3
Segmentation fault (core dumped)
VirtualBox 6.1.16 Oracle VM VirtualBox Extension Pack
Support for USB 2.0 and USB 3.0 devices, VirtualBox RDP, disk encryption, NVMe and PXE boot for Intel cards. See this chapter from the User Manual for an introduction to this Extension Pack. The Extension Pack binaries are released under the VirtualBox Personal Use and Evaluation License (PUEL). Please install the same version extension pack as your installed version of VirtualBox.
Can you share your main.py or run your gdb analysis again?
Currently trying to rebuild zebra-scanner with -O0
flag in order to get a bit more info in gdb
Barcode scanned successfully and triggers the print:
@scanner.on_barcode
def on_barcode(barcode):
print("Scanned:")
print(barcode.code, barcode.type)
Output:
Scanned:
pSHPs0924B381501JX 3
But at the event of Barcode deallocation segfault happens:
(gdb) list
756 #endif
757
758 /// RAII wrapper that temporarily clears any Python error state
759 struct error_scope {
760 PyObject *type, *value, *trace;
761 error_scope() { PyErr_Fetch(&type, &value, &trace); }
762 ~error_scope() { PyErr_Restore(type, value, trace); }
763 };
764
765 /// Dummy destructor wrapper that can be used to expose classes with a private destructor
(gdb) list pybind11::class_<Barcode>::dealloc
1504 }
1505 init_holder(inst, v_h, (const holder_type *) holder_ptr, v_h.value_ptr<type>());
1506 }
1507
1508 /// Deallocates an instance; via holder, if constructed; otherwise via operator delete.
1509 static void dealloc(detail::value_and_holder &v_h) {
1510 // We could be deallocating because we are cleaning up after a Python exception.
1511 // If so, the Python error indicator will be set. We need to clear that before
1512 // running the destructor, in case the destructor code calls more Python.
1513 // If we don't, the Python API will exit with an exception, and pybind11 will
(gdb)
1514 // throw error_already_set from the C++ destructor which is forbidden and triggers
1515 // std::terminate().
1516 error_scope scope;
1517 if (v_h.holder_constructed()) {
1518 v_h.holder<holder_type>().~holder_type();
1519 v_h.set_holder_constructed(false);
1520 }
1521 else {
1522 detail::call_operator_delete(v_h.value_ptr<type>(),
1523 v_h.type->type_size,
(gdb)
1524 v_h.type->type_align
1525 );
1526 }
1527 v_h.value_ptr() = nullptr;
1528 }
1529
1530 static detail::function_record *get_function_record(handle h) {
1531 h = detail::get_function(h);
1532 return h ? (detail::function_record *) reinterpret_borrow<capsule>(PyCFunction_GET_SELF(h.ptr()))
1533 : nullptr;
(gdb) s
Thread 3 "python3" received signal SIGSEGV, Segmentation fault.
0x0000000000558f6f in PyErr_Fetch ()
(gdb) info frames
Undefined info command: "frames". Try "help info".
(gdb) backtrace
#0 0x0000000000558f6f in PyErr_Fetch ()
#1 0x00007ffff794a583 in pybind11::error_scope::error_scope (this=0x7ffff68ce3c0) at /usr/local/lib/python3.8/dist-packages/pybind11/include/pybind11/detail/common.h:761
#2 0x00007ffff79676fd in pybind11::class_<Barcode>::dealloc (v_h=...) at /usr/local/lib/python3.8/dist-packages/pybind11/include/pybind11/pybind11.h:1516
#3 0x00007ffff7952761 in pybind11::detail::clear_instance (self=0x7ffff79e8fb0) at /usr/local/lib/python3.8/dist-packages/pybind11/include/pybind11/detail/class.h:402
#4 0x00007ffff7952863 in pybind11::detail::pybind11_object_dealloc (self=0x7ffff79e8fb0) at /usr/local/lib/python3.8/dist-packages/pybind11/include/pybind11/detail/class.h:422
#5 0x00007ffff7944ac9 in _Py_DECREF (filename=0x7ffff7988028 "/usr/include/python3.8/object.h", lineno=541, op=0x7ffff79e8fb0) at /usr/include/python3.8/object.h:478
#6 0x00007ffff794a11e in _Py_XDECREF (op=0x7ffff79e8fb0) at /usr/include/python3.8/object.h:541
#7 0x00007ffff794a6eb in pybind11::handle::dec_ref() const & (this=0x7ffff68ce5e0) at /usr/local/lib/python3.8/dist-packages/pybind11/include/pybind11/pytypes.h:199
#8 0x00007ffff794a7b2 in pybind11::object::~object (this=0x7ffff68ce5e0, __in_chrg=<optimized out>) at /usr/local/lib/python3.8/dist-packages/pybind11/include/pybind11/pytypes.h:242
#9 0x00007ffff7948a9d in CoreScanner::OnBarcodeEvent (this=0x9aed90, eventType=0,
pscanData="<outArgs\000<scannerID\000\061\000/scannerID><arg-xml\000<scandata\000<modelnumber\000DS2208-SR00007ZZWW\000/modelnumber><serialnumber\000\062\060\062\061\066\060\061\060\065\065\060\070\070\063 \000/serialnumber><GUID\000F6041394E2C0499E8DE4625340FC109A\000/GUID><datatype\000\063\000/"...) at /home/scanner-worker/zebra-scanner/src/BoostPythonCoreScanner.cpp:469
#10 0x00007ffff76e6197 in EventListenerXmlImpl::OnBarcodeEvent(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned char*, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) () from /usr/lib/zebra-scanner/corescanner/libcs-client.so
#11 0x00007ffff76aa4f9 in ?? () from /usr/lib/zebra-scanner/corescanner/libcs-client.so
#12 0x00007ffff76bf81d in boost::detail::thread_data<void (*)()>::run() () from /usr/lib/zebra-scanner/corescanner/libcs-client.so
#13 0x00007ffff76f1c3d in ?? () from /usr/lib/zebra-scanner/corescanner/libcs-client.so
#14 0x00007ffff7db5609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#15 0x00007ffff7ef1293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
@dayjaby Moving to pybind11==2.5.0
from 2.6.1
resolved the issue!! 🎊
pip3 install pybind11==2.5.0
Probably README has to mention that there might be troubles with 2.6.1
version, it might help others to avoid the issue.
Hey!
I am using mac os + virtual box + docker with ubuntu 20.04.
I have successfully installed all the packages and was able to start the example script. I have forwarded USB port and able to see the content when using "cat /dev/ttyUSB0" and scanning the QR code. The command lsusb also shows that the scanner has been identified.
But script is not seeing the scanner, is there any way to debug the issue?
Output in docker container when scanning something:
docker-compose.yaml:
Dockerfile