From e8ec9b415a2461569fc8ad2a4f49739c85ed871a Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 26 Nov 2024 13:40:13 +0100 Subject: [PATCH] improve lakeshore demo use super call for read_status TODO: update tutorial! Change-Id: I2dd5631908dc370c6e6286587099e25a0e5ee867 --- frappy_demo/lakeshore.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/frappy_demo/lakeshore.py b/frappy_demo/lakeshore.py index 9b9fe8e..133b694 100644 --- a/frappy_demo/lakeshore.py +++ b/frappy_demo/lakeshore.py @@ -69,14 +69,16 @@ class TemperatureLoop(TemperatureSensor, Drivable): # lakeshore loop number to be used for this module loop = Property('lakeshore loop', IntRange(1, 2), default=1) target = Parameter(datatype=FloatRange(unit='K', min=0, max=1500)) - heater_range = Property('heater power range', IntRange(0, 5)) # max. 3 on LakeShore 336 + heater_range = Property('heater power range', IntRange(0, 3), readonly=False) tolerance = Parameter('convergence criterion', FloatRange(0), default=0.1, readonly=False) _driving = False + def write_heater_range(self, value): + self.communicate(f'RANGE {self.loop},{value};RANGE?{self.loop}') + def write_target(self, target): # reactivate heater in case it was switched off - # the command has to be changed in case of model 340 to f'RANGE {self.heater_range};RANGE?' - self.communicate(f'RANGE {self.loop},{self.heater_range};RANGE?{self.loop}') + self.write_heater_range(self.heater_range) self.communicate(f'SETP {self.loop},{target};*OPC?') self._driving = True # Setting the status attribute triggers an update message for the SECoP status @@ -85,23 +87,21 @@ class TemperatureLoop(TemperatureSensor, Drivable): return target def read_status(self): - code = int(self.communicate(f'RDGST?{self.channel}')) - if code >= 128: - text = 'units overrange' - elif code >= 64: - text = 'units zero' - elif code >= 32: - text = 'temperature overrange' - elif code >= 16: - text = 'temperature underrange' - elif code % 2: - # ignore 'old reading', as this may happen in normal operation - text = 'invalid reading' - elif abs(self.target - self.value) > self.tolerance: + status = super().read_status() + if status[0] == ERROR: + return status + if abs(self.target - self.value) > self.tolerance: if self._driving: return BUSY, 'approaching setpoint' return WARN, 'temperature out of tolerance' - else: # within tolerance: simple convergence criterion - self._driving = False - return IDLE, '' - return ERROR, text + # within tolerance: simple convergence criterion + self._driving = False + return IDLE, '' + + +class TemperatureLoop340(TemperatureLoop): + # slightly different behaviour for model 340 + heater_range = Property('heater power range', IntRange(0, 5)) + + def write_heater_range(self, value): + self.communicate(f'RANGE {value};RANGE?')