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.tsc_commands import TSC_COMMANDS, TSC_STATUS, LINE_SEP
|
||||||
from driver.notifier import URL_ERR, URL_EVENT, URL_RESPONSE, send_response
|
from driver.notifier import URL_ERR, URL_EVENT, URL_RESPONSE, send_response
|
||||||
import traceback
|
import traceback
|
||||||
from win32comext.mapi.mapiutil import prTable
|
|
||||||
|
|
||||||
SOCK_TIMEOUT = 2
|
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):
|
def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: str, port: int, logger: logging.getLogger):
|
||||||
prt = None
|
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':
|
elif ftype == 'data':
|
||||||
data = content.join(LINE_SEP)+LINE_SEP
|
data = content.join(LINE_SEP)+LINE_SEP
|
||||||
to_send = TSC_COMMANDS['DOWNLOAD'].format(name=f'"{name}"',size=','+len(data),content=data)
|
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
|
pass
|
||||||
|
|
||||||
def delete_file(name=None):
|
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}"')
|
to_send = TSC_COMMANDS['REMOVE'].format(location='F,', name=f'"{name}"')
|
||||||
else:
|
else:
|
||||||
to_send = TSC_COMMANDS['REMOVE'].format(name=f'"{name}"')
|
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
|
pass
|
||||||
|
|
||||||
def move_file(name=None):
|
def move_file(name=None):
|
||||||
#per default muove i file dalla RAM alla FLASH
|
#per default muove i file dalla RAM alla FLASH
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
to_send = TSC_COMMANDS['MOVE'].format(name=f'"{name}"')
|
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
|
pass
|
||||||
|
|
||||||
def list_files():
|
def list_files():
|
||||||
nonlocal prt
|
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)
|
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}")
|
logger.info(f"Risposta: {retval}")
|
||||||
send_response(q_out, ip, "LIST",{"lista_file": retval})
|
send_response(q_out, ip, "LIST",{"lista_file": retval})
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def printer_info():
|
def printer_info():
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
|
prt.sendall(bytearray(TSC_COMMANDS['PAUSE'], encoding=ENC))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def printer_usage():
|
def printer_usage():
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
|
prt.sendall(bytearray(TSC_COMMANDS['USE'], encoding=ENC))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def printer_pause():
|
def printer_pause():
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['PAUSE']))
|
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['PAUSE'], encoding=ENC))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def printer_resume():
|
def printer_resume():
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['RESUME']))
|
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['RESUME'], encoding=ENC))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def clear_memory():
|
def clear_memory():
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['CLEAR']))
|
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['CLEAR'], encoding=ENC))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_batch(name=None):
|
def run_batch(name=None):
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
to_send = TSC_COMMANDS['RUN'].format(name=f'"{name}"')
|
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
|
pass
|
||||||
|
|
||||||
def get_status():
|
def get_status():
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['STATUS']))
|
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['STATUS'], encoding=ENC))
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
return TSC_STATUS[int(prt.recv(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()
|
list_files()
|
||||||
pass
|
pass
|
||||||
elif cmd == 'INFO':
|
elif cmd == 'INFO':
|
||||||
|
printer_info()
|
||||||
pass
|
pass
|
||||||
elif cmd == 'USE':
|
elif cmd == 'USE':
|
||||||
|
printer_usage()
|
||||||
pass
|
pass
|
||||||
elif cmd == 'PAUSE':
|
elif cmd == 'PAUSE':
|
||||||
|
printer_pause()
|
||||||
pass
|
pass
|
||||||
elif cmd == 'RESUME':
|
elif cmd == 'RESUME':
|
||||||
|
printer_resume()
|
||||||
pass
|
pass
|
||||||
elif cmd == 'CLEAR':
|
elif cmd == 'CLEAR':
|
||||||
|
clear_memory()
|
||||||
pass
|
pass
|
||||||
elif cmd == 'RUN':
|
elif cmd == 'RUN':
|
||||||
|
run_batch(**par)
|
||||||
pass
|
pass
|
||||||
elif cmd == 'STATUS':
|
elif cmd == 'STATUS':
|
||||||
get_status()
|
get_status()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue