stm32-fmt-code/access_control_python/display.py

32 lines
1.0 KiB
Python

import serial
class Display:
def __init__(self, serial_port: str) -> None:
self.serial_adapter = serial.Serial(
port=serial_port,
baudrate =115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1)
self.send_stop_bit()
self.reset_device()
def set_page(self, page):
command = f'page {page}'
self.send_command(command)
def set_string(self, field, text):
command = f'{field}="{text}"'
self.send_command(command)
def send_stop_bit(self):
self.serial_adapter.write(self.get_stop_bit())
def send_command(self, command: str):
command = bytes(command, 'ascii')
self.serial_adapter.write(command)
self.send_stop_bit()
def get_stop_bit(self) -> bytearray:
stop_bit = bytearray()
stop_bit.append(0xFF)
stop_bit.append(0xFF)
stop_bit.append(0XFF)
return stop_bit
def reset_device(self):
self.send_command("rest")