From 69dd011260d445c22bb66cf860680e5810f53db9 Mon Sep 17 00:00:00 2001 From: Oksana Shliakhtun Date: Thu, 2 Feb 2023 17:22:08 +0100 Subject: [PATCH] Added alarms Change-Id: Idd06278e44e01522ddf904b56a452ce8c704b5a6 --- cfg/ls340_cfg.py | 1 + frappy_psi/lakeshore.py | 37 ++++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/cfg/ls340_cfg.py b/cfg/ls340_cfg.py index edcfcf0..c42833a 100644 --- a/cfg/ls340_cfg.py +++ b/cfg/ls340_cfg.py @@ -2,6 +2,7 @@ Node('ls340test.psi.ch', 'ls340 test', 'tcp://5000', ) + Mod('io', 'frappy_psi.lakeshore.Ls340IO', 'communication to ls340', diff --git a/frappy_psi/lakeshore.py b/frappy_psi/lakeshore.py index e27b0eb..17d3f24 100644 --- a/frappy_psi/lakeshore.py +++ b/frappy_psi/lakeshore.py @@ -22,7 +22,8 @@ from math import log2 from frappy.core import Readable, Parameter, IntRange, EnumType, FloatRange, \ StringIO, HasIO, StringType, Property, Writable, Drivable, IDLE, ERROR, \ - Attached, StructOf + Attached, StructOf, WARN + from frappy_psi.mixins import HasOutputModule, HasControlledBy @@ -45,14 +46,16 @@ class LakeShore(HasIO): return [float(num) for num in reply.split(',')] -class Sensor340(HasIO, Readable): +class Sensor340(LakeShore, Readable): """A channel of 340TC""" # define the communication class to create the IO module ioClass = Ls340IO - channel = Property('lakeshore channel', StringType()) - # define or alter the parameters + # relay_mode = Property('relay setting mode', IntRange(0, 2)) + # relay = Property('relay high/low', IntRange(1, 2)) + alarm = Parameter('alarm limits', FloatRange(unit='K'), readonly=False) + # # define or alter the parameters # as Readable.value exists already, we give only the modified property 'unit' value = Parameter(unit='K') @@ -70,18 +73,27 @@ class Sensor340(HasIO, Readable): return ERROR, 'temperature overrange' if c >= 16: return ERROR, 'temperature underrange' - # do not check for old reading -> this happens regularely on NTCs with T comp + # do not check for old reading -> this happens regularly on NTCs with T comp if c % 2: return ERROR, 'invalid reading' + # ask for high alarm status and return warning + if '1' in str(self.communicate(f'ALARMST? {self.channel}')): + return Warning return IDLE, '' + def write_alarm(self): + return self.set_par(f'ALARM {self.channel}, 1, 1, {self.alarm}, 0, 0, 2') + + def read_alarm(self): + return self.get_par(f'ALARM? {self.channel}')[0] + class HeaterOutput(LakeShore, HasControlledBy, HasIO, Writable): - loop = Property('lakeshore loop', IntRange(1, 2), default=1) - channel = Property('attached channel', StringType()) max_power = Parameter('max heater power', datatype=FloatRange(0, 100), unit='W', readonly=False) value = Parameter('heater output', datatype=FloatRange(0, 100), unit='W') target = Parameter('manual heater output', datatype=FloatRange(0, 100), unit='W') + loop = Property('lakeshore loop', IntRange(1, 2), default=1) + channel = Property('attached channel', StringType()) resistance = Property('heater resistance', datatype=FloatRange(10, 1000)) current = Property('heater current', datatype=FloatRange(0, 2)) _range = 0 @@ -120,7 +132,8 @@ class HeaterOutput(LakeShore, HasControlledBy, HasIO, Writable): self._range = irange self.communicate(f'CLIMIT {self.loop},{self.SETPOINTLIMS},0,0,{icurrent},{irange};' f'RANGE {irange};' - f'CDISP {self.loop},1,{self.resistance},0;RANGE?') + f'CDISP {self.loop},1,{self.resistance},0;RANGE?;' + f'RELAY? 1') #only high relay return self.read_max_power() def read_max_power(self): @@ -142,9 +155,6 @@ class HeaterOutput(LakeShore, HasControlledBy, HasIO, Writable): def power_to_percent(self, power): return (power / self._max_power) ** (1 / 2) * 100 # limit - def read_value(self): - return self.percent_to_power(float(self.communicate(f'HTR?'))) - def read_status(self): return self.STATUS_MAP[int(self.communicate(f'HTRST?'))] @@ -162,6 +172,9 @@ class HeaterOutput(LakeShore, HasControlledBy, HasIO, Writable): f'CMODE {self.loop}, {int(mode)};' f'RANGE?') + def read_value(self): + return self.percent_to_power(float(self.communicate(f'HTR?'))) + class TemperatureLoop340(HasOutputModule, Sensor340, Drivable, LakeShore): target = Parameter(unit='K') @@ -196,3 +209,5 @@ class TemperatureLoop340(HasOutputModule, Sensor340, Drivable, LakeShore): + +