aggiunti gli errori

master
Emanuele Trabattoni 2020-03-19 17:22:49 +01:00
parent 93e806b359
commit c8358537d6
2 changed files with 28 additions and 9 deletions

View File

@ -6,6 +6,23 @@ Created on 19 mar 2020
TSC_COMMANDS = {'DOWNLOAD': "DOWNLOAD {location}{name}{size}{content}",
'REMOVE': "KILL {location}{name}",
'LIST': "~!F",
'RUN': "RUN {name}"}
'RUN': "RUN {name}",
'STATUS': '!?'}
TSC_STATUS = {0x00:"Normal",
0x01:"Head opened",
0x02:"Paper Jam",
0x03:"Paper Jam and head opened",
0x04:"Out of paper",
0x05:"Out of paper and head opened",
0x08:"Out of ribbon",
0x09:"Out of ribbon and head opened",
0x0A:"Out of ribbon and paper jam",
0x0B:"Out of ribbon, paper jam and head opened",
0x0C:"Out of ribbon and out of paper",
0x0D:"Out of ribbon, out of paper and head opened",
0x10:"Pause",
0x20:"Printing",
0x80:"Other error"
}
LINE_SEP = '\r\n'

View File

@ -4,8 +4,8 @@ Created on 19 mar 2020
@author: Emanuele Trabattoni
'''
import queue, sys, time, socket, logging
from driver.tsc_commands import TSC_COMMANDS, LINE_SEP
import queue, time, socket, logging
from driver.tsc_commands import TSC_COMMANDS, TSC_STATUS, LINE_SEP
from driver.notifier import URL_ERR, URL_EVENT, URL_RESPONSE
SOCK_TIMEOUT = 2
@ -26,6 +26,7 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s
def list_files():
nonlocal prt
prt.sendall(TSC_COMMANDS['LIST']+LINE_SEP)
time.sleep(0.1)
retval = read_until(0x1A).split(0x0D)
q_out.put({'url':URL_RESPONSE,
'msg': retval})
@ -66,17 +67,17 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s
def get_status():
nonlocal prt
return True
prt.sendall(0x1B+TSC_COMMANDS['STATUS'])
time.sleep(0.1)
return TSC_STATUS[prt.recv(1)]
while True: # connetti mantieni vivo il socket
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as prt:
prt.create_connection(address=(ip, port), timeout=SOCK_TIMEOUT)
while True:
itm = q_in.get(block=True)
prt_cmd = ""
cmd = itm['name']
par = itm['parameters']
if cmd == 'DOWNLOAD':
@ -89,11 +90,12 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s
move_file(**par)
pass
elif cmd == 'LIST':
resp = get_status()
q_out.put({'url='})
get_status()
pass
elif cmd == 'RUN':
pass
elif cmd == 'STATUS':
pass
else:
logger.error("Comando stampante non riconosciuto")
except socket.timeout as st: