diff options
Diffstat (limited to 'lab_control/sds1000xe.py')
-rw-r--r-- | lab_control/sds1000xe.py | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/lab_control/sds1000xe.py b/lab_control/sds1000xe.py index f71e422..d86c1c7 100644 --- a/lab_control/sds1000xe.py +++ b/lab_control/sds1000xe.py @@ -1,9 +1,39 @@ import socket +import re +from lab_control.oscilloscope import Oscilloscope -class SDS1000XE: +class SDS1000XE(Oscilloscope): PORT = 5025 + TIMEOUT = 0.2 + + AVAILABLE_CHANNELS = range(1, 5) def __init__(self, ip): - self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.socket.connect((ip, SDS1000XE.PORT)) + self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self._socket.connect((ip, SDS1000XE.PORT)) + self._socket.settimeout(SDS1000XE.TIMEOUT) + + def measureAmplitude(self, channel: int) -> float: + assert channel in SDS1000XE.AVAILABLE_CHANNELS + + query = f"C{channel}:PAVA? AMPL" + self._socket.sendall(query.encode()) + + try: + response = self._socket.recv(4096).decode() + m = re.search(r"C(?P<responseChannel>\d):PAVA AMPL,(?P<rawMeasurement>.+)V", response) + measurement = float(m.group("rawMeasurement")) + except (TimeoutError, AttributeError) as e: + measurement = None + + return measurement + + def measurePkToPk(self, channel: int) -> float: + pass + + def measureRMS(self, channel: int) -> float: + pass + + def measureFrequency(self, channel: int) -> float: + pass |