summaryrefslogtreecommitdiffstats
path: root/lab_control/connection
diff options
context:
space:
mode:
Diffstat (limited to 'lab_control/connection')
-rw-r--r--lab_control/connection/__init__.py0
-rw-r--r--lab_control/connection/direct_connection.py20
-rw-r--r--lab_control/connection/serial_connection.py26
3 files changed, 46 insertions, 0 deletions
diff --git a/lab_control/connection/__init__.py b/lab_control/connection/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lab_control/connection/__init__.py
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