demo: fixup Switch class

Target and value are not emitting an update event upon changing target.

Change-Id: Ic01d17fd8529dc0b0a720fbc79d98c7a61fc572b
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30645
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
Reviewed-by: Georg Brandl <g.brandl@fz-juelich.de>
This commit is contained in:
Georg Brandl 2023-03-10 07:02:07 +01:00 committed by Markus Zolliker
parent c0704b3d4f
commit 9755040ac2

View File

@ -35,7 +35,8 @@ from frappy.properties import Property
class Parameter(SECoP_Parameter): class Parameter(SECoP_Parameter):
test = Property('A property for testing purposes', StringType(), default='', mandatory=False, extname='test') test = Property('A property for testing purposes', StringType(), default='',
mandatory=False, extname='test')
PERSIST = 101 PERSIST = 101
@ -62,7 +63,8 @@ class Switch(Drivable):
) )
description = Property('The description of the Module', StringType(), description = Property('The description of the Module', StringType(),
default='no description', mandatory=False, extname='description') default='no description', mandatory=False,
extname='description')
def read_value(self): def read_value(self):
# could ask HW # could ask HW
@ -70,22 +72,14 @@ class Switch(Drivable):
self._update() self._update()
return self.value return self.value
def read_target(self):
# could ask HW
return self.target
def write_target(self, value): def write_target(self, value):
# could tell HW # could tell HW
setattr(self, 'status', (self.Status.BUSY, 'switching %s' % value.name.upper())) self.status = (self.Status.BUSY, 'switching %s' % value.name.upper())
# note: setting self.target to the new value is done after this.... # note: setting self.target to the new value is done after this....
# note: we may also return the read-back value from the hw here
def read_status(self): def read_status(self):
self.log.info("read status") self._update()
info = self._update() return self.status
if self.target == self.value:
return self.Status.IDLE, ''
return self.Status.BUSY, info
def _update(self): def _update(self):
started = self.parameters['target'].timestamp started = self.parameters['target'].timestamp
@ -95,14 +89,15 @@ class Switch(Drivable):
if time.time() > started + self.switch_on_time: if time.time() > started + self.switch_on_time:
info = 'is switched ON' info = 'is switched ON'
self.value = self.target self.value = self.target
self.status = self.Status.IDLE, info
elif self.target < self.value: elif self.target < self.value:
info = 'waiting for OFF' info = 'waiting for OFF'
if time.time() > started + self.switch_off_time: if time.time() > started + self.switch_off_time:
info = 'is switched OFF' info = 'is switched OFF'
self.value = self.target self.value = self.target
self.status = self.Status.IDLE, info
if info: if info:
self.log.info(info) self.log.info(info)
return info
class MagneticField(Drivable): class MagneticField(Drivable):