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
5 changes: 3 additions & 2 deletions qcodes/instrument/sims/keysight_b1500.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ devices:
error:
error_queue:
- q: 'ERRX?'
default: '0,"No Error."'
command_error: '1,"Command error"'
default: '+0,"No Error."'
lakhotiaharshit marked this conversation as resolved.
Show resolved Hide resolved
command_error: '+1,"Command error"'
status_register:
- q: "*STB?"
command_error: 32
Expand Down Expand Up @@ -71,6 +71,7 @@ devices:
- q: "LMN 0"
- q: "MT 0,0.1,7"
- q: "FMT 1,0"
- q: "FL 1"
- q: "WV 1,1,0,0,0,1,0.1,2"
- q: "WT 0.0,0.0,0.0,0.0,0.0"
- q: "WV 1,1,0,0.0,0.0,1,0.1,2.0"
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 @@ -914,14 +914,4 @@ def setup_staircase_sweep(
self.iv_sweep.current_compliance(i_comp)
self.root_instrument.clear_timer_count()

error_list, error = [], ''

while error != '+0,"No Error."':
error = self.root_instrument.error_message()
error_list.append(error)

if len(error_list) <= 1:
self.setup_fnc_already_run = True
else:
raise RuntimeError(f'Received following errors while trying to '
f'set staircase sweep {error_list}')
self.setup_fnc_already_run = True
Original file line number Diff line number Diff line change
Expand Up @@ -790,17 +790,7 @@ def setup_staircase_cv(
self.ranging_mode(ranging_mode)
self.measurement_range_for_non_auto(fixed_range_val)

error_list, error = [], ''

while error != '+0,"No Error."':
error = self.root_instrument.error_message()
error_list.append(error)

if len(error_list) <= 1:
self.setup_fnc_already_run = True
else:
raise Exception(f'Received following errors while trying to set '
f'staircase sweep {error_list}')
self.setup_fnc_already_run = True


class CVSweepMeasurement(MultiParameter):
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



Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_sampling_measurement(smu_sampling_measurement,
actual_data = smu_sampling_measurement.sampling_measurement_trace.get()

np.testing.assert_allclose(actual_data, data_to_return, atol=1e-3)
smu_sampling_measurement.root_instrument.ask.assert_called_once_with('XE')
smu_sampling_measurement.root_instrument.ask.assert_called_with('XE')


def test_compliance_needs_data_from_sampling_measurement(smu):
Expand Down