From 498b2543dc4336962c8c235ac7a0b41e175fde07 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Sun, 5 Jun 2022 16:15:15 +0200 Subject: Refactored JDS6600 tests, serial connection is no longer used --- lab_control/connection/__init__.py | 0 lab_control/connection/direct_connection.py | 20 ++++++++++++++++++++ lab_control/connection/serial_connection.py | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 lab_control/connection/__init__.py create mode 100644 lab_control/connection/direct_connection.py create mode 100644 lab_control/connection/serial_connection.py (limited to 'lab_control/connection') diff --git a/lab_control/connection/__init__.py b/lab_control/connection/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lab_control/connection/direct_connection.py b/lab_control/connection/direct_connection.py new file mode 100644 index 0000000..56a5cf3 --- /dev/null +++ b/lab_control/connection/direct_connection.py @@ -0,0 +1,20 @@ +class DirectConnection: + def __init__(self, requestHandler): + self.requestHandler = requestHandler + self.open = True + self.config = {} + + def configure(self, config: dict) -> None: + self.config = config + + def close(self) -> None: + self.open = False + + def send(self, request: str) -> str: + return self.requestHandler(request) + + def checkConfiguration(self) -> None: + assert self.config.get("baudrate") == 115200 + assert self.config.get("bytesize") == 8 + assert self.config.get("stopbits") == 1 + assert self.config.get("parity") == "N" diff --git a/lab_control/connection/serial_connection.py b/lab_control/connection/serial_connection.py new file mode 100644 index 0000000..282494b --- /dev/null +++ b/lab_control/connection/serial_connection.py @@ -0,0 +1,26 @@ +import termios +import serial + +class SerialConnection: + def __init__(self, portName): + self._port = serial.Serial(portName) + + def configure(self, config: dict) -> None: + self._port.baudrate = parameters["baudrate"] + self._port.bytesize = parameters["bytesize"] + self._port.stopbits = parameters["stopbits"] + self._port.parity = parameters["parity"] + + def send(self, request): + self._port.write(request.encode()) + return self._port.readline().decode() + + def checkConfiguration(self) -> None: + iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self._port) + + # JDS6600 configuration taken from manual + assert ispeed == termios.B115200 + assert ospeed == termios.B115200 + assert (cflag & termios.CSIZE) == termios.CS8 + assert (cflag & termios.CSTOPB) == 0 + assert (cflag & (termios.PARENB | termios.PARODD)) == 0 -- cgit v1.2.3