Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Keithley3706A): Fix interlock status dictionary #5013

Merged
Merged
6 changes: 6 additions & 0 deletions docs/changes/newsfragments/5013.improved_driver
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fixed a bug in interlock status querying for Keithley 3706A. Originally, not all
potential responses from the system were accounted for when querying for interlock
status. A dictionary is used to map the response from the system to a string describing
the interlock status. When the system returns a response that was not accounted for, this
resulted in a KeyError being raised. Now, this dictionary accounts for all potential responses
from the system.
2 changes: 1 addition & 1 deletion qcodes/instrument/sims/Keithley_3706A.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ devices:
- q: "print(slot[6].idn)"
r: "Empty Slot"
- q: "print(slot[1].interlock.state)"
r: 0
r: "nil"
type: int
- q: "print(slot[2].interlock.state)"
r: 0
Expand Down
19 changes: 16 additions & 3 deletions qcodes/instrument_drivers/Keithley/Keithley_3706A.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,15 +793,28 @@ def get_interlock_state(self) -> Tuple[Dict[str, str], ...]:
cannot be energized.
"""
slot_id = self._get_slot_ids()
interlock_status = {0: "Interlock is disengaged", 1: "Interlock is engaged"}
interlock_status = {
None: (
"No card is installed or the installed card does "
"not support interlocks"
),
0: "Interlocks 1 and 2 are disengaged on the card",
1: "Interlock 1 is engaged, interlock 2 (if it exists) is disengaged",
2: "Interlock 2 in engaged, interlock 1 is disengaged",
3: "Both interlock 1 and 2 are engaged",
}
states: List[Dict[str, str]] = []
for i in slot_id:
state = self.get_interlock_state_by_slot(i)
states.append({"slot_no": i, "state": interlock_status[state]})
return tuple(states)

def get_interlock_state_by_slot(self, slot: Union[str, int]) -> int:
return int(float(self.ask(f"slot[{int(slot)}].interlock.state")))
def get_interlock_state_by_slot(self, slot: Union[str, int]) -> Union[int, None]:
state = self.ask(f"slot[{int(slot)}].interlock.state")
if state == "nil":
return None
else:
return int(float(state))

def get_ip_address(self) -> str:
"""
Expand Down
15 changes: 12 additions & 3 deletions qcodes/tests/drivers/test_keithley_3706A.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,18 @@ def test_slot_names(driver):

def test_get_interlock_state(driver):
dict_list = (
{'slot_no': '1', 'state': 'Interlock is disengaged'},
{'slot_no': '2', 'state': 'Interlock is disengaged'},
{'slot_no': '3', 'state': 'Interlock is engaged'},
{
"slot_no": "1",
"state": (
"No card is installed or the installed card does "
"not support interlocks"
),
},
{"slot_no": "2", "state": "Interlocks 1 and 2 are disengaged on the card"},
{
"slot_no": "3",
"state": "Interlock 1 is engaged, interlock 2 (if it exists) is disengaged",
},
)
assert dict_list == driver.get_interlock_state()

Expand Down