stm32-fmt-code/access_control_python/access_control.py

34 lines
1.1 KiB
Python
Raw Normal View History

2023-09-17 08:27:41 +00:00
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)
2023-09-17 09:18:33 +00:00
#Thread(target=self.read_serial).start()
2023-09-17 08:27:41 +00:00
def read_serial(self):
while True:
2023-09-17 09:18:33 +00:00
if True:
print("Reading Serial")
data = self.serial_adapter.read_until(0xFF)
print(data)
2023-09-17 08:27:41 +00:00
#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)
2023-09-17 09:18:33 +00:00
def request_door_state(self):
packet = bytearray()
packet.append(0x01)
packet.append(0xFF)
self.serial_adapter.write(packet)