import socket import re from lab_control.oscilloscope import Oscilloscope class SDS1000XE(Oscilloscope): PORT = 5025 TIMEOUT = 0.2 AVAILABLE_CHANNELS = range(1, 5) def __init__(self, address): self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._socket.connect((address, SDS1000XE.PORT)) self._socket.settimeout(SDS1000XE.TIMEOUT) def measureAmplitude(self, channel: int) -> float: return self._measure(channel, "AMPL") def measurePeakToPeak(self, channel: int) -> float: return self._measure(channel, "PKPK") def measureRMS(self, channel: int) -> float: return self._measure(channel, "RMS") def measureFrequency(self, channel: int) -> float: return self._measure(channel, "FREQ") def _measure(self, channel: int, code: str) -> float: assert channel in SDS1000XE.AVAILABLE_CHANNELS query = f"C{channel}:PAVA? {code}\r\n" self._socket.sendall(query.encode()) try: # TODO add code to regex response = self._socket.recv(4096).decode() m = re.search(r"C(?P\d):PAVA .+,(?P.+)V", response) measurement = float(m.group("rawMeasurement")) except TimeoutError as e: measurement = None return measurement