Aggiornamneto del main (non del tutto funzionante)

master
Emanuele Trabattoni 2019-09-28 14:46:57 +02:00
parent 7045dee32e
commit 82d18aee26
5 changed files with 564526 additions and 268 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,25 +6,27 @@ Created on 27 set 2019
import time
import sys
import printer as p
import commands
import logging
import test
import protocol
def main():
isRunning = True
while isRunning:
connessa=True
#printer = p.MarkoPrinter('./conf.json', LOGGER)
#connessa = printer.connetti()
printer = p.MarkoPrinter('./conf.json', LOGGER)
connessa = printer.connetti()
while connessa:
lastTimestamp = int(time.time()*100)
commandString = test.cmdString('callPrintImage', {'imageName': 'TM2.00I',
'printMode': '10',
'fieldContent': '{0}\r{0}\r'.format(lastTimestamp)
}
)
LOGGER.debug(commandString)
#printer.sendCommand(commandString)
commandString = protocol.callPrintImage(imageName='TM2.00I',
printMode='10',
fieldContent='{0}\r{0}'.format(lastTimestamp))
try:
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
@ -38,12 +40,12 @@ if __name__ == '__main__':
("%m-%d %H:%M:%S"))
# File Logging
fh = logging.FileHandler(("./log/dimelog.log"))
fh.setLevel(logging.WARNING)
fh.setLevel(logging.DEBUG)
fh.setFormatter(FORMATTER)
LOGGER.addHandler(fh)
# Console Logging
cl= logging.StreamHandler(sys.stdout)
cl.setLevel(logging.INFO)
cl.setLevel(logging.DEBUG)
cl.setFormatter(FORMATTER)
LOGGER.addHandler(cl)

View File

@ -1,7 +1,8 @@
import socket
import json
import time
import test
import protocol
import commands as cmd
class MarkoPrinter:
def __init__(self, configFilePath, LOGGER):
@ -11,6 +12,7 @@ class MarkoPrinter:
self.headStatus = dict()
self.connected = False
self.sending = False
self.reading = False
with open(configFilePath, "r") as setFile:
self.settings = json.load(setFile)
self.data = self.settings["printcmd"]
@ -120,7 +122,7 @@ class MarkoPrinter:
if self.connected:
try:
self.printSock.settimeout(1.0)
self.printSock.send(bytearray(test.cmdString(c, "ascii")))
self.printSock.send(bytearray(c,'ascii'))
self.printSock.settimeout(0.5)
return True
except socket.error as e:
@ -129,6 +131,29 @@ class MarkoPrinter:
self.sending = False
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):
statusUpdated = False
if not self.sending:

View File

@ -47,7 +47,7 @@ def _checkError(cmdName, response):
return error_codes.groups()
return None
def _checkResponse(cmdName, response):
def checkResponse(cmdName, response):
sucKey = 'success'
cmdDict = cmd.MKPcommands[cmdName]
if sucKey in cmdDict and cmdDict[sucKey] is not None: