Merge remote-tracking branch 'origin/BARCODE-POKA-YOKE' into BARCODE-POKA-YOKE
This commit is contained in:
commit
301c31eb9c
|
|
@ -5,7 +5,11 @@ import subprocess
|
|||
import tarfile
|
||||
import traceback
|
||||
|
||||
import cv2
|
||||
# OpenCV is optional: only needed for commented image endpoints; avoid hard dependency at import time
|
||||
try:
|
||||
import cv2 # noqa: F401
|
||||
except Exception:
|
||||
cv2 = None # type: ignore
|
||||
from bottle import post, request, response, route, run
|
||||
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
|
|
|||
|
|
@ -10,6 +10,14 @@ from src.lib.nfc.clf import RemoteTarget
|
|||
|
||||
|
||||
class RFID_PN532(Component):
|
||||
"""
|
||||
Windows note:
|
||||
Some environments on Windows have a known issue where writing log output to the
|
||||
console can raise AttributeError: characters_written (typically from win32console
|
||||
when wrapped by certain stream handlers). To prevent this from crashing the
|
||||
component, we route such errors through a safe logger that falls back to
|
||||
printing to stderr.
|
||||
"""
|
||||
new_id_signal = pyqtSignal(str)
|
||||
rfid_error_signal = pyqtSignal(bool)
|
||||
|
||||
|
|
@ -30,10 +38,34 @@ class RFID_PN532(Component):
|
|||
self._fail_log_limit = 10
|
||||
self._fail_log_suppressed = False
|
||||
|
||||
def _safe_log(self, level, msg, exc: Exception = None):
|
||||
try:
|
||||
if exc is not None:
|
||||
msg = f"{msg}: {exc}"
|
||||
getattr(self.log, level)(msg)
|
||||
except AttributeError as ae:
|
||||
# Workaround for Windows console logger bug: AttributeError: characters_written
|
||||
if str(ae) == 'characters_written':
|
||||
try:
|
||||
import sys as _sys
|
||||
_sys.stderr.write(f"[RFID_PN532:{level}] {msg}\n")
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
|
||||
def open_device(self):
|
||||
self.clf = src.lib.nfc.ContactlessFrontend()
|
||||
for dev in self.dev_list:
|
||||
self.connected = self.clf.open(dev)
|
||||
try:
|
||||
self.connected = self.clf.open(dev)
|
||||
except Exception as e:
|
||||
self.connected = False
|
||||
msg = "RFID open failed"
|
||||
# Make timeout on Windows (WinError 10060) more explicit
|
||||
if '10060' in str(e):
|
||||
msg = "RFID open timed out (WinError 10060). Check COM port and PN532 wiring/power."
|
||||
self._safe_log('info', f"{msg} on {dev}", e)
|
||||
if self.connected:
|
||||
# Reset failure log suppression on successful connection
|
||||
self._fail_log_count = 0
|
||||
|
|
@ -100,7 +132,7 @@ class RFID_PN532(Component):
|
|||
self.rfid_error_signal.emit(self.connected)
|
||||
|
||||
except Exception as e:
|
||||
self.log.info(f"{e}")
|
||||
self._safe_log('info', 'RFID runtime error', e)
|
||||
self.connected = False
|
||||
finally:
|
||||
if not self.connected:
|
||||
|
|
@ -135,7 +167,7 @@ class RFID_PN532(Component):
|
|||
else:
|
||||
self.log.debug("No tag present for writing")
|
||||
except Exception as e:
|
||||
self.log.error(f"Error during tag writing: {e}")
|
||||
self._safe_log('error', 'Error during tag writing', e)
|
||||
finally:
|
||||
# Move closing outside the try block
|
||||
self.mutex.unlock() # Unlock mutex always
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ import shutil
|
|||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import cv2
|
||||
# OpenCV is optional; only needed when saving frames
|
||||
try:
|
||||
import cv2 # noqa: F401
|
||||
except Exception:
|
||||
cv2 = None # type: ignore
|
||||
import numpy as np
|
||||
|
||||
from .component import Component
|
||||
|
|
|
|||
|
|
@ -20,4 +20,5 @@ requests
|
|||
#tensorflow
|
||||
#tflite-runtime
|
||||
zebra
|
||||
pylibdmtx~=0.1.10
|
||||
pylibdmtx~=0.1.10
|
||||
opencv-python
|
||||
Loading…
Reference in New Issue
Block a user