diff --git a/config/machine_settings/st-ten-7.ini b/config/machine_settings/st-ten-7.ini index 513dfcb..2613397 100644 --- a/config/machine_settings/st-ten-7.ini +++ b/config/machine_settings/st-ten-7.ini @@ -1,5 +1,5 @@ [machine] -description = ST-TEN-6 DOPPIA PROVA PRESSIONE 6/20 BAR +description = ST-TEN-7 SECONDO BANCO IVECO DAILY ELETTRICO [hardware_config] archive_synchronizer: present diff --git a/config/machine_settings/st-ten-8.ini b/config/machine_settings/st-ten-8.ini index 6138090..3ad5342 100644 --- a/config/machine_settings/st-ten-8.ini +++ b/config/machine_settings/st-ten-8.ini @@ -1,5 +1,5 @@ [machine] -description = ST-TEN-8 COLLAUDO DAILY AUTOMATICO +description = ST-TEN-8 DAILY AUTOMATICO [hardware_config] archive_synchronizer: present @@ -13,7 +13,7 @@ vision: absent screwdriver: absent digital_io: present second_leak_test: absent -fixture_auto_id: present +fixture_id: present discard_box: present [tecna_t3] @@ -28,6 +28,9 @@ printer: zd421 id: USB-5860,BID#0 discard_idx:15 # BIT NUMBER OF THE I/0 MODULE USED FOR DISCARD SENSING +[fixture_rfid] +port: COM5 + [recipe] recipe_name_field: codice_ricetta part_number_field: codice_prodotto diff --git a/src/components/rfid.py b/src/components/rfid.py new file mode 100644 index 0000000..69af776 --- /dev/null +++ b/src/components/rfid.py @@ -0,0 +1,42 @@ +import ctypes +import sys +import platform +from PyQt5.QtCore import QMutex, Qt, QTimer, pyqtSlot, pyqtSignal +from .component import Component +import nfc +from nfc.clf import RemoteTarget + + + +is_win = platform.system() == "Windows" + +class RFID(Component): + def __init__(self, config=None, name=None, period=1, lazy=True, paused=False, threaded=True): + super().__init__(config=config, name=name, period=period, lazy=lazy, paused=paused, threaded=threaded) + self.mutex = QMutex() + self.simulate="--sim-rfid" in sys.argv + self.clf = nfc.ContactlessFrontend() + + def open_device(self): + self.clf.open('tty:USB0:pn532') + + def close_device(self): + pass + + @pyqtSlot() + def start(self): + # ACQUISITION TIMER + self.timer = QTimer() + self.timer.setTimerType(Qt.PreciseTimer) + self.timer.setInterval(int(1000 / 20)) + self.timer.timeout.connect(self.get) + self.timer.start() + super().start() + + @pyqtSlot() + def get(self): + data=None + if data is not None: + super()._get([data]) + + diff --git a/src/test/rfid.py b/src/test/rfid.py new file mode 100644 index 0000000..b11665c --- /dev/null +++ b/src/test/rfid.py @@ -0,0 +1,34 @@ +import time +import ndef +import nfc +from nfc.clf import RemoteTarget + +clf = nfc.ContactlessFrontend() +assert clf.open('tty:USB0:pn532') is True # open /dev/ttyUSB0 with pn532 driver + +while True: + target = clf.sense(RemoteTarget('106A'), RemoteTarget('106B'), RemoteTarget('212F')) + if target is not None: + tag = nfc.tag.activate(clf, target) + print(tag) + if tag.ndef is not None: + for record in tag.ndef.records: + print(record) + else: + print("EMPTY TAG - WRITING...") + if not tag.ndef.is_writeable: + print("This Tag is not writeable.") + break + tag.format() + ret = tag.wr + + if ret: + print("ERROR") + else: + print("OK") + else: + print("NO TARGET") + time.sleep(0.1) + +print("EXITING") +clf.close() \ No newline at end of file diff --git a/src/ui/rfid_recipe_selection/__init__.py b/src/ui/rfid_recipe_selection/__init__.py new file mode 100644 index 0000000..b3a3f30 --- /dev/null +++ b/src/ui/rfid_recipe_selection/__init__.py @@ -0,0 +1 @@ +from .rfid_recipe_selection import RFID_Recipe_Selection diff --git a/src/ui/rfid_recipe_selection/rfid_recipe_selection.py b/src/ui/rfid_recipe_selection/rfid_recipe_selection.py new file mode 100644 index 0000000..9b2ee0b --- /dev/null +++ b/src/ui/rfid_recipe_selection/rfid_recipe_selection.py @@ -0,0 +1,85 @@ +import sys + +import peewee +from PyQt5 import Qt + +from lib.helpers import timing +from PyQt5.QtCore import Qt, QTimer, QThread +from PyQt5.QtGui import QKeySequence, QPixmap, QPalette, QColor +from PyQt5.QtWidgets import QShortcut, QApplication +from ui.widget import Widget +from lib import db +from lib.db.models import Recipes + +class RFID(Widget): + def __init__(self, parent): + super().__init__() + self.parent=parent + self.recipe_db_model=Recipes + self.status_palettes = { + True: QPalette(), + "": QPalette(), + "warning": QPalette(), + False: QPalette(), + None: QPalette(), + } + self.status_palettes[True].setColor(QPalette.Base, Qt.green) + self.status_palettes[False].setColor(QPalette.Base, Qt.red) + self.status_palettes["warning"].setColor(QPalette.Base, QColor(255, 165, 0)) + self.status_palettes[""].setColor(QPalette.Base, QColor(255, 255, 0)) + + self.delay_timer = QTimer() + self.delay_timer.setSingleShot(True) + self.delay_timer.timeout.connect(self.reset_display) + + self.ok_timer = QTimer() + self.ok_timer.setSingleShot(True) + self.ok_timer.timeout.connect(self.set_recipe) + + def start(self, recipe=None, step=None, pieces=None): + + self.rfid_input_l.setPalette(self.status_palettes[None]) + self.rfid_input_l.setPlainText("") + + def get(self, data=None, override=False): + if not len(data): + data = None + if data is None: + return + else: + lines = data + if lines[0]=="ERRECINQUE RFID": + # RECIPE CODE FOUND + self.recipe=lines[1] + self.rfid_input_l.setPalette(self.status_palettes[True]) + self.ok_timer.start(2000) + + else: + # RECIPE CODE NOT FOUND + self.rfid_input_l.setPalette(self.status_palettes[False]) + self.instruction_text("FORMATO RFID DIMA NON VALIDO", "red") + self.delay_timer.start(3000) + + # LOOKUP RECIPE + + def set_recipe(self): + try: + recipe = self.recipe_db_model.get_by_id(self.recipe) + self.parent.set_recipe(recipe) + except peewee.DoesNotExist: + self.rfid_input_l.setPalette(self.status_palettes[False]) + self.instruction_text("RICETTA NON TROVATA","red") + self.delay_timer.start(3000) + + + def reset_display(self): + self.rfid_input_l.setFocus() + self.rfid_input_l.setPlainText("") + self.rfid_input_l.setPalette(self.status_palettes[""]) + self.instruction_text("SCANSIONARE BARCODE SELEZIONE RICETTA") + + def instruction_text(self,text,color=None): + if getattr(self.parent.centralWidget, "set_text"): + self.parent.centralWidget.set_text(text, color=color) + + diff --git a/src/ui/rfid_recipe_selection/rfid_recipe_selection.ui b/src/ui/rfid_recipe_selection/rfid_recipe_selection.ui new file mode 100644 index 0000000..2805d48 --- /dev/null +++ b/src/ui/rfid_recipe_selection/rfid_recipe_selection.ui @@ -0,0 +1,95 @@ + + + Test_Connector + + + + 0 + 0 + 1445 + 793 + + + + Test Connector + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 200 + 200 + + + + + 12 + + + + + + + + + + + + 600 + 0 + + + + + 600 + 200 + + + + + 20 + + + + 123 +456 +abc + + + + + + + + 20 + + + + TORNA ALLA TABELLA RICETTE + + + + + + + +