Aggiornamneto del main (non del tutto funzionante)
parent
7045dee32e
commit
82d18aee26
564231
MkpWIFI/log/dimelog.log
564231
MkpWIFI/log/dimelog.log
File diff suppressed because it is too large
Load Diff
|
|
@ -6,25 +6,27 @@ Created on 27 set 2019
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import printer as p
|
import printer as p
|
||||||
import commands
|
|
||||||
import logging
|
import logging
|
||||||
import test
|
import protocol
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
isRunning = True
|
isRunning = True
|
||||||
while isRunning:
|
while isRunning:
|
||||||
connessa=True
|
printer = p.MarkoPrinter('./conf.json', LOGGER)
|
||||||
#printer = p.MarkoPrinter('./conf.json', LOGGER)
|
connessa = printer.connetti()
|
||||||
#connessa = printer.connetti()
|
|
||||||
while connessa:
|
while connessa:
|
||||||
lastTimestamp = int(time.time()*100)
|
lastTimestamp = int(time.time()*100)
|
||||||
commandString = test.cmdString('callPrintImage', {'imageName': 'TM2.00I',
|
commandString = protocol.callPrintImage(imageName='TM2.00I',
|
||||||
'printMode': '10',
|
printMode='10',
|
||||||
'fieldContent': '{0}\r{0}\r'.format(lastTimestamp)
|
fieldContent='{0}\r{0}'.format(lastTimestamp))
|
||||||
}
|
try:
|
||||||
)
|
printer.sendCommand(commandString)
|
||||||
LOGGER.debug(commandString)
|
LOGGER.debug('SENT: {}'.format(commandString))
|
||||||
#printer.sendCommand(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
|
pass
|
||||||
pass
|
pass
|
||||||
|
|
@ -38,12 +40,12 @@ if __name__ == '__main__':
|
||||||
("%m-%d %H:%M:%S"))
|
("%m-%d %H:%M:%S"))
|
||||||
# File Logging
|
# File Logging
|
||||||
fh = logging.FileHandler(("./log/dimelog.log"))
|
fh = logging.FileHandler(("./log/dimelog.log"))
|
||||||
fh.setLevel(logging.WARNING)
|
fh.setLevel(logging.DEBUG)
|
||||||
fh.setFormatter(FORMATTER)
|
fh.setFormatter(FORMATTER)
|
||||||
LOGGER.addHandler(fh)
|
LOGGER.addHandler(fh)
|
||||||
# Console Logging
|
# Console Logging
|
||||||
cl= logging.StreamHandler(sys.stdout)
|
cl= logging.StreamHandler(sys.stdout)
|
||||||
cl.setLevel(logging.INFO)
|
cl.setLevel(logging.DEBUG)
|
||||||
cl.setFormatter(FORMATTER)
|
cl.setFormatter(FORMATTER)
|
||||||
LOGGER.addHandler(cl)
|
LOGGER.addHandler(cl)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import test
|
import protocol
|
||||||
|
import commands as cmd
|
||||||
|
|
||||||
class MarkoPrinter:
|
class MarkoPrinter:
|
||||||
def __init__(self, configFilePath, LOGGER):
|
def __init__(self, configFilePath, LOGGER):
|
||||||
|
|
@ -11,6 +12,7 @@ class MarkoPrinter:
|
||||||
self.headStatus = dict()
|
self.headStatus = dict()
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.sending = False
|
self.sending = False
|
||||||
|
self.reading = False
|
||||||
with open(configFilePath, "r") as setFile:
|
with open(configFilePath, "r") as setFile:
|
||||||
self.settings = json.load(setFile)
|
self.settings = json.load(setFile)
|
||||||
self.data = self.settings["printcmd"]
|
self.data = self.settings["printcmd"]
|
||||||
|
|
@ -120,7 +122,7 @@ class MarkoPrinter:
|
||||||
if self.connected:
|
if self.connected:
|
||||||
try:
|
try:
|
||||||
self.printSock.settimeout(1.0)
|
self.printSock.settimeout(1.0)
|
||||||
self.printSock.send(bytearray(test.cmdString(c, "ascii")))
|
self.printSock.send(bytearray(c,'ascii'))
|
||||||
self.printSock.settimeout(0.5)
|
self.printSock.settimeout(0.5)
|
||||||
return True
|
return True
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
|
|
@ -129,6 +131,29 @@ class MarkoPrinter:
|
||||||
self.sending = False
|
self.sending = False
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def readResponse(self, c):
|
||||||
|
self.reading = True
|
||||||
|
buf = bytearray()
|
||||||
|
respTerm = cmd.DEFprefix['end'] if cmd.MKPcommands[c]['defPrefix'] else cmd.MKPcommands[c]['end']
|
||||||
|
if self.connected:
|
||||||
|
try:
|
||||||
|
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)
|
||||||
|
self.printSock.settimeout(0.5)
|
||||||
|
self.printSock.setblocking(False)
|
||||||
|
return str(buf, 'ascii')
|
||||||
|
except socket.error as e:
|
||||||
|
self.LOGGER.error('Socket Error: {}'.format(e))
|
||||||
|
return False
|
||||||
|
self.reading = False
|
||||||
|
pass
|
||||||
|
|
||||||
def keepalive(self):
|
def keepalive(self):
|
||||||
statusUpdated = False
|
statusUpdated = False
|
||||||
if not self.sending:
|
if not self.sending:
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ def _checkError(cmdName, response):
|
||||||
return error_codes.groups()
|
return error_codes.groups()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _checkResponse(cmdName, response):
|
def checkResponse(cmdName, response):
|
||||||
sucKey = 'success'
|
sucKey = 'success'
|
||||||
cmdDict = cmd.MKPcommands[cmdName]
|
cmdDict = cmd.MKPcommands[cmdName]
|
||||||
if sucKey in cmdDict and cmdDict[sucKey] is not None:
|
if sucKey in cmdDict and cmdDict[sucKey] is not None:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue