From 4d99ada31e7e5964eb279929564b39311e75145f Mon Sep 17 00:00:00 2001 From: Pieter Date: Fri, 22 Jul 2016 09:38:17 +0200 Subject: [PATCH 01/11] workaround for termination character issues --- qcodes/instrument_drivers/QuTech/IVVI.py | 66 +++++++++++++++++------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/qcodes/instrument_drivers/QuTech/IVVI.py b/qcodes/instrument_drivers/QuTech/IVVI.py index 69a39a31f9b6..1268953fbee4 100644 --- a/qcodes/instrument_drivers/QuTech/IVVI.py +++ b/qcodes/instrument_drivers/QuTech/IVVI.py @@ -58,9 +58,11 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, # values based on descriptor self.visa_handle.baud_rate = 115200 self.visa_handle.parity = visa.constants.Parity(1) # odd parity + self.visa_handle.write_termination='' + self.visa_handle.read_termination='' - self.add_parameter('version', - get_cmd=self._get_version) +# self.add_parameter('version', +# get_cmd=self._get_version) self.add_parameter('dac voltages', label='Dac voltages', @@ -87,7 +89,7 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, t1 = time.time() - # basic test to confirm we are properly connected +# basic test to confirm we are properly connected try: self.get_all() except Exception as ex: @@ -96,19 +98,27 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, print('Initialized IVVI-rack in %.2fs' % (t1-t0)) - def get_idn(self): - """ - Overwrites the get_idn function using constants as the hardware - does not have a proper *IDN function. - """ - idparts = ['QuTech', 'IVVI', 'None', self.version()] +# def get_idn(self): +# """ +# Overwrites the get_idn function using constants as the hardware +# does not have a proper *IDN function. +# """ +# idparts = ['QuTech', 'IVVI', 'None', self.version()] +# +# return dict(zip(('vendor', 'model', 'serial', 'firmware'), idparts)) - return dict(zip(('vendor', 'model', 'serial', 'firmware'), idparts)) + def get_idn(self): + ''' + makeshift replacement for the get_idn, because the original wants to do a get_version + ''' + IDN=['vendor','model','serial','etc.'] + + return IDN - def _get_version(self): - mes = self.ask(bytes([3, 4])) - v = mes[2] - return v +# def _get_version(self): +# mes = self.ask(bytes([3, 4])) +# v = mes[2] +# return v def get_all(self): return self.snapshot(update=True) @@ -247,6 +257,28 @@ def ask(self, message, raw=False): message_len = self.write(message, raw=raw) return self.read(message_len=message_len) + def _read_raw_bytes(self, size, maxread=256, verbose=0): + """ Read raw data in blocks using the visa lib + + The pyvisa visalib.read always terminates at a newline, this is a workaround + + Also see: https://github.com/qdev-dk/Qcodes/issues/276 + https://github.com/hgrecco/pyvisa/issues/225 + """ + ret = [] + instr=self.visa_handle + with self.visa_handle.ignore_warning(visa.constants.VI_SUCCESS_MAX_CNT): + nread=0 + while nread < size: + nn=min(maxread, size-nread) + chunk, status = instr.visalib.read(instr.session, nn) + ret += [chunk] + nread+=len(chunk) + if verbose: + print('_read_raw: %d/%d bytes' % (len(chunk), nread)) + ret=b''.join(ret) + return ret + def read(self, message_len=None): # because protocol has no termination chars the read reads the number # of bytes in the buffer @@ -265,10 +297,8 @@ def read(self, message_len=None): if t1-t0 > timeout: raise TimeoutError() # a workaround for a timeout error in the pyvsia read_raw() function - with(self.visa_handle.ignore_warning(visa.constants.VI_SUCCESS_MAX_CNT)): - mes = self.visa_handle.visalib.read( - self.visa_handle.session, bytes_in_buffer) - mes = mes[0] # cannot be done on same line for some reason + mes=self._read_raw_bytes(bytes_in_buffer) + # if mes[1] != 0: # # see protocol descriptor for error codes # raise Exception('IVVI rack exception "%s"' % mes[1]) From de2b33e635d3bc1d2f98d7a173e46fde8cdde5c0 Mon Sep 17 00:00:00 2001 From: Pieter Date: Fri, 22 Jul 2016 09:48:40 +0200 Subject: [PATCH 02/11] fix version command; fix issue with expected_answer_length --- qcodes/instrument_drivers/QuTech/IVVI.py | 41 +++++++++++------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/qcodes/instrument_drivers/QuTech/IVVI.py b/qcodes/instrument_drivers/QuTech/IVVI.py index 1268953fbee4..7367e29a47c8 100644 --- a/qcodes/instrument_drivers/QuTech/IVVI.py +++ b/qcodes/instrument_drivers/QuTech/IVVI.py @@ -61,8 +61,8 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, self.visa_handle.write_termination='' self.visa_handle.read_termination='' -# self.add_parameter('version', -# get_cmd=self._get_version) + self.add_parameter('version', + get_cmd=self._get_version) self.add_parameter('dac voltages', label='Dac voltages', @@ -98,27 +98,21 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, print('Initialized IVVI-rack in %.2fs' % (t1-t0)) -# def get_idn(self): -# """ -# Overwrites the get_idn function using constants as the hardware -# does not have a proper *IDN function. -# """ -# idparts = ['QuTech', 'IVVI', 'None', self.version()] -# -# return dict(zip(('vendor', 'model', 'serial', 'firmware'), idparts)) - def get_idn(self): - ''' - makeshift replacement for the get_idn, because the original wants to do a get_version - ''' - IDN=['vendor','model','serial','etc.'] - - return IDN + """ + Overwrites the get_idn function using constants as the hardware + does not have a proper *IDN function. + """ + idparts = ['QuTech', 'IVVI', 'None', self.version()] + + return dict(zip(('vendor', 'model', 'serial', 'firmware'), idparts)) -# def _get_version(self): -# mes = self.ask(bytes([3, 4])) -# v = mes[2] -# return v + def _get_version(self): + # not all IVVI racks support the version command, so return a dummy + return -1 + mes = self.ask(bytes([3, 4])) + v = mes[2] + return v def get_all(self): return self.snapshot(update=True) @@ -237,9 +231,10 @@ def write(self, message, raw=False): returns message_len ''' - # This is used when write is used in the ask command - expected_answer_length = message[0] + expected_answer_length = None if not raw: + # This is used when write is used in the ask command + expected_answer_length = message[0] message_len = len(message)+2 error_code = bytes([0]) message = bytes([message_len]) + error_code + message From 1afa449198afcb68e89945aa9afb6015ca3b7583 Mon Sep 17 00:00:00 2001 From: Pieter Date: Fri, 22 Jul 2016 14:03:21 +0200 Subject: [PATCH 03/11] make sure termination characters are ignored --- qcodes/instrument_drivers/QuTech/IVVI.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/qcodes/instrument_drivers/QuTech/IVVI.py b/qcodes/instrument_drivers/QuTech/IVVI.py index 7367e29a47c8..5f0117098fe7 100644 --- a/qcodes/instrument_drivers/QuTech/IVVI.py +++ b/qcodes/instrument_drivers/QuTech/IVVI.py @@ -96,6 +96,12 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, print('IVVI: get_all() failed, maybe connected to wrong port?') print(traceback.format_exc()) + v=self.visa_handle + + # make sure we igonore termination characters + # http://www.ni.com/tutorial/4256/en/#toc2 on Termination Character Enabled + v.set_visa_attribute(visa.constants.VI_ATTR_TERMCHAR_EN, 0) + v.set_visa_attribute(visa.constants.VI_ATTR_ASRL_END_IN, 0) print('Initialized IVVI-rack in %.2fs' % (t1-t0)) def get_idn(self): @@ -252,10 +258,19 @@ def ask(self, message, raw=False): message_len = self.write(message, raw=raw) return self.read(message_len=message_len) - def _read_raw_bytes(self, size, maxread=256, verbose=0): + def _read_raw_bytes_direct(self, size): + """ Read raw data using the visa lib + + """ + with(self.visa_handle.ignore_warning(visa.constants.VI_SUCCESS_MAX_CNT)): + mes = self.visa_handle.visalib.read( + self.visa_handle.session, size) + return mes[0] + + def _read_raw_bytes_multiple(self, size, maxread=256, verbose=0): """ Read raw data in blocks using the visa lib - The pyvisa visalib.read always terminates at a newline, this is a workaround + The pyvisa visalib.read does not always terminates at a newline, this is a workaround Also see: https://github.com/qdev-dk/Qcodes/issues/276 https://github.com/hgrecco/pyvisa/issues/225 @@ -292,7 +307,7 @@ def read(self, message_len=None): if t1-t0 > timeout: raise TimeoutError() # a workaround for a timeout error in the pyvsia read_raw() function - mes=self._read_raw_bytes(bytes_in_buffer) + mes=self._read_raw_bytes_multiple(bytes_in_buffer) # if mes[1] != 0: # # see protocol descriptor for error codes From 924195822a64132546beeb2f66ed1c85390e6e8f Mon Sep 17 00:00:00 2001 From: Ruben van Gulik Date: Fri, 16 Sep 2016 09:38:56 +0200 Subject: [PATCH 04/11] fix: Mode-dependent parameters --- .../tektronix/Keithley_2000.py | 75 ++++++++++++------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/qcodes/instrument_drivers/tektronix/Keithley_2000.py b/qcodes/instrument_drivers/tektronix/Keithley_2000.py index b848bcc4560c..a90e2adb49b1 100644 --- a/qcodes/instrument_drivers/tektronix/Keithley_2000.py +++ b/qcodes/instrument_drivers/tektronix/Keithley_2000.py @@ -1,8 +1,9 @@ from qcodes import VisaInstrument -from qcodes.utils.validators import Numbers, Ints, Enum, MultiType +from qcodes.utils.validators import Numbers, Ints, Enum, MultiType, Bool from functools import partial + def parse_output_string(s): """ Parses and cleans string outputs of the Keithley """ # Remove surrounding whitespace and newline characters @@ -25,31 +26,37 @@ def parse_output_string(s): return s + def parse_output_bool(value): - return 'on' if int(value) == 1 else 'off' + return True if int(value) == 1 else False + class Keithley_2000(VisaInstrument): """ Driver for the Keithley 2000 multimeter. """ - def __init__(self, name, address, reset=False, **kwargs): + def __init__(self, name, address, reset=False, terminator='\n', **kwargs): super().__init__(name, address, **kwargs) self._trigger_sent = False + # Unfortunately the strings have to contain quotation marks and a + # newline character, as this is how the instrument returns it. + self._mode_map = { + 'ac current': '"CURR:AC"\n', + 'dc current': '"CURR:DC"\n', + 'ac voltage': '"VOLT:AC"\n', + 'dc voltage': '"VOLT:DC"\n', + '2w resistance': '"RES"\n', + '4w resistance': '"FRES"\n', + 'temperature': '"TEMP"\n', + 'frequency': '"FREQ"\n', + } + self.add_parameter('mode', get_cmd='SENS:FUNC?', set_cmd="SENS:FUNC {}", - val_mapping={ - 'ac current': '"CURR:AC"\n', - 'dc current': '"CURR:DC"\n', - 'ac voltage': '"VOLT:AC"\n', - 'dc voltage': '"VOLT:DC"\n', - '2w resistance': '"RES"\n', - '4w resistance': '"FRES"\n', - 'temperature': '"TEMP"\n', - 'frequency': '"FREQ"\n', - }) + val_mapping=self._mode_map) # Mode specific parameters self.add_parameter('nplc', @@ -64,10 +71,10 @@ def __init__(self, name, address, reset=False, **kwargs): set_cmd=partial(self._set_mode_param, 'RANG'), vals=Numbers()) - self.add_parameter('auto_range', + 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=Enum('on', 'off')) + vals=Bool()) self.add_parameter('digits', get_cmd=partial(self._get_mode_param, 'DIG', int), @@ -84,31 +91,39 @@ def __init__(self, name, address, reset=False, **kwargs): set_cmd=partial(self._set_mode_param, 'AVER:COUN'), vals=Ints(min_value=1, max_value=100)) - self.add_parameter('averaging', + 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=Enum('on', 'off')) + vals=Bool()) # Global parameters - self.add_parameter('display', + self.add_parameter('display_enabled', get_cmd='DISP:ENAB?', get_parser=parse_output_bool, set_cmd='DISP:ENAB {}', - vals=Enum('on', 'off')) + set_parser=int, + vals=Bool()) self.add_parameter('trigger_continuous', get_cmd='INIT:CONT?', get_parser=parse_output_bool, set_cmd='INIT:CONT {}', - vals=Enum('on', 'off')) + set_parser=int, + vals=Bool()) self.add_parameter('trigger_count', get_cmd='TRIG:COUN?', + get_parser=int, set_cmd='TRIG:COUN {}', - vals=MultiType(Ints(min_value=1, max_value=9999), Enum('inf'))) + vals=MultiType(Ints(min_value=1, max_value=9999), + Enum('inf', + 'default', + 'minimum', + 'maximum'))) self.add_parameter('trigger_delay', get_cmd='TRIG:DEL?', + get_parser=float, set_cmd='TRIG:DEL {}', units='s', vals=Numbers(min_value=0, max_value=999999.999)) @@ -126,6 +141,7 @@ def __init__(self, name, address, reset=False, **kwargs): self.add_parameter('trigger_timer', get_cmd='TRIG:TIM?', + get_parser=float, set_cmd='TRIG:TIM {}', units='s', vals=Numbers(min_value=0.001, max_value=999999.999)) @@ -142,13 +158,13 @@ def __init__(self, name, address, reset=False, **kwargs): self.connect_message() def trigger(self): - if self.trigger_continuous() == 'off': + if self.trigger_continuous(): self.write('INIT') self._trigger_sent = True def _read_next_value(self): # Prevent a timeout when no trigger has been sent - if self.trigger_continuous() == 'off' and not self._trigger_sent: + if self.trigger_continuous() and not self._trigger_sent: return 0.0 self._trigger_sent = False @@ -156,11 +172,18 @@ def _read_next_value(self): return float(self.ask('DATA:FRESH?')) def _get_mode_param(self, parameter, parser): - cmd = '{}:{}?'.format(self.mode(), parameter) + """ Read the current Keithley mode and ask for a parameter """ + mode = parse_output_string(self._mode_map[self.mode()]) + cmd = '{}:{}?'.format(mode, parameter) return parser(self.ask(cmd)) def _set_mode_param(self, parameter, value): - cmd = '{}:{} {}'.format(self.mode(), parameter, value) + """ Read the current Keithley mode and set a parameter """ + if type(value) is bool: + value = int(value) + + mode = parse_output_string(self._mode_map[self.mode()]) + cmd = '{}:{} {}'.format(mode, parameter, value) - self.write(cmd) \ No newline at end of file + self.write(cmd) From 8a566f517ff957d889f35894aff2b22f0bdd1669 Mon Sep 17 00:00:00 2001 From: Ruben van Gulik Date: Fri, 16 Sep 2016 09:40:49 +0200 Subject: [PATCH 05/11] refactor: PEP8 formatting --- .../tektronix/Keithley_2000.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/qcodes/instrument_drivers/tektronix/Keithley_2000.py b/qcodes/instrument_drivers/tektronix/Keithley_2000.py index a90e2adb49b1..8b94fe7f9949 100644 --- a/qcodes/instrument_drivers/tektronix/Keithley_2000.py +++ b/qcodes/instrument_drivers/tektronix/Keithley_2000.py @@ -60,19 +60,22 @@ def __init__(self, name, address, reset=False, terminator='\n', **kwargs): # Mode specific parameters self.add_parameter('nplc', - get_cmd=partial(self._get_mode_param, 'NPLC', float), + 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)) # TODO: validator, this one is more difficult since different modes # require different validation ranges self.add_parameter('range', - get_cmd=partial(self._get_mode_param, 'RANG', float), + get_cmd=partial(self._get_mode_param, 'RANG', + float), set_cmd=partial(self._set_mode_param, 'RANG'), vals=Numbers()) self.add_parameter('auto_range_enabled', - get_cmd=partial(self._get_mode_param, 'RANG:AUTO', parse_output_bool), + get_cmd=partial(self._get_mode_param, 'RANG:AUTO', + parse_output_bool), set_cmd=partial(self._set_mode_param, 'RANG:AUTO'), vals=Bool()) @@ -82,17 +85,20 @@ def __init__(self, name, address, reset=False, terminator='\n', **kwargs): vals=Ints(min_value=4, max_value=7)) self.add_parameter('averaging_type', - get_cmd=partial(self._get_mode_param, 'AVER:TCON', parse_output_string), + 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')) self.add_parameter('averaging_count', - get_cmd=partial(self._get_mode_param, 'AVER:COUN', int), + 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)) self.add_parameter('averaging_enabled', - get_cmd=partial(self._get_mode_param, 'AVER:STAT', parse_output_bool), + get_cmd=partial(self._get_mode_param, 'AVER:STAT', + parse_output_bool), set_cmd=partial(self._set_mode_param, 'AVER:STAT'), vals=Bool()) From 82946cc01ed8ba9484e26c8ecf92b73ec158f899 Mon Sep 17 00:00:00 2001 From: Ruben van Gulik Date: Fri, 16 Sep 2016 09:56:57 +0200 Subject: [PATCH 06/11] Revert "make sure termination characters are ignored" This reverts commit 1afa449198afcb68e89945aa9afb6015ca3b7583. --- qcodes/instrument_drivers/QuTech/IVVI.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/qcodes/instrument_drivers/QuTech/IVVI.py b/qcodes/instrument_drivers/QuTech/IVVI.py index 5f0117098fe7..7367e29a47c8 100644 --- a/qcodes/instrument_drivers/QuTech/IVVI.py +++ b/qcodes/instrument_drivers/QuTech/IVVI.py @@ -96,12 +96,6 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, print('IVVI: get_all() failed, maybe connected to wrong port?') print(traceback.format_exc()) - v=self.visa_handle - - # make sure we igonore termination characters - # http://www.ni.com/tutorial/4256/en/#toc2 on Termination Character Enabled - v.set_visa_attribute(visa.constants.VI_ATTR_TERMCHAR_EN, 0) - v.set_visa_attribute(visa.constants.VI_ATTR_ASRL_END_IN, 0) print('Initialized IVVI-rack in %.2fs' % (t1-t0)) def get_idn(self): @@ -258,19 +252,10 @@ def ask(self, message, raw=False): message_len = self.write(message, raw=raw) return self.read(message_len=message_len) - def _read_raw_bytes_direct(self, size): - """ Read raw data using the visa lib - - """ - with(self.visa_handle.ignore_warning(visa.constants.VI_SUCCESS_MAX_CNT)): - mes = self.visa_handle.visalib.read( - self.visa_handle.session, size) - return mes[0] - - def _read_raw_bytes_multiple(self, size, maxread=256, verbose=0): + def _read_raw_bytes(self, size, maxread=256, verbose=0): """ Read raw data in blocks using the visa lib - The pyvisa visalib.read does not always terminates at a newline, this is a workaround + The pyvisa visalib.read always terminates at a newline, this is a workaround Also see: https://github.com/qdev-dk/Qcodes/issues/276 https://github.com/hgrecco/pyvisa/issues/225 @@ -307,7 +292,7 @@ def read(self, message_len=None): if t1-t0 > timeout: raise TimeoutError() # a workaround for a timeout error in the pyvsia read_raw() function - mes=self._read_raw_bytes_multiple(bytes_in_buffer) + mes=self._read_raw_bytes(bytes_in_buffer) # if mes[1] != 0: # # see protocol descriptor for error codes From 1312c1bba570142e3116b5637c0a70fba9e6ab08 Mon Sep 17 00:00:00 2001 From: Ruben van Gulik Date: Fri, 16 Sep 2016 09:57:05 +0200 Subject: [PATCH 07/11] Revert "fix version command; fix issue with expected_answer_length" This reverts commit de2b33e635d3bc1d2f98d7a173e46fde8cdde5c0. --- qcodes/instrument_drivers/QuTech/IVVI.py | 41 +++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/qcodes/instrument_drivers/QuTech/IVVI.py b/qcodes/instrument_drivers/QuTech/IVVI.py index 7367e29a47c8..1268953fbee4 100644 --- a/qcodes/instrument_drivers/QuTech/IVVI.py +++ b/qcodes/instrument_drivers/QuTech/IVVI.py @@ -61,8 +61,8 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, self.visa_handle.write_termination='' self.visa_handle.read_termination='' - self.add_parameter('version', - get_cmd=self._get_version) +# self.add_parameter('version', +# get_cmd=self._get_version) self.add_parameter('dac voltages', label='Dac voltages', @@ -98,21 +98,27 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, print('Initialized IVVI-rack in %.2fs' % (t1-t0)) - def get_idn(self): - """ - Overwrites the get_idn function using constants as the hardware - does not have a proper *IDN function. - """ - idparts = ['QuTech', 'IVVI', 'None', self.version()] +# def get_idn(self): +# """ +# Overwrites the get_idn function using constants as the hardware +# does not have a proper *IDN function. +# """ +# idparts = ['QuTech', 'IVVI', 'None', self.version()] +# +# return dict(zip(('vendor', 'model', 'serial', 'firmware'), idparts)) - return dict(zip(('vendor', 'model', 'serial', 'firmware'), idparts)) + def get_idn(self): + ''' + makeshift replacement for the get_idn, because the original wants to do a get_version + ''' + IDN=['vendor','model','serial','etc.'] + + return IDN - def _get_version(self): - # not all IVVI racks support the version command, so return a dummy - return -1 - mes = self.ask(bytes([3, 4])) - v = mes[2] - return v +# def _get_version(self): +# mes = self.ask(bytes([3, 4])) +# v = mes[2] +# return v def get_all(self): return self.snapshot(update=True) @@ -231,10 +237,9 @@ def write(self, message, raw=False): returns message_len ''' - expected_answer_length = None + # This is used when write is used in the ask command + expected_answer_length = message[0] if not raw: - # This is used when write is used in the ask command - expected_answer_length = message[0] message_len = len(message)+2 error_code = bytes([0]) message = bytes([message_len]) + error_code + message From b73933e7ba9123e30fab2b92aa913ee683779009 Mon Sep 17 00:00:00 2001 From: Ruben van Gulik Date: Fri, 16 Sep 2016 09:57:08 +0200 Subject: [PATCH 08/11] Revert "workaround for termination character issues" This reverts commit 4d99ada31e7e5964eb279929564b39311e75145f. --- qcodes/instrument_drivers/QuTech/IVVI.py | 66 +++++++----------------- 1 file changed, 18 insertions(+), 48 deletions(-) diff --git a/qcodes/instrument_drivers/QuTech/IVVI.py b/qcodes/instrument_drivers/QuTech/IVVI.py index 1268953fbee4..69a39a31f9b6 100644 --- a/qcodes/instrument_drivers/QuTech/IVVI.py +++ b/qcodes/instrument_drivers/QuTech/IVVI.py @@ -58,11 +58,9 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, # values based on descriptor self.visa_handle.baud_rate = 115200 self.visa_handle.parity = visa.constants.Parity(1) # odd parity - self.visa_handle.write_termination='' - self.visa_handle.read_termination='' -# self.add_parameter('version', -# get_cmd=self._get_version) + self.add_parameter('version', + get_cmd=self._get_version) self.add_parameter('dac voltages', label='Dac voltages', @@ -89,7 +87,7 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, t1 = time.time() -# basic test to confirm we are properly connected + # basic test to confirm we are properly connected try: self.get_all() except Exception as ex: @@ -98,27 +96,19 @@ def __init__(self, name, address, reset=False, numdacs=16, dac_step=10, print('Initialized IVVI-rack in %.2fs' % (t1-t0)) -# def get_idn(self): -# """ -# Overwrites the get_idn function using constants as the hardware -# does not have a proper *IDN function. -# """ -# idparts = ['QuTech', 'IVVI', 'None', self.version()] -# -# return dict(zip(('vendor', 'model', 'serial', 'firmware'), idparts)) - def get_idn(self): - ''' - makeshift replacement for the get_idn, because the original wants to do a get_version - ''' - IDN=['vendor','model','serial','etc.'] - - return IDN + """ + Overwrites the get_idn function using constants as the hardware + does not have a proper *IDN function. + """ + idparts = ['QuTech', 'IVVI', 'None', self.version()] -# def _get_version(self): -# mes = self.ask(bytes([3, 4])) -# v = mes[2] -# return v + return dict(zip(('vendor', 'model', 'serial', 'firmware'), idparts)) + + def _get_version(self): + mes = self.ask(bytes([3, 4])) + v = mes[2] + return v def get_all(self): return self.snapshot(update=True) @@ -257,28 +247,6 @@ def ask(self, message, raw=False): message_len = self.write(message, raw=raw) return self.read(message_len=message_len) - def _read_raw_bytes(self, size, maxread=256, verbose=0): - """ Read raw data in blocks using the visa lib - - The pyvisa visalib.read always terminates at a newline, this is a workaround - - Also see: https://github.com/qdev-dk/Qcodes/issues/276 - https://github.com/hgrecco/pyvisa/issues/225 - """ - ret = [] - instr=self.visa_handle - with self.visa_handle.ignore_warning(visa.constants.VI_SUCCESS_MAX_CNT): - nread=0 - while nread < size: - nn=min(maxread, size-nread) - chunk, status = instr.visalib.read(instr.session, nn) - ret += [chunk] - nread+=len(chunk) - if verbose: - print('_read_raw: %d/%d bytes' % (len(chunk), nread)) - ret=b''.join(ret) - return ret - def read(self, message_len=None): # because protocol has no termination chars the read reads the number # of bytes in the buffer @@ -297,8 +265,10 @@ def read(self, message_len=None): if t1-t0 > timeout: raise TimeoutError() # a workaround for a timeout error in the pyvsia read_raw() function - mes=self._read_raw_bytes(bytes_in_buffer) - + with(self.visa_handle.ignore_warning(visa.constants.VI_SUCCESS_MAX_CNT)): + mes = self.visa_handle.visalib.read( + self.visa_handle.session, bytes_in_buffer) + mes = mes[0] # cannot be done on same line for some reason # if mes[1] != 0: # # see protocol descriptor for error codes # raise Exception('IVVI rack exception "%s"' % mes[1]) From 79a3815b636b5bac9c6dc0f1e34114936db1f4ba Mon Sep 17 00:00:00 2001 From: Ruben van Gulik Date: Mon, 19 Sep 2016 21:41:54 +0200 Subject: [PATCH 09/11] fix: typos in triggering check --- qcodes/instrument_drivers/tektronix/Keithley_2000.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qcodes/instrument_drivers/tektronix/Keithley_2000.py b/qcodes/instrument_drivers/tektronix/Keithley_2000.py index 8b94fe7f9949..d0fb729fd622 100644 --- a/qcodes/instrument_drivers/tektronix/Keithley_2000.py +++ b/qcodes/instrument_drivers/tektronix/Keithley_2000.py @@ -164,13 +164,13 @@ def __init__(self, name, address, reset=False, terminator='\n', **kwargs): self.connect_message() def trigger(self): - if self.trigger_continuous(): + if not self.trigger_continuous(): self.write('INIT') self._trigger_sent = True def _read_next_value(self): # Prevent a timeout when no trigger has been sent - if self.trigger_continuous() and not self._trigger_sent: + if not self.trigger_continuous() and not self._trigger_sent: return 0.0 self._trigger_sent = False From 0f62b7436b7f4620056e5f0db39fb7a4232dee34 Mon Sep 17 00:00:00 2001 From: Ruben van Gulik Date: Tue, 20 Sep 2016 18:40:46 +0200 Subject: [PATCH 10/11] refactor: bool type check --- qcodes/instrument_drivers/tektronix/Keithley_2000.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcodes/instrument_drivers/tektronix/Keithley_2000.py b/qcodes/instrument_drivers/tektronix/Keithley_2000.py index d0fb729fd622..9ad90705597a 100644 --- a/qcodes/instrument_drivers/tektronix/Keithley_2000.py +++ b/qcodes/instrument_drivers/tektronix/Keithley_2000.py @@ -186,7 +186,7 @@ def _get_mode_param(self, parameter, parser): def _set_mode_param(self, parameter, value): """ Read the current Keithley mode and set a parameter """ - if type(value) is bool: + if isinstance(value, bool): value = int(value) mode = parse_output_string(self._mode_map[self.mode()]) From 707f98da58d11eadae4d423969c45ed888be1a53 Mon Sep 17 00:00:00 2001 From: Ruben van Gulik Date: Tue, 20 Sep 2016 18:47:58 +0200 Subject: [PATCH 11/11] fix: newline char handling --- .../tektronix/Keithley_2000.py | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/qcodes/instrument_drivers/tektronix/Keithley_2000.py b/qcodes/instrument_drivers/tektronix/Keithley_2000.py index 9ad90705597a..9dc78a1018d6 100644 --- a/qcodes/instrument_drivers/tektronix/Keithley_2000.py +++ b/qcodes/instrument_drivers/tektronix/Keithley_2000.py @@ -35,22 +35,22 @@ class Keithley_2000(VisaInstrument): """ Driver for the Keithley 2000 multimeter. """ - def __init__(self, name, address, reset=False, terminator='\n', **kwargs): - super().__init__(name, address, **kwargs) + def __init__(self, name, address, reset=False, **kwargs): + super().__init__(name, address, terminator='\n', **kwargs) self._trigger_sent = False # Unfortunately the strings have to contain quotation marks and a # newline character, as this is how the instrument returns it. self._mode_map = { - 'ac current': '"CURR:AC"\n', - 'dc current': '"CURR:DC"\n', - 'ac voltage': '"VOLT:AC"\n', - 'dc voltage': '"VOLT:DC"\n', - '2w resistance': '"RES"\n', - '4w resistance': '"FRES"\n', - 'temperature': '"TEMP"\n', - 'frequency': '"FREQ"\n', + 'ac current': '"CURR:AC"', + 'dc current': '"CURR:DC"', + 'ac voltage': '"VOLT:AC"', + 'dc voltage': '"VOLT:DC"', + '2w resistance': '"RES"', + '4w resistance': '"FRES"', + 'temperature': '"TEMP"', + 'frequency': '"FREQ"', } self.add_parameter('mode', @@ -138,11 +138,11 @@ def __init__(self, name, address, reset=False, terminator='\n', **kwargs): get_cmd='TRIG:SOUR?', set_cmd='TRIG:SOUR {}', val_mapping={ - 'immediate': 'IMM\n', - 'timer': 'TIM\n', - 'manual': 'MAN\n', - 'bus': 'BUS\n', - 'external': 'EXT\n', + 'immediate': 'IMM', + 'timer': 'TIM', + 'manual': 'MAN', + 'bus': 'BUS', + 'external': 'EXT', }) self.add_parameter('trigger_timer',