Compare commits
6 Commits
949c6412d9
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 47b86bef95 | |||
| 3f6bf53a96 | |||
| 72965f4308 | |||
| e9a4a6089f | |||
| cc2e801ec6 | |||
| 3c726a8937 |
+21
-21
@@ -1,21 +1,21 @@
|
|||||||
# Eclipse user settings directory
|
# Eclipse user settings directory
|
||||||
.project
|
.project
|
||||||
.pydevproject
|
.pydevproject
|
||||||
.settings
|
.settings
|
||||||
|
|
||||||
# VS Codium user settings directory
|
# VS Codium user settings directory
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
MkpWIFI/__pycache__/
|
MkpWIFI/__pycache__/
|
||||||
MkpWIFI/build/
|
MkpWIFI/build/
|
||||||
MkpWIFI/dist/
|
MkpWIFI/dist/
|
||||||
MkpWIFI/main.spec
|
MkpWIFI/main.spec
|
||||||
MkpWIFI/*.dll
|
MkpWIFI/*.dll
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
log
|
log
|
||||||
__pycache__
|
__pycache__
|
||||||
build
|
build
|
||||||
dist
|
dist
|
||||||
main.spec
|
main.spec
|
||||||
|
|||||||
+65
-24
@@ -4,22 +4,24 @@ Created on 8 apr 2019
|
|||||||
@author: Emanuele Trabattoni
|
@author: Emanuele Trabattoni
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys
|
import sys, logging, os
|
||||||
import datetime
|
import datetime
|
||||||
import PyQt5.QtWidgets
|
import PyQt5.QtWidgets
|
||||||
from MKPrint_GUI import Ui_MainWindow
|
from MKPrint_GUI import Ui_MainWindow
|
||||||
from printer import MarkoPrinter
|
from printer import MarkoPrinter
|
||||||
|
import protocol
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(PyQt5.QtWidgets.QMainWindow):
|
class MainWindow(PyQt5.QtWidgets.QMainWindow):
|
||||||
def __init__(self, configFilePath):
|
def __init__(self, configFilePath, LOGGER):
|
||||||
try:
|
try:
|
||||||
self.printer = MarkoPrinter(configFilePath)
|
self.printer = MarkoPrinter(configFilePath, LOGGER)
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
print("Configuration file error: {}".format(e))
|
print("Configuration file error: {}".format(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
PyQt5.QtWidgets.QMainWindow.__init__(self)
|
PyQt5.QtWidgets.QMainWindow.__init__(self)
|
||||||
|
self.log = LOGGER
|
||||||
self.ui = Ui_MainWindow()
|
self.ui = Ui_MainWindow()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
self.setFixedSize(self.maximumSize())
|
self.setFixedSize(self.maximumSize())
|
||||||
@@ -31,27 +33,18 @@ class MainWindow(PyQt5.QtWidgets.QMainWindow):
|
|||||||
self.ui.rad_dataOn.setChecked(True)
|
self.ui.rad_dataOn.setChecked(True)
|
||||||
self.ui.prg_inkLevel.setTextVisible(True)
|
self.ui.prg_inkLevel.setTextVisible(True)
|
||||||
|
|
||||||
def updateStatusView(self):
|
|
||||||
connessa = self.printer.connected
|
|
||||||
self.ui.btn_upload.setEnabled(connessa)
|
|
||||||
if connessa:
|
|
||||||
self.ui.prg_inkLevel.setValue(self.printer.headStatus["iuse"])
|
|
||||||
self.ui.lcd_printCount.display(
|
|
||||||
str(self.printer.headStatus["labelCnt"]))
|
|
||||||
else:
|
|
||||||
self.ui.prg_inkLevel.setValue(0)
|
|
||||||
self.ui.lcd_printCount.display('0')
|
|
||||||
|
|
||||||
def toggla_connessione(self):
|
def toggla_connessione(self):
|
||||||
connessa = self.printer.connected
|
connessa = self.printer.connected
|
||||||
if connessa:
|
if connessa:
|
||||||
connessa = self.printer.disconnetti()
|
connessa = self.printer.disconnetti()
|
||||||
else:
|
else:
|
||||||
connessa = self.printer.connetti()
|
connessa = self.printer.connetti()
|
||||||
|
|
||||||
if connessa:
|
if connessa:
|
||||||
self.ui.btn_connect.setText("DISCONNETTI")
|
self.ui.btn_connect.setText("DISCONNETTI")
|
||||||
self.ui.lbl_stat.setText("Connesso")
|
self.ui.lbl_stat.setText("Connesso")
|
||||||
self.timer.start(self.printer.settings["keepalive"])
|
self.printer.sendCommand(protocol.deleteMemory())
|
||||||
|
self.timer.start(5000)
|
||||||
self.timer.timeout.connect(self.keepalive)
|
self.timer.timeout.connect(self.keepalive)
|
||||||
else:
|
else:
|
||||||
self.timer.stop()
|
self.timer.stop()
|
||||||
@@ -59,11 +52,23 @@ class MainWindow(PyQt5.QtWidgets.QMainWindow):
|
|||||||
self.ui.btn_connect.setText("CONNETTI")
|
self.ui.btn_connect.setText("CONNETTI")
|
||||||
self.updateStatusView()
|
self.updateStatusView()
|
||||||
|
|
||||||
|
def updateStatusView(self):
|
||||||
|
connessa = self.printer.connected
|
||||||
|
self.ui.btn_upload.setEnabled(connessa)
|
||||||
|
if connessa:
|
||||||
|
self.ui.lbl_stat.setText("Ready")
|
||||||
|
self.ui.prg_inkLevel.setValue(self.printer.headStatus["iuse"])
|
||||||
|
self.ui.lcd_printCount.display(str(self.printer.headStatus["labelCnt"]))
|
||||||
|
else:
|
||||||
|
self.ui.prg_inkLevel.setValue(0)
|
||||||
|
self.ui.lcd_printCount.display('0')
|
||||||
|
|
||||||
def keepalive(self):
|
def keepalive(self):
|
||||||
# TODO: usare il primo argomento di keepalive (stato connessione) per aggiornare la ui
|
# TODO: usare il primo argomento di keepalive (stato connessione) per aggiornare la ui
|
||||||
_, statusUpdated = self.printer.keepalive()
|
_, statusUpdated = self.printer.keepalive()
|
||||||
if statusUpdated:
|
if statusUpdated:
|
||||||
self.updateStatusView()
|
self.updateStatusView()
|
||||||
|
pass
|
||||||
|
|
||||||
def upload(self):
|
def upload(self):
|
||||||
if self.ui.rad_dataOn.isChecked():
|
if self.ui.rad_dataOn.isChecked():
|
||||||
@@ -71,21 +76,57 @@ class MainWindow(PyQt5.QtWidgets.QMainWindow):
|
|||||||
date = date.strftime(self.printer.data["dateformat"])
|
date = date.strftime(self.printer.data["dateformat"])
|
||||||
else:
|
else:
|
||||||
date = ""
|
date = ""
|
||||||
descr = str(self.ui.txt_descr.toPlainText()).capitalize()
|
descr = str(self.ui.txt_descr.toPlainText()).capitalize().replace('\n','\t').replace('\r','')
|
||||||
datastr = str(self.ui.txt_model.text()).upper() + "\r" + \
|
self.log.debug("SENDING: {}".format(descr))
|
||||||
date + descr + "\r"
|
self.printer.sendCommand(protocol.callPrintImage(imageName='TM1.00I',
|
||||||
response, statusUpdated = self.printer.upload(descr, datastr)
|
printMode='11',
|
||||||
if statusUpdated:
|
fieldContent = '{0}\r{1}'.format(self.ui.txt_model.text().upper(),\
|
||||||
self.updateStatusView()
|
date + descr)))
|
||||||
self.ui.lbl_stat.setText(response)
|
r=self.printer.readResponse('callPrintImage')
|
||||||
|
if protocol.checkResponse('callPrintImage', r):
|
||||||
|
self.log.info("Caricamento Riuscito")
|
||||||
|
self.ui.lbl_stat.setText(self.subChars(r))
|
||||||
|
else:
|
||||||
|
self.log.error("Caricamento Fallito")
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def subChars(self, s):
|
||||||
|
subDict = {'\x02': "#STX ",
|
||||||
|
'\x03': "#ETX ",
|
||||||
|
'\x1B': "#ESC ",
|
||||||
|
'\r': "#CR ",
|
||||||
|
'\f': "#LF ",
|
||||||
|
'\t': "#TAB ",
|
||||||
|
'\x06': "#ACK ",
|
||||||
|
'\x15': "#NACK "
|
||||||
|
}
|
||||||
|
out = ""
|
||||||
|
for c in s:
|
||||||
|
if c in subDict.keys():
|
||||||
|
out += subDict[c]
|
||||||
|
else:
|
||||||
|
out += c
|
||||||
|
return out
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = PyQt5.QtWidgets.QApplication(sys.argv)
|
app = PyQt5.QtWidgets.QApplication(sys.argv)
|
||||||
configFilePath = "MkpWIFI/conf.json"
|
configFilePath = "conf.json"
|
||||||
window = MainWindow(configFilePath)
|
print(os.getcwd())
|
||||||
|
|
||||||
|
# Setup Logger
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
LOGGER.setLevel(logging.DEBUG)
|
||||||
|
LOGGER.propagate = False
|
||||||
|
FORMATTER = logging.Formatter(("%(asctime)s|%(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s"),\
|
||||||
|
("%m-%d %H:%M:%S"))
|
||||||
|
# Console Logging
|
||||||
|
cl= logging.StreamHandler(sys.stdout)
|
||||||
|
cl.setLevel(logging.DEBUG)
|
||||||
|
cl.setFormatter(FORMATTER)
|
||||||
|
LOGGER.addHandler(cl)
|
||||||
|
|
||||||
|
window = MainWindow(configFilePath, LOGGER)
|
||||||
window.show()
|
window.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|||||||
+5
-3
@@ -39,7 +39,10 @@ def main():
|
|||||||
LOGGER.debug("Timeout stampa")
|
LOGGER.debug("Timeout stampa")
|
||||||
lastAck = False
|
lastAck = False
|
||||||
try:
|
try:
|
||||||
connessa = printer.keepalive()
|
connessa, statusUpdated = printer.keepalive()
|
||||||
|
if statusUpdated and printer.headStatus['txt'] == ">> No Label <<":
|
||||||
|
LOGGER.warning("Immagine di stampa non caricata, invio..")
|
||||||
|
lastAck = True
|
||||||
except RuntimeError as r:
|
except RuntimeError as r:
|
||||||
LOGGER.error("Stampante Disconnessa")
|
LOGGER.error("Stampante Disconnessa")
|
||||||
connessa = False
|
connessa = False
|
||||||
@@ -73,7 +76,7 @@ def subChars(s):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Setup Logger
|
# Setup Logger
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
LOGGER.setLevel(logging.DEBUG)
|
LOGGER.setLevel(logging.INFO)
|
||||||
LOGGER.propagate = False
|
LOGGER.propagate = False
|
||||||
FORMATTER = logging.Formatter(("%(asctime)s|%(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s"),
|
FORMATTER = logging.Formatter(("%(asctime)s|%(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s"),
|
||||||
("%m-%d %H:%M:%S"))
|
("%m-%d %H:%M:%S"))
|
||||||
@@ -89,6 +92,5 @@ if __name__ == '__main__':
|
|||||||
LOGGER.addHandler(cl)
|
LOGGER.addHandler(cl)
|
||||||
|
|
||||||
LOGGER.warning("MarcaturaDime Started!")
|
LOGGER.warning("MarcaturaDime Started!")
|
||||||
|
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
pass
|
pass
|
||||||
@@ -150,6 +150,8 @@ class MarkoPrinter:
|
|||||||
c = self.printSock.recv(1)
|
c = self.printSock.recv(1)
|
||||||
# disattivo lettura bloccante
|
# disattivo lettura bloccante
|
||||||
self.printSock.settimeout(0.5)
|
self.printSock.settimeout(0.5)
|
||||||
|
# VERIFICARE SE VA BENE
|
||||||
|
self.reading = False
|
||||||
return str(buf, 'ascii')
|
return str(buf, 'ascii')
|
||||||
except socket.timeout as t:
|
except socket.timeout as t:
|
||||||
self.reading = False
|
self.reading = False
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
X;#=51;g=1;h=MODELLO:P1-0-000000000;A9mmB;~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~
|
||||||
|
X;#=52;g=1;h=Descrizione:P1-0-014800000;A4mm;~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~
|
||||||
|
P1r0-035430000;;
|
||||||
|
P1-0-000000000:h=24
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
BI0A0300000000000;A2,5mmB;0123456789
|
||||||
|
X;#=50;g=1;h=___CLIENTONE____:P1-0-009400000;A3mmB;~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~
|
||||||
|
X;#=51;g=1;h=MODELLO FUST:P1-0-009400120;A2,5mmB;~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~
|
||||||
|
X;#=52;g=1;h=TIPO FUSTO:P1-0-009400200;A2,5mmB;~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~
|
||||||
|
P1r0-018900000;;
|
||||||
|
P1-0-000000000:h=24
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
EW----;TM3.00I
|
||||||
Binary file not shown.
Reference in New Issue
Block a user