rfid wip
This commit is contained in:
parent
0617d0f4bb
commit
66b94fef6f
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
42
src/components/rfid.py
Normal file
42
src/components/rfid.py
Normal file
@ -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])
|
||||
|
||||
|
||||
34
src/test/rfid.py
Normal file
34
src/test/rfid.py
Normal file
@ -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()
|
||||
1
src/ui/rfid_recipe_selection/__init__.py
Normal file
1
src/ui/rfid_recipe_selection/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .rfid_recipe_selection import RFID_Recipe_Selection
|
||||
85
src/ui/rfid_recipe_selection/rfid_recipe_selection.py
Normal file
85
src/ui/rfid_recipe_selection/rfid_recipe_selection.py
Normal file
@ -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)
|
||||
|
||||
|
||||
95
src/ui/rfid_recipe_selection/rfid_recipe_selection.ui
Normal file
95
src/ui/rfid_recipe_selection/rfid_recipe_selection.ui
Normal file
@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Test_Connector</class>
|
||||
<widget class="QWidget" name="Test_Connector">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1445</width>
|
||||
<height>793</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Test Connector</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="2" column="0" alignment="Qt::AlignHCenter">
|
||||
<widget class="QLabel" name="state_l">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" alignment="Qt::AlignHCenter">
|
||||
<widget class="QPlainTextEdit" name="barcode_input_l">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>600</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>600</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="plainText">
|
||||
<string>123
|
||||
456
|
||||
abc</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" alignment="Qt::AlignHCenter">
|
||||
<widget class="QPushButton" name="recipe_selection_b">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TORNA ALLA TABELLA RICETTE</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Loading…
Reference in New Issue
Block a user