From 9572c6de19c4fa082fb199d038ba3caacdbd6a8f Mon Sep 17 00:00:00 2001 From: Janek Fleper Date: Mon, 16 Dec 2024 18:06:48 +0100 Subject: [PATCH 1/3] Use correct sense function for sense parameters --- .../private/Keysight_344xxA_submodules.py | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py b/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py index 2a2f53d3526..5363cb44a9f 100644 --- a/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py +++ b/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py @@ -26,7 +26,7 @@ ) if TYPE_CHECKING: - from collections.abc import Sequence + from collections.abc import Sequence, Callable from typing_extensions import Unpack @@ -748,7 +748,7 @@ def __init__( self.NPLC: Parameter = self.add_parameter( "NPLC", - get_cmd="SENSe:VOLTage:DC:NPLC?", + get_cmd=partial(self._ask_with_sense_function, cmd="NPLC"), get_parser=float, set_cmd=self._set_NPLC, vals=vals.Enum(*self.NPLC_list), @@ -836,8 +836,8 @@ def __init__( self.autorange: Parameter = self.add_parameter( "autorange", label="Autorange", - set_cmd="SENSe:VOLTage:DC:RANGe:AUTO {}", - get_cmd="SENSe:VOLTage:DC:RANGe:AUTO?", + set_cmd=self._set_with_sense_function("RANGe:AUTO"), + get_cmd=self._get_with_sense_function("RANGe:AUTO"), val_mapping={"ON": 1, "OFF": 0}, vals=vals.Enum("ON", "OFF"), ) @@ -846,8 +846,8 @@ def __init__( self.autozero: Parameter = self.add_parameter( "autozero", label="Autozero", - set_cmd="SENSe:VOLTage:DC:ZERO:AUTO {}", - get_cmd="SENSe:VOLTage:DC:ZERO:AUTO?", + set_cmd=self._set_with_sense_function("ZERO:AUTO"), + get_cmd=self._get_with_sense_function("ZERO:AUTO"), val_mapping={"ON": 1, "OFF": 0, "ONCE": "ONCE"}, vals=vals.Enum("ON", "OFF", "ONCE"), docstring=textwrap.dedent( @@ -932,8 +932,8 @@ def __init__( self.aperture_mode: Parameter = self.add_parameter( "aperture_mode", label="Aperture mode", - set_cmd="SENSe:VOLTage:DC:APERture:ENABled {}", - get_cmd="SENSe:VOLTage:DC:APERture:ENABled?", + set_cmd=self._set_with_sense_function("APERture:ENABled"), + get_cmd=self._get_with_sense_function("APERture:ENABled"), val_mapping={"ON": 1, "OFF": 0}, vals=vals.Enum("ON", "OFF"), docstring=textwrap.dedent( @@ -953,7 +953,7 @@ def __init__( "aperture_time", label="Aperture time", set_cmd=self._set_apt_time, - get_cmd="SENSe:VOLTage:DC:APERture?", + get_cmd=self._get_with_sense_function("APERture"), get_parser=float, vals=vals.Numbers(*apt_times[self.model]), docstring=textwrap.dedent( @@ -1212,14 +1212,32 @@ def read(self) -> np.ndarray: raw_vals: str = self.ask("READ?") return _raw_vals_to_array(raw_vals) + def _ask_with_sense_function(self, cmd: str) -> str: + function = self.sense_function.get_latest.get_raw().strip("\"") + return self.ask(f"SENSe:{function}:{cmd}?") + + def _write_with_sense_function(self, cmd: str, value: str) -> None: + function = self.sense_function.get_latest.get_raw().strip("\"") + self.write(f"SENSe:{function}:{cmd} {value}") + + def _get_with_sense_function(self, cmd: str) -> "Callable[[], str]": + def func() -> str: + return self._ask_with_sense_function(cmd) + return func + + def _set_with_sense_function(self, cmd: str) -> "Callable[[str], None]": + def func(value: str) -> None: + self._write_with_sense_function(cmd, value) + return func + def _set_apt_time(self, value: float) -> None: - self.write(f"SENSe:VOLTage:DC:APERture {value:f}") + self._write_with_sense_function("APERture", f"{value:f}") # setting aperture time switches aperture mode ON self.aperture_mode.get() def _set_NPLC(self, value: float) -> None: - self.write(f"SENSe:VOLTage:DC:NPLC {value:f}") + self._write_with_sense_function("NPLC", f"{value:f}") # resolution settings change with NPLC self.resolution.get() From 7578b6fe11d71279693c9d2b43e22a1d9187da6b Mon Sep 17 00:00:00 2001 From: Janek Fleper Date: Mon, 16 Dec 2024 19:20:39 +0100 Subject: [PATCH 2/3] Don't use partial for NPLC --- .../Keysight/private/Keysight_344xxA_submodules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py b/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py index 5363cb44a9f..12eb5f3ab01 100644 --- a/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py +++ b/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py @@ -748,7 +748,7 @@ def __init__( self.NPLC: Parameter = self.add_parameter( "NPLC", - get_cmd=partial(self._ask_with_sense_function, cmd="NPLC"), + get_cmd=self._set_with_sense_function("NPLC"), get_parser=float, set_cmd=self._set_NPLC, vals=vals.Enum(*self.NPLC_list), From 202d45aaa60382a125f546cc5d3788730a0dfa6a Mon Sep 17 00:00:00 2001 From: Janek Fleper Date: Tue, 17 Dec 2024 11:32:43 +0100 Subject: [PATCH 3/3] Use the get function for the get_cmd of NPLC --- .../Keysight/private/Keysight_344xxA_submodules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py b/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py index 12eb5f3ab01..5ca2a8f19de 100644 --- a/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py +++ b/src/qcodes/instrument_drivers/Keysight/private/Keysight_344xxA_submodules.py @@ -748,7 +748,7 @@ def __init__( self.NPLC: Parameter = self.add_parameter( "NPLC", - get_cmd=self._set_with_sense_function("NPLC"), + get_cmd=self._get_with_sense_function("NPLC"), get_parser=float, set_cmd=self._set_NPLC, vals=vals.Enum(*self.NPLC_list),