diff --git a/qcodes/instrument/parameter.py b/qcodes/instrument/parameter.py index 8d4fe186a05..cb84e287588 100644 --- a/qcodes/instrument/parameter.py +++ b/qcodes/instrument/parameter.py @@ -178,7 +178,7 @@ def __init__(self, name, instrument, snapshot_get=True, metadata=None, # record of latest value and when it was set or measured # what exactly this means is different for different subclasses # but they all use the same attributes so snapshot is consistent. - self._latest = {'value': None, 'ts': None} + self._latest = {'value': None, 'ts': None, 'raw_value': None} self.get_latest = GetLatest(self, max_val_age=max_val_age) if hasattr(self, 'get'): @@ -188,7 +188,7 @@ def __init__(self, name, instrument, snapshot_get=True, metadata=None, # subclasses should extend this list with extra attributes they # want automatically included in the snapshot - self._meta_attrs = ['name', 'instrument', 'step', 'scale', 'raw_value', + self._meta_attrs = ['name', 'instrument', 'step', 'scale', 'inter_delay', 'post_delay', 'val_mapping', 'vals'] # Specify time of last set operation, used when comparing to delay to @@ -243,6 +243,7 @@ def snapshot_base(self, update=False): if not self._snapshot_value: state.pop('value') + state.pop('raw_value', None) if isinstance(state['ts'], datetime): state['ts'] = state['ts'].strftime('%Y-%m-%d %H:%M:%S') @@ -267,7 +268,8 @@ def snapshot_base(self, update=False): def _save_val(self, value, validate=False): if validate: self.validate(value) - self._latest = {'value': value, 'ts': datetime.now()} + self._latest = {'value': value, 'ts': datetime.now(), + 'raw_value': self.raw_value} def _wrap_get(self, get_function): @wraps(get_function) @@ -347,8 +349,13 @@ def set_wrapper(value, **kwargs): set_function(val, **kwargs) self.raw_value = val - self._save_val(val, validate=(self.val_mapping is None and - self.set_parser is None)) + if self.scale is not None: + scaled_val = val / self.scale + else: + scaled_val = val + self._save_val(scaled_val, + validate=(self.val_mapping is None and + self.set_parser is None)) # Update last set time (used for calculating delays) self._t_last_set = time.perf_counter() @@ -379,7 +386,9 @@ def get_ramp_values(self, value, step=None): if step is None: return [value] else: - start_value = self.get_latest() + if self.get_latest() is None: + self.get() + start_value = self.raw_value self.validate(start_value) @@ -647,7 +656,8 @@ def __init__(self, name, instrument=None, label=None, unit=None, if max_val_age is not None: raise SyntaxError('Must have get method or specify get_cmd ' 'when max_val_age is set') - self.get = self.get_latest + self.get = lambda: self._latest['value' if self.scale is None + else 'raw_value'] else: exec_str = instrument.ask if instrument else None self.get = Command(arg_count=0, cmd=get_cmd, exec_str=exec_str) @@ -667,7 +677,7 @@ def __init__(self, name, instrument=None, label=None, unit=None, self.unit = unit if unit is not None else '' if initial_value is not None: - self._save_val(initial_value, validate=True) + self.set(initial_value) # generate default docstring self.__doc__ = os.linesep.join((