finito aggiungere comandi
parent
59c203f3a2
commit
14d019ce67
|
|
@ -8,10 +8,9 @@ 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, send_response
|
||||
import traceback
|
||||
from win32comext.mapi.mapiutil import prTable
|
||||
|
||||
SOCK_TIMEOUT = 2
|
||||
|
||||
ENC = 'ascii'
|
||||
|
||||
def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: str, port: int, logger: logging.getLogger):
|
||||
prt = None
|
||||
|
|
@ -31,7 +30,7 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s
|
|||
elif ftype == 'data':
|
||||
data = content.join(LINE_SEP)+LINE_SEP
|
||||
to_send = TSC_COMMANDS['DOWNLOAD'].format(name=f'"{name}"',size=','+len(data),content=data)
|
||||
prt.send_all(bytearray(to_send, encoding='utf-8'))
|
||||
prt.send_all(bytearray(to_send, encoding=ENC))
|
||||
pass
|
||||
|
||||
def delete_file(name=None):
|
||||
|
|
@ -40,57 +39,59 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s
|
|||
to_send = TSC_COMMANDS['REMOVE'].format(location='F,', name=f'"{name}"')
|
||||
else:
|
||||
to_send = TSC_COMMANDS['REMOVE'].format(name=f'"{name}"')
|
||||
prt.sendall(bytearray(to_send+LINE_SEP, encoding='utf-8'))
|
||||
prt.sendall(bytearray(to_send+LINE_SEP, encoding=ENC))
|
||||
pass
|
||||
|
||||
def move_file(name=None):
|
||||
#per default muove i file dalla RAM alla FLASH
|
||||
nonlocal prt
|
||||
to_send = TSC_COMMANDS['MOVE'].format(name=f'"{name}"')
|
||||
prt.sendall(bytearray(to_send+LINE_SEP, encoding='utf-8'))
|
||||
prt.sendall(bytearray(to_send+LINE_SEP, encoding=ENC))
|
||||
pass
|
||||
|
||||
def list_files():
|
||||
nonlocal prt
|
||||
prt.sendall(bytearray(TSC_COMMANDS['LIST']+LINE_SEP, encoding="ascii"))
|
||||
prt.sendall(bytearray(TSC_COMMANDS['LIST']+LINE_SEP, encoding="utf-8"))
|
||||
time.sleep(0.1)
|
||||
retval = read_until(b'\x1A').decode('utf-8').split('\r')
|
||||
retval = read_until(b'\x1A').decode(ENC).split('\r')
|
||||
logger.info(f"Risposta: {retval}")
|
||||
send_response(q_out, ip, "LIST",{"lista_file": retval})
|
||||
pass
|
||||
|
||||
def printer_info():
|
||||
nonlocal prt
|
||||
prt.sendall(bytearray(TSC_COMMANDS['PAUSE'], encoding=ENC))
|
||||
pass
|
||||
|
||||
def printer_usage():
|
||||
nonlocal prt
|
||||
prt.sendall(bytearray(TSC_COMMANDS['USE'], encoding=ENC))
|
||||
pass
|
||||
|
||||
def printer_pause():
|
||||
nonlocal prt
|
||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['PAUSE']))
|
||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['PAUSE'], encoding=ENC))
|
||||
pass
|
||||
|
||||
def printer_resume():
|
||||
nonlocal prt
|
||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['RESUME']))
|
||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['RESUME'], encoding=ENC))
|
||||
pass
|
||||
|
||||
def clear_memory():
|
||||
nonlocal prt
|
||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['CLEAR']))
|
||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['CLEAR'], encoding=ENC))
|
||||
pass
|
||||
|
||||
def run_batch(name=None):
|
||||
nonlocal prt
|
||||
to_send = TSC_COMMANDS['RUN'].format(name=f'"{name}"')
|
||||
prt.sendall(bytearray(to_send+LINE_SEP, encoding='utf-8'))
|
||||
prt.sendall(bytearray(to_send+LINE_SEP, encoding=ENC))
|
||||
pass
|
||||
|
||||
def get_status():
|
||||
nonlocal prt
|
||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['STATUS']))
|
||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['STATUS'], encoding=ENC))
|
||||
time.sleep(0.1)
|
||||
return TSC_STATUS[int(prt.recv(1))]
|
||||
|
||||
|
|
@ -116,16 +117,22 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s
|
|||
list_files()
|
||||
pass
|
||||
elif cmd == 'INFO':
|
||||
printer_info()
|
||||
pass
|
||||
elif cmd == 'USE':
|
||||
printer_usage()
|
||||
pass
|
||||
elif cmd == 'PAUSE':
|
||||
printer_pause()
|
||||
pass
|
||||
elif cmd == 'RESUME':
|
||||
printer_resume()
|
||||
pass
|
||||
elif cmd == 'CLEAR':
|
||||
clear_memory()
|
||||
pass
|
||||
elif cmd == 'RUN':
|
||||
run_batch(**par)
|
||||
pass
|
||||
elif cmd == 'STATUS':
|
||||
get_status()
|
||||
|
|
|
|||
Loading…
Reference in New Issue