otime/mtr.py

20 lines
554 B
Python
Raw Normal View History

2022-05-21 14:27:15 +00:00
import otime
import serial
from time import sleep
def dump_all(port):
mtr = serial.Serial(port, baudrate=9600, timeout=40)
# dump all command
mtr.write(b'/SA')
card_dumps = []
sleep(0.4)
while mtr.in_waiting > 0:
mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
size = mtr.read(size=1)
if size == b'\xe6':
meat = mtr.read(229)
full = b'\xFF\xFF\xFF\xFF' + size + meat
card_r = otime.CardDump.from_mtr_bytes(full)
card_dumps.append(card_r)
return card_dumps