stm32-fmt-code/access_control_python/display.py

32 lines
1.0 KiB
Python
Raw Normal View History

2023-11-06 08:42:06 +00:00
import serial
2023-11-06 06:53:10 +00:00
class Display:
2023-11-06 08:42:06 +00:00
def __init__(self, serial_port: str) -> None:
2023-11-14 11:45:43 +00:00
self.serial_adapter = serial.Serial(
port=serial_port,
baudrate =115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1)
2023-11-06 08:42:06 +00:00
self.send_stop_bit()
2023-11-14 11:45:43 +00:00
self.reset_device()
def set_page(self, page):
command = f'page {page}'
self.send_command(command)
2023-11-06 08:42:06 +00:00
def set_string(self, field, text):
2023-11-14 11:45:43 +00:00
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')
2023-11-06 08:42:06 +00:00
self.serial_adapter.write(command)
2023-11-13 12:12:30 +00:00
self.send_stop_bit()
2023-11-14 11:45:43 +00:00
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")