Modifiche ai comandi, mainDime e cose

master
Emanuele Trabattoni 2019-09-27 17:34:47 +02:00
parent af78d34797
commit 4c361f2cc3
4 changed files with 41 additions and 7 deletions

View File

@ -47,7 +47,8 @@ MKPcommands = {
'command': 'TZ',
'success': '\x06\x02([0-9])OK\x03',
'error': '([0-9])E([0-9])',
'args': ['imageName', 'printMode']
'args': ['imageName', 'printMode', 'fieldContent']
},
'sendImage': {
'defPrefix': True,

View File

@ -8,11 +8,25 @@ import sys
import printer as p
import commands
import logging
import test
def main():
printer = p.MarkoPrinter('./conf.json')
printer.connetti()
isRunning = True
while isRunning:
connessa=True
#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': '\r{0}\r{0}\r'.format(lastTimestamp)
}
)
LOGGER.debug(commandString)
#printer.sendCommand(commandString)
pass
pass
pass
if __name__ == '__main__':

View File

@ -1,9 +1,11 @@
import socket
import json
import time
import test
class MarkoPrinter:
def __init__(self, configFilePath):
def __init__(self, configFilePath, LOGGER):
self.LOGGER = LOGGER
self.inkStatCounter = 0
self.printSock = None
self.headStatus = dict()
@ -112,6 +114,20 @@ class MarkoPrinter:
self.printSock.recv(5)
self.sending = False
return response, statusUpdated
def sendCommand(self, c):
self.sending = True
if self.connected:
try:
self.printSock.settimeout(1.0)
self.printSock.send(bytearray(test.cmdString(c, "ascii")))
self.printSock.settimeout(0.5)
return True
except socket.error as e:
self.LOGGER.error('Socket Error: {}'.format(e))
return False
self.sending = False
pass
def keepalive(self):
statusUpdated = False

View File

@ -9,9 +9,12 @@ Created on Fri Sep 27 14:35:31 2019
import commands as cmd
import re
def cmdString(cmdName):
def cmdString(cmdName, cmdArgs=None):
cmdDict = cmd.MKPcommands[cmdName]
return str(cmd.DEFprefix['begin'] if cmdDict['defPrefix'] else cmdDict['begin']) + str(cmdDict['command']) + str(cmd.DEFprefix['end'] if cmdDict['defPrefix'] else cmdDict['end'])
return str(cmd.DEFprefix['begin'] if cmdDict['defPrefix'] else cmdDict['begin']) \
+ str(cmdDict['command']) \
+ str(';'.join([cmdArgs[k] for k in cmdDict['args']]) if cmdArgs is not None else '') \
+ str(cmd.DEFprefix['end'] if cmdDict['defPrefix'] else cmdDict['end'])
def checkResponse(cmdName,response):
sucKey = 'success'