2022-04-03 20:00:15 +00:00
|
|
|
import serial
|
|
|
|
import mtrreader
|
|
|
|
from rich import inspect
|
|
|
|
import mtrlog
|
|
|
|
from datetime import datetime
|
2022-04-07 19:00:37 +00:00
|
|
|
import binascii
|
|
|
|
import otime
|
2022-04-03 20:00:15 +00:00
|
|
|
|
|
|
|
mtr = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=40)
|
|
|
|
|
|
|
|
def main():
|
2022-04-07 19:00:37 +00:00
|
|
|
pree = mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
|
|
|
|
size = mtr.read(size=1)
|
|
|
|
if size == b'\xe6':
|
|
|
|
meat = mtr.read(229)
|
|
|
|
print('START')
|
|
|
|
|
|
|
|
full = b'\xFF\xFF\xFF\xFF' + size + meat
|
|
|
|
print(binascii.hexlify(full))
|
|
|
|
msg = mtrreader.MtrDataMessage(full)
|
|
|
|
f = mtrlog.MtrLogFormatter
|
|
|
|
#print(f.format(f, msg, datetime.now()))
|
|
|
|
#card_r_from_mtr_bytes(full)
|
|
|
|
inspect(otime.card_punch.from_mtr_bytes(full))
|
|
|
|
print('END')
|
|
|
|
elif size == b'\x37':
|
|
|
|
meat = mtr.read(55)
|
|
|
|
status = mtrreader.MtrStatusMessage(meat)
|
|
|
|
inspect(status)
|
|
|
|
print(status.year(),status.month(),status.day(),status.hours(),status.minutes())
|
2022-04-03 20:00:15 +00:00
|
|
|
main()
|
|
|
|
|
2022-04-07 19:00:37 +00:00
|
|
|
def send_status_command(mtr):
|
|
|
|
mtr.write(b'/ST')
|
|
|
|
|
2022-04-03 20:00:15 +00:00
|
|
|
if __name__ == '__main__':
|
2022-04-07 19:00:37 +00:00
|
|
|
#send_status_command(mtr)
|
2022-04-03 20:00:15 +00:00
|
|
|
main()
|