stm32-fmt-code/access_control_python/access_control.py

34 lines
1.1 KiB
Python

import serial
from threading import Thread
class access_control:
_read_buffer = []
serial_adapter: serial.Serial
def __init__(self, serial_port: str):
self.serial_adapter = serial.Serial(serial_port,baudrate=115200)
#Thread(target=self.read_serial).start()
def read_serial(self):
while True:
if True:
print("Reading Serial")
data = self.serial_adapter.read_until(0xFF)
print(data)
#data = data.decode("ascii").removesuffix("\r\n")
self._read_buffer.append(data)
def light_on(self):
packet = bytearray()
packet.append(0x00)
packet.append(0x01)
packet.append(0xFF)
self.serial_adapter.write(packet)
def light_off(self):
packet = bytearray()
packet.append(0x00)
packet.append(0x00)
packet.append(0xFF)
self.serial_adapter.write(packet)
def request_door_state(self):
packet = bytearray()
packet.append(0x01)
packet.append(0xFF)
self.serial_adapter.write(packet)