summaryrefslogtreecommitdiffstats
path: root/lab_control/jds6600.py
diff options
context:
space:
mode:
Diffstat (limited to 'lab_control/jds6600.py')
-rw-r--r--lab_control/jds6600.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/lab_control/jds6600.py b/lab_control/jds6600.py
index 6282fd1..2321a4b 100644
--- a/lab_control/jds6600.py
+++ b/lab_control/jds6600.py
@@ -3,8 +3,9 @@ import re
from lab_control.function_generator import FunctionGenerator
-# TODO figure out error handling
class JDS6600(FunctionGenerator):
+ AVAILABLE_CHANNELS = [1, 2]
+
def __init__(self, portName):
self._port = serial.Serial(portName)
self._port.baudrate = 115200
@@ -27,30 +28,37 @@ class JDS6600(FunctionGenerator):
return [response[5], response[7]]
def setOn(self, channel: int) -> None:
+ assert channel in JDS6600.AVAILABLE_CHANNELS, f"JDS6600: Invalid channel {channel}"
+
state = self._queryOnOff()
state[channel - 1] = "1"
response = self._sendRequest("w20", f"{state[0]},{state[1]}")
def setOff(self, channel: int) -> None:
+ assert channel in JDS6600.AVAILABLE_CHANNELS, f"JDS6600: Invalid channel {channel}"
+
state = self._queryOnOff()
state[channel - 1] = "0"
response = self._sendRequest("w20", f"{state[0]},{state[1]}")
def setFrequency(self, channel: int, frequency: float) -> None:
+ assert channel in JDS6600.AVAILABLE_CHANNELS, f"JDS6600: Invalid channel {channel}"
+ assert frequency is not None and frequency >= 0.0 and frequency <= 60e6, f"JDS6600: Invalid frequency {frequency}"
+
# TODO implement after testing on actual device
opcode = f"w{23 + channel - 1}"
def setAmplitude(self, channel: int, amplitude: float) -> None:
- if amplitude is None or amplitude < 0.0 or amplitude > 20.0:
- return
+ assert channel in JDS6600.AVAILABLE_CHANNELS, f"JDS6600: Invalid channel {channel}"
+ assert amplitude is not None and amplitude >= 0.0 and amplitude <= 20.0, f"JDS6600: Invalid amplitude {amplitude}"
opcode = f"w{25 + channel - 1}"
arg = int(amplitude * 1000.0)
response = self._sendRequest(opcode, str(arg))
def setFunction(self, channel: int, function: int) -> None:
- if function is None or function < 0 or function > 16:
- return
+ assert channel in JDS6600.AVAILABLE_CHANNELS, f"JDS6600: Invalid channel {channel}"
+ assert function is not None and function >= 0 and function <= 16, f"JDS6600: Invalid function code {function}"
opcode = f"w{21 + channel - 1}"
response = self._sendRequest(opcode, str(function))