Compare commits
No commits in common. "d87eb7a22bccd08b1ffc2044d92c17e67d77f8fa" and "82d18aee26d2f8275f99237125a56c41d8b4b480" have entirely different histories.
d87eb7a22b
...
82d18aee26
|
|
@ -45,8 +45,8 @@ MKPcommands = {
|
|||
'begin': '\x02', # STX
|
||||
'end': '\x03', # ETX
|
||||
'command': 'TZ{imageName};{printMode};{queueNo};{delay}\r{fieldContent}\r{counterStart}',
|
||||
'success': '([0-9]OK)',
|
||||
'error': '([0-9]E[0-9])',
|
||||
'success': '\x06\x02([0-9])OK\x03',
|
||||
'error': '([0-9])E([0-9])',
|
||||
'args': ['imageName', 'printMode', 'fieldContent'],
|
||||
'optArgs': ['queueNo', 'delay', 'counterStart']
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
{
|
||||
"ip": "192.168.40.30",
|
||||
"port": 8899,
|
||||
"name": "MKPsouplesse",
|
||||
"autoconnect": true,
|
||||
"keepalive": 5.0,
|
||||
"timeout": 0.5,
|
||||
"inkstat": 2,
|
||||
"printcmd": {
|
||||
"filename": "TM1.00I",
|
||||
"dateformat": "%d%m%y-",
|
||||
"handshake": "*",
|
||||
"printmode": "11",
|
||||
"headstatus": [
|
||||
"ink",
|
||||
"htmr",
|
||||
"iuse",
|
||||
"xclk",
|
||||
"bat",
|
||||
"txt",
|
||||
"pause",
|
||||
"headOk",
|
||||
"headTyp",
|
||||
"labelCnt",
|
||||
"ztv",
|
||||
"cp",
|
||||
"lx",
|
||||
"exInk",
|
||||
"scStat",
|
||||
"inkStat"
|
||||
]
|
||||
}
|
||||
}
|
||||
{
|
||||
"ip": "192.168.40.30",
|
||||
"port": 8899,
|
||||
"name": "MKPsouplesse",
|
||||
"autoconnect": true,
|
||||
"keepalive": 5000,
|
||||
"timeout": 0.5,
|
||||
"inkstat": 2,
|
||||
"printcmd": {
|
||||
"filename": "TM1.00I",
|
||||
"dateformat": "%d%m%y-",
|
||||
"handshake": "*",
|
||||
"printmode": "11",
|
||||
"headstatus": [
|
||||
"ink",
|
||||
"htmr",
|
||||
"iuse",
|
||||
"xclk",
|
||||
"bat",
|
||||
"txt",
|
||||
"pause",
|
||||
"headOk",
|
||||
"headTyp",
|
||||
"labelCnt",
|
||||
"ztv",
|
||||
"cp",
|
||||
"lx",
|
||||
"exInk",
|
||||
"scStat",
|
||||
"inkStat"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,29 +6,6 @@ Created on Sat Sep 28 11:41:21 2019
|
|||
@author: Guido Longoni - guidolongoni@gmail.com
|
||||
"""
|
||||
|
||||
#import protocol as p
|
||||
import protocol as p
|
||||
|
||||
#testala=p.callPrintImage(imageName='Pippus',printMode='10',fieldContent='qualcosa\rqualcosaltro\rciao')
|
||||
|
||||
def subChars(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
|
||||
|
||||
|
||||
t="\x06\x02OK\x03\r\n\t"
|
||||
|
||||
print(subChars(t))
|
||||
testala=p.callPrintImage(imageName='Pippus',printMode='10',fieldContent='qualcosa\rqualcosaltro\rciao')
|
||||
93394
MkpWIFI/log/dimelog.log
93394
MkpWIFI/log/dimelog.log
File diff suppressed because it is too large
Load Diff
|
|
@ -7,63 +7,30 @@ import time
|
|||
import sys
|
||||
import printer as p
|
||||
import logging
|
||||
import socket
|
||||
import protocol
|
||||
|
||||
def main():
|
||||
isRunning = True
|
||||
lastAck = True
|
||||
while isRunning:
|
||||
printer = p.MarkoPrinter('./conf.json', LOGGER)
|
||||
connessa = printer.connetti()
|
||||
printer.sendCommand(protocol.deleteMemory())
|
||||
while connessa:
|
||||
lastTimestamp = int(time.time()*100)
|
||||
commandString = protocol.callPrintImage(imageName='TM2.00I',
|
||||
printMode='10',
|
||||
fieldContent='{0}\r{0}'.format(lastTimestamp))
|
||||
try:
|
||||
if lastAck == True:
|
||||
lastTimestamp = int(time.time()*100)
|
||||
commandString = protocol.callPrintImage(imageName='TM2.00I',
|
||||
printMode='10',
|
||||
fieldContent='{0}\r{0}'.format(lastTimestamp))
|
||||
printer.sendCommand(commandString)
|
||||
LOGGER.debug('SENT: {}'.format(subChars(commandString)))
|
||||
lastAck = False
|
||||
else:
|
||||
r=printer.readResponse('callPrintImage')
|
||||
LOGGER.debug('RECEIVED: {}'.format(subChars(r)))
|
||||
if protocol.checkResponse('callPrintImage',r):
|
||||
LOGGER.info("Stampa Riuscita: {}".format(lastTimestamp))
|
||||
else:
|
||||
LOGGER.error("Stampa Fallita: {}".format(lastTimestamp))
|
||||
lastAck = True
|
||||
except socket.timeout as t:
|
||||
LOGGER.debug("Timeout stampa")
|
||||
lastAck = False
|
||||
printer.keepalive()
|
||||
pass
|
||||
printer.sendCommand(commandString)
|
||||
LOGGER.debug('SENT: {}'.format(commandString))
|
||||
r=printer.readResponse('callPrintImage')
|
||||
LOGGER.debug('RECEIVED: {}'.format(r))
|
||||
protocol.checkResponse('callPrintImage',r)
|
||||
except Exception as e:
|
||||
LOGGER.error(str(e))
|
||||
pass
|
||||
pass
|
||||
pass
|
||||
|
||||
def subChars(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__':
|
||||
# Setup Logger
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import socket
|
|||
import json
|
||||
import time
|
||||
import protocol
|
||||
import threading
|
||||
import commands as cmd
|
||||
|
||||
class MarkoPrinter:
|
||||
|
|
@ -34,13 +33,11 @@ class MarkoPrinter:
|
|||
self.connected = True
|
||||
self.printSock.settimeout(0.5)
|
||||
self.checkStatus()
|
||||
self.LOGGER.debug("Connessione Riuscita")
|
||||
except socket.error as e:
|
||||
self.printSock = None
|
||||
self.connected = False
|
||||
self.LOGGER.debug("Connessione Fallita: {}".format(e))
|
||||
self.log("Connessione Fallita: {}".format(e))
|
||||
else:
|
||||
self.keepaliveTimer.cancel()
|
||||
self.printSock.close()
|
||||
self.printSock = None
|
||||
self.connetti()
|
||||
|
|
@ -64,7 +61,7 @@ class MarkoPrinter:
|
|||
while c != b"\r":
|
||||
inData += c
|
||||
if len(inData) > 200:
|
||||
self.LOGGER.error("Status Message Length Error")
|
||||
self.log("Status Message Length Error")
|
||||
raise IOError
|
||||
c = self.printSock.recv(1)
|
||||
inData = str(inData, "ascii")
|
||||
|
|
@ -74,10 +71,10 @@ class MarkoPrinter:
|
|||
self.headStatus[key] = int(inData[index])
|
||||
else:
|
||||
self.headStatus[key] = str(inData[index])
|
||||
self.LOGGER.info("Status: {}".format(self.headStatus))
|
||||
self.log("Status: {}".format(self.headStatus))
|
||||
statusUpdated = True
|
||||
except:
|
||||
self.LOGGER.error("Status retreive error!")
|
||||
self.log("Status retreive error!")
|
||||
return statusUpdated
|
||||
|
||||
def upload(self, descr, datastr):
|
||||
|
|
@ -127,12 +124,11 @@ class MarkoPrinter:
|
|||
self.printSock.settimeout(1.0)
|
||||
self.printSock.send(bytearray(c,'ascii'))
|
||||
self.printSock.settimeout(0.5)
|
||||
self.sending = False
|
||||
return True
|
||||
except socket.error as e:
|
||||
self.LOGGER.error('Socket Error: {}'.format(e))
|
||||
return False
|
||||
self.sending = False
|
||||
self.sending = False
|
||||
pass
|
||||
|
||||
def readResponse(self, c):
|
||||
|
|
@ -141,20 +137,17 @@ class MarkoPrinter:
|
|||
respTerm = cmd.DEFprefix['end'] if cmd.MKPcommands[c]['defPrefix'] else cmd.MKPcommands[c]['end']
|
||||
if self.connected:
|
||||
try:
|
||||
# lettura bloccante del socket in attesa di conferma
|
||||
self.printSock.settimeout(5)
|
||||
self.printSock.settimeout(1.0)
|
||||
self.printSock.setblocking(True)
|
||||
c = self.printSock.recv(1)
|
||||
while c != respTerm:
|
||||
buf += c
|
||||
if str(c, 'ascii') == respTerm:
|
||||
break
|
||||
c = self.printSock.recv(1)
|
||||
# disattivo lettura bloccante
|
||||
self.printSock.settimeout(0.5)
|
||||
self.printSock.setblocking(False)
|
||||
return str(buf, 'ascii')
|
||||
except socket.timeout as t:
|
||||
self.reading = False
|
||||
raise t
|
||||
except socket.error as e:
|
||||
self.LOGGER.error('Socket Error: {}'.format(e))
|
||||
return False
|
||||
|
|
@ -163,12 +156,12 @@ class MarkoPrinter:
|
|||
|
||||
def keepalive(self):
|
||||
statusUpdated = False
|
||||
self.LOGGER.debug("Keepalive")
|
||||
if not self.sending and not self.reading:
|
||||
if not self.sending:
|
||||
self.log("Keepalive")
|
||||
if self.connected:
|
||||
try:
|
||||
self.printSock.send(b"\x1B*\r")
|
||||
self.LOGGER.debug(str(self.printSock.recv(5)))
|
||||
self.log(str(self.printSock.recv(5)))
|
||||
if self.inkStatCounter <= self.settings["inkstat"]:
|
||||
self.inkStatCounter += 1
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ def _cmdString(cmdName, **cmdArgs):
|
|||
def _checkError(cmdName, response):
|
||||
errKey = 'error'
|
||||
cmdDict = cmd.MKPcommands[cmdName]
|
||||
if errKey in cmdDict and cmdDict[errKey] is None:
|
||||
if errKey in cmdDict and cmdDict[errKey] is not None:
|
||||
return None
|
||||
error_codes = re.search(cmdDict[errKey], response, re.I)
|
||||
error_codes = re.match(cmdDict[errKey], response, re.I)
|
||||
if error_codes:
|
||||
return error_codes.groups()
|
||||
return None
|
||||
|
|
@ -57,7 +57,7 @@ def checkResponse(cmdName, response):
|
|||
return None
|
||||
else:
|
||||
return error
|
||||
if re.search(cmdDict[sucKey], response, re.I):
|
||||
if re.match(cmdDict[sucKey], response, re.I):
|
||||
return True
|
||||
error = _checkError(cmdName, response)
|
||||
if error is None:
|
||||
|
|
|
|||
Loading…
Reference in New Issue