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