From 1393405ed5e8796a37224344c51cdcd4427f9b4b Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Sun, 5 Jun 2022 11:34:50 +0200 Subject: Minor improvement to automatic vertical scaling --- lab_control/frequency_response.py | 2 +- lab_control/oscilloscope.py | 3 +++ lab_control/sds1000xe.py | 3 +++ lab_control/test/frequency_response_test.py | 6 +++--- lab_control/test/mock_lab.py | 3 +++ 5 files changed, 13 insertions(+), 4 deletions(-) (limited to 'lab_control') diff --git a/lab_control/frequency_response.py b/lab_control/frequency_response.py index 9f6c79e..84259d4 100644 --- a/lab_control/frequency_response.py +++ b/lab_control/frequency_response.py @@ -25,7 +25,7 @@ class FrequencyResponseMeasurement(Measurement): fg.setAmplitude(self.functionGeneratorChannel, self.inputAmplitude) fg.setFunction(self.functionGeneratorChannel, FunctionGenerator.SINE) fg.setOn(self.functionGeneratorChannel) - osc.setVoltsPerDivision(self.oscilloscopeChannel, self.inputAmplitude / 6) + osc.setVoltsPerDivision(self.oscilloscopeChannel, self.inputAmplitude / (osc.getDivisionsDisplayed() - 2)) for f in frequencies: fg.setFrequency(self.functionGeneratorChannel, f) diff --git a/lab_control/oscilloscope.py b/lab_control/oscilloscope.py index 04bd338..8b0c0ec 100644 --- a/lab_control/oscilloscope.py +++ b/lab_control/oscilloscope.py @@ -19,4 +19,7 @@ class Oscilloscope: def setVoltsPerDivision(self, channel: int, volts: float) -> None: """ Sets the vertical scale of specific channel. """ + + def getDivisionsDisplayed(self) -> int: + """ Returns the number of vertical divisions on the device display. """ diff --git a/lab_control/sds1000xe.py b/lab_control/sds1000xe.py index 7f6d552..61fa86d 100644 --- a/lab_control/sds1000xe.py +++ b/lab_control/sds1000xe.py @@ -58,3 +58,6 @@ class SDS1000XE(Oscilloscope): query = f"C{channel}:VDIV {volts:.2E}V\r\n" self._socket.sendall(query.encode()) # no response expected + + def getDivisionsDisplayed(self) -> int: + return 8 diff --git a/lab_control/test/frequency_response_test.py b/lab_control/test/frequency_response_test.py index 61fd021..d694887 100644 --- a/lab_control/test/frequency_response_test.py +++ b/lab_control/test/frequency_response_test.py @@ -49,19 +49,19 @@ def test_frequencyResponseRamp(uut, mockLab): expectedData = prepareRampResponse(uut, mockLab) - assert not uut.measurementDone - assert uut.data is None assert fg.amplitude is None assert fg.function is None assert not fg.on assert osc.voltsPerDiv is None + assert not uut.measurementDone + assert uut.data is None uut.measure(mockLab, mockLab) assert fg.amplitude == uut.inputAmplitude assert fg.function == FunctionGenerator.SINE assert fg.on - assert osc.voltsPerDiv == uut.inputAmplitude / 6 + assert osc.voltsPerDiv == uut.inputAmplitude / (mockLab.getDivisionsDisplayed() - 2) assert uut.measurementDone assert uut.data == expectedData diff --git a/lab_control/test/mock_lab.py b/lab_control/test/mock_lab.py index 75ba1bf..1016b92 100644 --- a/lab_control/test/mock_lab.py +++ b/lab_control/test/mock_lab.py @@ -55,6 +55,9 @@ class MockLab(FunctionGenerator, Oscilloscope): def setVoltsPerDivision(self, channel: int, volts: float) -> None: self.oscChannels[channel - 1].voltsPerDiv = volts + def getDivisionsDisplayed(self) -> int: + return 12 + def setTestFunction(self, channel: int, f: Callable[[float], float]) -> None: self.oscChannels[channel - 1].testFunction = f -- cgit v1.2.3