diff --git a/frappy_psi/lakeshore.py b/frappy_psi/lakeshore.py index 1b992271..11d6fc04 100644 --- a/frappy_psi/lakeshore.py +++ b/frappy_psi/lakeshore.py @@ -137,9 +137,8 @@ class Device(HasLscIO, Module): def initModule(self): self._to_delete = [] # curves to delete self._requests = {} # dict of CurveRequest - self._sensors = {} # dict of sensors - self._disable_channels = set(self.channels) - self._raw_channels = set() + self._sensors = {} # dict of sensors with calibration + self._all_sensors = {} # dict of sensors self._request_lock = threading.Lock() self.io.setProperty('model', self.model) super().initModule() @@ -172,7 +171,6 @@ class Device(HasLscIO, Module): self._requests[sensor.calcurve] = req else: self._requests[sensor.calcurve] = req - self._disable_channels.discard(sensor.channel) self.setFastPoll(True, self.FAST_POLL) def doPoll(self): @@ -210,13 +208,8 @@ class Device(HasLscIO, Module): return self.finish_curve(self._requests.pop(key)) # no more requests pending - self._disable_channels -= self._raw_channels - while self._disable_channels: - ch = self._disable_channels.pop() - sensor = self._sensors.get(ch) - if sensor is None or sensor.disabled: - self.disable_channel(ch) if self._to_delete: + self.log.info('to delete %r', self._to_delete) no = self._to_delete.pop(0) if self.curve_cache[no].key is None: self.command(f'CRVDEL {no}') @@ -228,6 +221,23 @@ class Device(HasLscIO, Module): if not self._requests: self.setFastPoll(False) + def initialReads(self): + super().initialReads() + self.log.info('all sens %r', self._all_sensors) + self.configure_display() + for ch in self.channels: + sensor = self._all_sensors.get(ch) + if sensor is None or not sensor.enabled: + self.log.info('sensor %r, enabled %r, ch %r', sensor, getattr(sensor, 'enabled', 0), ch) + self.disable_channel(ch) + + + def configure_display(self, disp_dict): + """Configure display + + disp_dict: dict of 1, 2, 3 (Kelvin, Celsius, raw)""" + pass + def read_status(self): status = IDLE, '' for req in self._requests.values(): @@ -486,8 +496,8 @@ class Device(HasLscIO, Module): def disable_channel(self, channel): self.command(f'INTYPE {channel},0') - def register_raw(self, sensor): - self._raw_channels.add(sensor.channel) + def register_sensor(self, sensor): + self._all_sensors[sensor.channel] = sensor class CurveRequest: @@ -632,6 +642,11 @@ class SensorBase(Base, Readable): _raw_error = None # TODO: implement alarms + def initModule(self): + if self.device: + self.device.register_sensor(self) + super().initModule() + def doPoll(self): self.read_status() # polls also value and raw @@ -670,11 +685,7 @@ class RawSensor(SensorBase): """class for sensors using raw value (w/o calibration curve)""" value = Parameter('raw value', unit='Ohm') _curve_handling = False - - def initModule(self): - if self.device: - self.device.register_raw(self) - super().initModule() + DISPLAY_UNIT = 3 # number as for DISPFLD command def get_internal_data(self): ch = self.channel @@ -701,6 +712,7 @@ class Sensor(SensorBase): calcurve = Parameter('calibration curve name', StringType(), readonly=False) curve_no = None _curve_handling = False # True when a device is present and device.curve_handling is True + DISPLAY_UNIT = 1 # number as for DISPFLD command # TODO: implement alarms def initModule(self): diff --git a/frappy_psi/lakeshore370.py b/frappy_psi/lakeshore370.py index 539395d5..99449465 100644 --- a/frappy_psi/lakeshore370.py +++ b/frappy_psi/lakeshore370.py @@ -92,6 +92,15 @@ class Device(ls.Device): self.command('MODE', mode) return self.read_remote_mode() + def configure_display(self): + self.command('DISPLAY', min(8, len(self._all_sensors)+1)) + for loc, (ch, sens) in enumerate(self._all_sensors.items(), 1): + if loc > 8: + return + self.command(f'DISPLOC {loc}', ch, sens.DISPLAY_UNIT, 6) # ch, loc, source, resolution (digits) + if loc < 8: + self.command(f'DISPLOC {loc+1}', 0, 2, 6) + class Switcher(ls.HasLscIO, ChannelSwitcher): device = Attached(Device) @@ -292,7 +301,7 @@ class SensorBase(Ls370, ls.SensorBase, Channel): def read_rdgrng(self): # rdgrng_params = 'range', 'iexc', 'vexc' iscur, exc, rng, autorange, excoff = self.query(f'RDGRNG?{self.channel}', int, int, int, int, int) - self.log.info('ch %r, rng %r', self.channel, rng) + # self.log.info('ch %r, rng %r', self.channel, rng) self._prev_rdgrng = iscur, exc if autorange and self.device.remote_mode == 'remote': # disable hardware autorange @@ -371,6 +380,7 @@ class SensorBase(Ls370, ls.SensorBase, Channel): class RawSensor(SensorBase, ls.RawSensor): + DISPLAY_UNIT = 2 # number as for DISPLOC command def get_internal_data(self): ch = self.channel