fazalmajid / cs1504

Python driver for the Symbol CS1504 bar code scanner
11 stars 11 forks source link

opticon OPN-2001 and Ubuntu 17.04LTS #9

Open kalon33 opened 6 years ago

kalon33 commented 6 years ago

Currently testing the opticon OPN-2001 with your program under Ubuntu 17.04LTS.

On the first run, I got:

Using device /dev/ttyUSB0...  connected
serial# 0000000000697227
SW version RBBV0143
reading clock for drift
clock drift -17441 days, 14:23:44.502896
WARNING: big gap between host & scanner clocks -17441 days, 14:23:44.502896
resetting scanner clock... done
reading barcodes...Traceback (most recent call last):
  File "./cs1504.py", line 333, in <module>
    barcodes = scanner.get_barcodes()
  File "./cs1504.py", line 244, in get_barcodes
    ts = datetime.datetime(y, m, d, h, mi, s) + self.delta
ValueError: month must be in 1..12

And on the second one, and others, I got:

Traceback (most recent call last):
  File "./cs1504.py", line 329, in <module>
    scanner = CS1504(serial_port)
  File "./cs1504.py", line 135, in __init__
    timeout=2)
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 240, in __init__
    self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 272, in open
    self._reconfigure_port(force_update=True)
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 438, in _reconfigure_port
    [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
termios.error: (22, 'Invalid argument')
Exception AttributeError: "CS1504 instance has no attribute 'ser'" in <bound method CS1504.__del__ of <__main__.CS1504 instance at 0x7f8be53ea128>> ignored

I could not get any barcode from it. Please help me fixing this

ernstki commented 4 years ago

Well, this is going to be a little late, and this likely won't fix your exact issue anyway, but I had a similar issue (not month, but second must be in 0..59), and here's how I fixed it.

I ran cs1504.py with the Python debugger (I use pdbpp), let it run until the error with c, and looked at the values that were being passed to datetime.datetime() post-mortem.

python2 -m pdb cs1504.py

Based on this traceback

Traceback — ValueError: second must be in 0..59

``` Traceback (most recent call last): File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pdb.py", line 1314, in main pdb._runscript(mainpyfile) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pdb.py", line 1233, in _runscript self.run(statement) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py", line 400, in run exec cmd in globals, locals File "", line 1, in File "cs1504.py", line 7, in import sys, time, datetime, serial, struct, pprint File "cs1504.py", line 249, in get_barcodes ts = datetime.datetime(y, m, d, h, mi, s) + self.delta ValueError: second must be in 0..59 ```

I saw s had a suspicious value of 255 (1111 11112), which led me to believe maybe my model didn't record timestamps down to the second, so I just clamped s to zero.

I made the following changes (not all of which will apply in your case; my serial port driver is different, for example), and then the script worked fine.

--- /dev/fd/63  2020-05-02 22:12:26.000000000 -0400
+++ /path/to/bin/cs1504.py  2020-05-02 22:12:20.000000000 -0400
@@ -1,4 +1,7 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2
 # Copyright (c) 2006-2007, Fazal Majid. All rights reserved
 # This code is hereby placed in the public domain
+#
+# source: https://github.com/fazalmajid/cs1504
+#
 import sys, time, datetime, serial, struct, pprint
@@ -6,3 +9,4 @@
 if sys.platform == 'darwin':
-  serial_port = '/dev/cu.usbserial'
+  #serial_port = '/dev/cu.usbserial'
+  serial_port = '/dev/cu.Repleo-PL2303-000013FA'
 elif sys.platform == 'linux2':
@@ -199,2 +203,3 @@
     y += 2000
+    s = s if 0 <= s <= 59 else 0
     ts = datetime.datetime(y, m, d, h, mi, s)
@@ -243,2 +248,3 @@
       s = int(t & 0x3f)
+      s = s if 0 <= s <= 59 else 0
       ts = datetime.datetime(y, m, d, h, mi, s) + self.delta

Maybe this helps… somebody?