Skip to content

Commit

Permalink
Merge pull request #6115 from jenshnielsen/keithley_refactor
Browse files Browse the repository at this point in the history
Refactor Keithley drivers
  • Loading branch information
jenshnielsen authored May 24, 2024
2 parents 0b64086 + 00934db commit 6392f13
Show file tree
Hide file tree
Showing 11 changed files with 363 additions and 173 deletions.
6 changes: 6 additions & 0 deletions docs/changes/newsfragments/6115.improved_driver
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The Keithley drivers shipping with QCoDeS
have been updated to ensure all Parameters are set as static
attributes that are documented and can be type checked. The docs for the same drivers have been
updated to not document inherited members. This makes the documentation significantly more readable
as it focuses on specific members for a given instrument. The documentation now also links superclasses.
Please consult these for inherited members.
1 change: 1 addition & 0 deletions docs/drivers_api/Keithley.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Keithley Drivers

.. automodule:: qcodes.instrument_drivers.Keithley
:autosummary:
:no-inherited-members:
49 changes: 34 additions & 15 deletions src/qcodes/instrument_drivers/Keithley/Keithley_2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.parameters import Parameter


def _parse_output_string(s: str) -> str:
"""Parses and cleans string outputs of the Keithley"""
Expand Down Expand Up @@ -66,85 +68,95 @@ def __init__(
"frequency": '"FREQ"',
}

self.add_parameter(
self.mode: Parameter = self.add_parameter(
"mode",
get_cmd="SENS:FUNC?",
set_cmd="SENS:FUNC {}",
val_mapping=self._mode_map,
)
"""Parameter mode"""

# Mode specific parameters
self.add_parameter(
self.nplc: Parameter = self.add_parameter(
"nplc",
get_cmd=partial(self._get_mode_param, "NPLC", float),
set_cmd=partial(self._set_mode_param, "NPLC"),
vals=Numbers(min_value=0.01, max_value=10),
)
"""Parameter nplc"""

# TODO: validator, this one is more difficult since different modes
# require different validation ranges
self.add_parameter(
self.range: Parameter = self.add_parameter(
"range",
get_cmd=partial(self._get_mode_param, "RANG", float),
set_cmd=partial(self._set_mode_param, "RANG"),
vals=Numbers(),
)
"""Parameter range"""

self.add_parameter(
self.auto_range_enabled: Parameter = self.add_parameter(
"auto_range_enabled",
get_cmd=partial(self._get_mode_param, "RANG:AUTO", _parse_output_bool),
set_cmd=partial(self._set_mode_param, "RANG:AUTO"),
vals=Bool(),
)
"""Parameter auto_range_enabled"""

self.add_parameter(
self.digits: Parameter = self.add_parameter(
"digits",
get_cmd=partial(self._get_mode_param, "DIG", int),
set_cmd=partial(self._set_mode_param, "DIG"),
vals=Ints(min_value=4, max_value=7),
)
"""Parameter digits"""

self.add_parameter(
self.averaging_type: Parameter = self.add_parameter(
"averaging_type",
get_cmd=partial(self._get_mode_param, "AVER:TCON", _parse_output_string),
set_cmd=partial(self._set_mode_param, "AVER:TCON"),
vals=Enum("moving", "repeat"),
)
"""Parameter averaging_type"""

self.add_parameter(
self.averaging_count: Parameter = self.add_parameter(
"averaging_count",
get_cmd=partial(self._get_mode_param, "AVER:COUN", int),
set_cmd=partial(self._set_mode_param, "AVER:COUN"),
vals=Ints(min_value=1, max_value=100),
)
"""Parameter averaging_count"""

self.add_parameter(
self.averaging_enabled: Parameter = self.add_parameter(
"averaging_enabled",
get_cmd=partial(self._get_mode_param, "AVER:STAT", _parse_output_bool),
set_cmd=partial(self._set_mode_param, "AVER:STAT"),
vals=Bool(),
)
"""Parameter averaging_enabled"""

# Global parameters
self.add_parameter(
self.display_enabled: Parameter = self.add_parameter(
"display_enabled",
get_cmd="DISP:ENAB?",
get_parser=_parse_output_bool,
set_cmd="DISP:ENAB {}",
set_parser=int,
vals=Bool(),
)
"""Parameter display_enabled"""

self.add_parameter(
self.trigger_continuous: Parameter = self.add_parameter(
"trigger_continuous",
get_cmd="INIT:CONT?",
get_parser=_parse_output_bool,
set_cmd="INIT:CONT {}",
set_parser=int,
vals=Bool(),
)
"""Parameter trigger_continuous"""

self.add_parameter(
self.trigger_count: Parameter = self.add_parameter(
"trigger_count",
get_cmd="TRIG:COUN?",
get_parser=int,
Expand All @@ -154,17 +166,19 @@ def __init__(
Enum("inf", "default", "minimum", "maximum"),
),
)
"""Parameter trigger_count"""

self.add_parameter(
self.trigger_delay: Parameter = self.add_parameter(
"trigger_delay",
get_cmd="TRIG:DEL?",
get_parser=float,
set_cmd="TRIG:DEL {}",
unit="s",
vals=Numbers(min_value=0, max_value=999999.999),
)
"""Parameter trigger_delay"""

self.add_parameter(
self.trigger_source: Parameter = self.add_parameter(
"trigger_source",
get_cmd="TRIG:SOUR?",
set_cmd="TRIG:SOUR {}",
Expand All @@ -176,17 +190,22 @@ def __init__(
"external": "EXT",
},
)
"""Parameter trigger_source"""

self.add_parameter(
self.trigger_timer: Parameter = self.add_parameter(
"trigger_timer",
get_cmd="TRIG:TIM?",
get_parser=float,
set_cmd="TRIG:TIM {}",
unit="s",
vals=Numbers(min_value=0.001, max_value=999999.999),
)
"""Parameter trigger_timer"""

self.add_parameter("amplitude", unit="arb.unit", get_cmd=self._read_next_value)
self.amplitude: Parameter = self.add_parameter(
"amplitude", unit="arb.unit", get_cmd=self._read_next_value
)
"""Parameter amplitude"""

self.add_function("reset", call_cmd="*RST")

Expand Down
40 changes: 27 additions & 13 deletions src/qcodes/instrument_drivers/Keithley/Keithley_2400.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
if TYPE_CHECKING:
from typing_extensions import Unpack

from qcodes.parameters import Parameter


class Keithley2400(VisaInstrument):
"""
Expand All @@ -23,39 +25,43 @@ def __init__(
):
super().__init__(name, address, **kwargs)

self.add_parameter(
self.rangev: Parameter = self.add_parameter(
"rangev",
get_cmd="SENS:VOLT:RANG?",
get_parser=float,
set_cmd="SOUR:VOLT:RANG {:f}",
label="Voltage range",
)
"""Parameter rangev"""

self.add_parameter(
self.rangei: Parameter = self.add_parameter(
"rangei",
get_cmd="SENS:CURR:RANG?",
get_parser=float,
set_cmd="SOUR:CURR:RANG {:f}",
label="Current range",
)
"""Parameter rangei"""

self.add_parameter(
self.compliancev: Parameter = self.add_parameter(
"compliancev",
get_cmd="SENS:VOLT:PROT?",
get_parser=float,
set_cmd="SENS:VOLT:PROT {:f}",
label="Voltage Compliance",
)
"""Parameter compliancev"""

self.add_parameter(
self.compliancei: Parameter = self.add_parameter(
"compliancei",
get_cmd="SENS:CURR:PROT?",
get_parser=float,
set_cmd="SENS:CURR:PROT {:f}",
label="Current Compliance",
)
"""Parameter compliancei"""

self.add_parameter(
self.volt: Parameter = self.add_parameter(
"volt",
get_cmd=self._get_read_output_protected,
get_parser=self._volt_parser,
Expand All @@ -69,8 +75,9 @@ def __init__(
"Note that it is an error to read voltage with "
"output off",
)
"""Sets voltage in 'VOLT' mode. Get returns measured voltage if sensing 'VOLT' otherwise it returns setpoint value. Note that it is an error to read voltage with output off"""

self.add_parameter(
self.curr: Parameter = self.add_parameter(
"curr",
get_cmd=self._get_read_output_protected,
get_parser=self._curr_parser,
Expand All @@ -84,56 +91,63 @@ def __init__(
"Note that it is an error to read current with "
"output off",
)
"""Sets current in 'CURR' mode. Get returns measured current if sensing 'CURR' otherwise it returns setpoint value. Note that it is an error to read current with output off"""

self.add_parameter(
self.mode: Parameter = self.add_parameter(
"mode",
vals=Enum("VOLT", "CURR"),
get_cmd=":SOUR:FUNC?",
set_cmd=self._set_mode_and_sense,
label="Mode",
)
"""Parameter mode"""

self.add_parameter(
self.sense: Parameter = self.add_parameter(
"sense",
vals=Strings(),
get_cmd=":SENS:FUNC?",
set_cmd=':SENS:FUNC "{:s}"',
label="Sense mode",
)
"""Parameter sense"""

self.add_parameter(
self.output: Parameter = self.add_parameter(
"output",
set_cmd=":OUTP:STAT {}",
get_cmd=":OUTP:STAT?",
val_mapping=create_on_off_val_mapping(on_val="1", off_val="0"),
)
"""Parameter output"""

self.add_parameter(
self.nplcv: Parameter = self.add_parameter(
"nplcv",
get_cmd="SENS:VOLT:NPLC?",
get_parser=float,
set_cmd="SENS:VOLT:NPLC {:f}",
label="Voltage integration time",
)
"""Parameter nplcv"""

self.add_parameter(
self.nplci: Parameter = self.add_parameter(
"nplci",
get_cmd="SENS:CURR:NPLC?",
get_parser=float,
set_cmd="SENS:CURR:NPLC {:f}",
label="Current integration time",
)
"""Parameter nplci"""

self.add_parameter(
self.resistance: Parameter = self.add_parameter(
"resistance",
get_cmd=self._get_read_output_protected,
get_parser=self._resistance_parser,
label="Resistance",
unit="Ohm",
docstring="Measure resistance from current and voltage "
docstring="Measure resistance from current and voltage. "
"Note that it is an error to read current "
"and voltage with output off",
)
"""Measure resistance from current and voltage. Note that it is an error to read current and voltage with output off"""

self.write(":TRIG:COUN 1;:FORM:ELEM VOLT,CURR")
# This line sends 2 commands to the instrument:
Expand Down
Loading

0 comments on commit 6392f13

Please sign in to comment.