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

Improved error handling of B1500 driver #2041

Merged
merged 8 commits into from
Jun 11, 2020
2 changes: 1 addition & 1 deletion qcodes/instrument/sims/keysight_b1500.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ devices:
error:
error_queue:
- q: 'ERRX?'
default: '0,"No Error."'
default: '+0,"No Error."'
lakhotiaharshit marked this conversation as resolved.
Show resolved Hide resolved
command_error: '1,"Command error"'
astafan8 marked this conversation as resolved.
Show resolved Hide resolved
status_register:
- q: "*STB?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class KeysightB1500(VisaInstrument):
calibration_time_out = 60 # 30 seconds suggested by manual
def __init__(self, name, address, **kwargs):
super().__init__(name, address, terminator="\r\n", **kwargs)

self.by_slot = {}
self.by_channel = {}
self.by_kind = defaultdict(list)
Expand Down Expand Up @@ -64,6 +63,17 @@ def __init__(self, name, address, **kwargs):

self.connect_message()

def write(self, cmd):
astafan8 marked this conversation as resolved.
Show resolved Hide resolved
"""
Extend write method from the super to ask for error message each
time a write command is called.
"""
super().write(cmd)
error_message = self.error_message()
lakhotiaharshit marked this conversation as resolved.
Show resolved Hide resolved
if error_message != '+0,"No Error."':
raise RuntimeError(f"While setting this parameter received "
f"error: {error_message}")

def add_module(self, name: str, module: B1500Module) -> None:
super().add_submodule(name, module)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_self_calibration_failed(b1500):

def test_error_message(b1500):
response = b1500.error_message()
assert '0,"No Error."' == response
assert '+0,"No Error."' == response


def test_clear_timer_count(b1500):
Expand Down Expand Up @@ -268,3 +268,24 @@ def test_enable_smu_filters(b1500):
constants.ChNr.SLOT_03_CH2])
mock_write.assert_called_once_with('FL 1,102,202,302')


def test_error_message_is_called_after_setting_a_parameter(b1500):
mock_ask = MagicMock()
b1500.ask = mock_ask
mock_ask.return_value = '+0,"No Error."'

b1500.enable_smu_filters(True)
mock_ask.assert_called_once_with('ERRX?')

mock_ask.reset_mock()

mock_ask.return_value = '+200, "Output channel not enabled"'
with pytest.raises(Exception) as e_info:
b1500.enable_smu_filters(True)
mock_ask.assert_called_once_with('ERRX?')
error_string = 'While setting this parameter received error: +200, ' \
'"Output channel not enabled"'
assert e_info.value.args[0] == error_string