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}", TSC_COMMANDS = {'DOWNLOAD': "DOWNLOAD {location}{name}{size}{content}",
'REMOVE': "KILL {location}{name}", 'REMOVE': "KILL {location}{name}",
'LIST': "~!F", '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' LINE_SEP = '\r\n'

View File

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