otime/serial_test.py

39 lines
1.0 KiB
Python

import serial
import mtrreader
from rich import inspect
import mtrlog
from datetime import datetime
import binascii
import otime
mtr = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=40)
def main():
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())
main()
def send_status_command(mtr):
mtr.write(b'/ST')
if __name__ == '__main__':
#send_status_command(mtr)
main()