diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2022-06-05 16:15:15 +0200 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2022-06-05 16:15:15 +0200 |
commit | 498b2543dc4336962c8c235ac7a0b41e175fde07 (patch) | |
tree | 8d7f23f0f19d41859c7326fe69f4317789452981 /lab_control/jds6600.py | |
parent | 832e5fc6208f4395aa75423cad28eec5d9bc11a4 (diff) |
Refactored JDS6600 tests, serial connection is no longer used
Diffstat (limited to 'lab_control/jds6600.py')
-rw-r--r-- | lab_control/jds6600.py | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/lab_control/jds6600.py b/lab_control/jds6600.py index 32f12af..5f072af 100644 --- a/lab_control/jds6600.py +++ b/lab_control/jds6600.py @@ -2,9 +2,8 @@ Implements partial support for Joy-IT JDS6600 function generator. """ -import serial - from lab_control.function_generator import FunctionGenerator +from lab_control.connection.serial_connection import SerialConnection def _checkChannel(channel: int): assert channel in JDS6600.AVAILABLE_CHANNELS, f"JDS6600: Invalid channel {channel}" @@ -23,32 +22,41 @@ class JDS6600(FunctionGenerator): """ AVAILABLE_CHANNELS = [1, 2] - def __init__(self, portName): + # TODO type hints + def __init__(self, portName: str, overrideConnection=None): super().__init__() - self._port = serial.Serial(portName) - self._port.baudrate = 115200 - self._port.bytesize = serial.EIGHTBITS - self._port.stopbits = serial.STOPBITS_ONE - self._port.parity = serial.PARITY_NONE + + config = { + "baudrate" : 115200, + "bytesize" : 8, + "stopbits" : 1, + "parity" : "N" + } + + if overrideConnection is not None: + self._connection = overrideConnection + else: + self._connection = SerialConnection(portName) + + self._connection.configure(config) def closePort(self) -> None: """ Close the serial port. Instances of this class are no longer usable after this is called. """ - self._port.close() + self._connection.close() + + def _sendRequest(self, opcode: str, args: str="") -> str: + request = f":{opcode}={args}.\r\n" + response = self._connection.send(request) + return response.strip() def _query(self, opcode: str) -> list[str]: # response format: ":{opcode}={v1},{v2}." response = self._sendRequest(opcode) return response[5:-1].split(",") - def _sendRequest(self, opcode: str, args: str="") -> str: - request = f":{opcode}={args}.\r\n" - self._port.write(request.encode()) - responseRaw = self._port.readline() - return responseRaw.decode().strip() - def setOn(self, channel: int) -> None: _checkChannel(channel) |