mirror of
https://github.com/janishutz/BiogasControllerApp.git
synced 2025-11-25 05:44:23 +00:00
Improve Com class, continue writing test
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
import serial
|
||||
import struct
|
||||
import serial.tools.list_ports
|
||||
|
||||
|
||||
class Com:
|
||||
class ComSuperClass(ABC):
|
||||
def __init__(self, baudrate: int = 19200, filters: Optional[list[str]] = None) -> None:
|
||||
self._serial: Optional[serial.Serial] = None
|
||||
self._filters = filters if filters != None else [ 'USB-Serial Controller', 'Prolific USB-Serial Controller' ]
|
||||
@@ -19,6 +20,32 @@ class Com:
|
||||
def get_error(self) -> serial.SerialException | None:
|
||||
return self._err
|
||||
|
||||
@abstractmethod
|
||||
def get_comport(self) -> str:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def connect(self) -> bool:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def close(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def receive(self, byte_count: int) -> bytes:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def send(self, msg: str) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def send_float(self, msg: float) -> None:
|
||||
pass
|
||||
|
||||
|
||||
class Com(ComSuperClass):
|
||||
def _connection_check(self) -> bool:
|
||||
if self._serial == None:
|
||||
return self._open()
|
||||
|
||||
Reference in New Issue
Block a user