From e21146472566f75c071798d63e388104e22c6001 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Tue, 31 May 2022 10:47:06 +0200 Subject: Implemented JDS6600 setFrequency --- lab_control/function_generator.py | 2 +- lab_control/jds6600.py | 9 +++++---- lab_control/test/jds6600_test.py | 4 ++-- lab_control/test/mock_jds6600_device.py | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lab_control/function_generator.py b/lab_control/function_generator.py index 35fc1d8..be522d9 100644 --- a/lab_control/function_generator.py +++ b/lab_control/function_generator.py @@ -1,7 +1,7 @@ class FunctionGenerator: SINE = 0 SQUARE = 1 - TRIANGULAR = 2 + TRIANGULAR = 3 def __init__(self): raise Exception("This class should not be instantiated directly, please extend it instead") diff --git a/lab_control/jds6600.py b/lab_control/jds6600.py index 2321a4b..006a041 100644 --- a/lab_control/jds6600.py +++ b/lab_control/jds6600.py @@ -13,7 +13,7 @@ class JDS6600(FunctionGenerator): self._port.stopbits = serial.STOPBITS_ONE self._port.parity = serial.PARITY_NONE - def _sendRequest(self, opcode: str, args: str) -> str: + def _sendRequest(self, opcode: str, args: str="") -> str: request = f":{opcode}={args}.\r\n" self._port.write(request.encode()) responseRaw = self._port.readline() @@ -23,8 +23,8 @@ class JDS6600(FunctionGenerator): self._port.close() def _queryOnOff(self) -> list[str, str]: - # TODO double check query on the device - response = self._sendRequest("r20", "") + # response format: ":r20=0,0." + response = self._sendRequest("r20") return [response[5], response[7]] def setOn(self, channel: int) -> None: @@ -45,8 +45,9 @@ class JDS6600(FunctionGenerator): 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}" + arg = int(frequency * 100.0) + response = self._sendRequest(opcode, str(arg)) def setAmplitude(self, channel: int, amplitude: float) -> None: assert channel in JDS6600.AVAILABLE_CHANNELS, f"JDS6600: Invalid channel {channel}" diff --git a/lab_control/test/jds6600_test.py b/lab_control/test/jds6600_test.py index c53388a..e9089c0 100644 --- a/lab_control/test/jds6600_test.py +++ b/lab_control/test/jds6600_test.py @@ -44,8 +44,8 @@ def test_channelOnAndOff(uut, mockDevice): uut.setOff(ch) assert not mockDevice.isOn(ch) -def disabled_test_setFrequency(uut, mockDevice): - checkNumericalParameter([0.0, 100.0, 100000.0], uut.setFrequency, mockDevice.getFrequency) +def test_setFrequency(uut, mockDevice): + checkNumericalParameter([0.0, 100.0, 100000.0, 60000000.0], uut.setFrequency, mockDevice.getFrequency) def test_setInvalidFrequency(uut, mockDevice): checkInvalidNumericalParameter([-10.0, 60000000.1, None], uut.setFrequency, mockDevice.getFrequency) diff --git a/lab_control/test/mock_jds6600_device.py b/lab_control/test/mock_jds6600_device.py index 426b8ac..6db4f4c 100644 --- a/lab_control/test/mock_jds6600_device.py +++ b/lab_control/test/mock_jds6600_device.py @@ -52,9 +52,9 @@ class MockJDS6600Device(): # channel frequency elif function == 23 or function == 24: - # TODO implement correct behaviour + # Actual device takes a second argument for scaling, here we ignore it and always use 0 (Hz) ch = function - 23 - frequency = float(args[0]) + frequency = float(args[0]) / 100.0 self._channels[ch].frequency = frequency # channel amplitude -- cgit v1.2.3