From 4c361f2cc372fb7b8e49a29a613f83c29fb09024 Mon Sep 17 00:00:00 2001 From: Emanuele Date: Fri, 27 Sep 2019 17:34:47 +0200 Subject: [PATCH] Modifiche ai comandi, mainDime e cose --- MkpWIFI/commands.py | 3 ++- MkpWIFI/mainDime.py | 20 +++++++++++++++++--- MkpWIFI/printer.py | 18 +++++++++++++++++- MkpWIFI/test.py | 7 +++++-- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/MkpWIFI/commands.py b/MkpWIFI/commands.py index 8896a8b..99695dd 100644 --- a/MkpWIFI/commands.py +++ b/MkpWIFI/commands.py @@ -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, diff --git a/MkpWIFI/mainDime.py b/MkpWIFI/mainDime.py index f1ffa16..95b1d31 100644 --- a/MkpWIFI/mainDime.py +++ b/MkpWIFI/mainDime.py @@ -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__': diff --git a/MkpWIFI/printer.py b/MkpWIFI/printer.py index 341aeb5..cbb62e8 100644 --- a/MkpWIFI/printer.py +++ b/MkpWIFI/printer.py @@ -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 diff --git a/MkpWIFI/test.py b/MkpWIFI/test.py index 54265c4..dfcf517 100644 --- a/MkpWIFI/test.py +++ b/MkpWIFI/test.py @@ -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'