rework property handling
+ DataType validators are shifted to __call__ + as_json is moved to export_datatape() + new HasProperties Base Mixin for Modules/DataTypes + accessibles can be accessed via iterator of a module + properties are properly 'derived' and checked, are set with .setPropertyValue remember: parameters only have properties, so use getPropertyValue() Change-Id: Iae0273f971aacb00fe6bf05e6a4d24a6d1be881a Reviewed-on: https://forge.frm2.tum.de/review/20635 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
@ -26,17 +26,20 @@ import random
|
||||
import time
|
||||
from math import atan
|
||||
|
||||
from secop.datatypes import EnumType, FloatRange, TupleOf
|
||||
from secop.datatypes import EnumType, FloatRange, TupleOf, StringType, BoolType
|
||||
from secop.lib import clamp, mkthread
|
||||
from secop.modules import Command, Drivable, Override, Parameter
|
||||
from secop.modules import Drivable, Override, Parameter
|
||||
|
||||
# test custom property (value.test can be changed in config file)
|
||||
Parameter.add_property('test')
|
||||
# in the rare case of namespace conflicts, the external name could be completely different
|
||||
Command.add_property(special='_peculiar')
|
||||
from secop.properties import Property
|
||||
|
||||
Parameter.properties['test'] = Property(StringType(), default='', export=True)
|
||||
|
||||
|
||||
class CryoBase(Drivable):
|
||||
pass
|
||||
properties = {
|
||||
'is_cryo': Property(BoolType(), default=True, export=True),
|
||||
}
|
||||
|
||||
|
||||
class Cryostat(CryoBase):
|
||||
|
@ -29,9 +29,17 @@ import time
|
||||
from secop.datatypes import ArrayOf, BoolType, EnumType, \
|
||||
FloatRange, IntRange, StringType, StructOf, TupleOf
|
||||
from secop.lib.enum import Enum
|
||||
from secop.modules import Drivable, Override, Parameter, Readable
|
||||
from secop.modules import Drivable, Override, Parameter as SECoP_Parameter, Readable
|
||||
from secop.properties import Property
|
||||
|
||||
|
||||
class Parameter(SECoP_Parameter):
|
||||
properties = {
|
||||
'test' : Property(StringType(), default='', mandatory=False, extname='test'),
|
||||
}
|
||||
|
||||
PERSIST = 101
|
||||
|
||||
class Switch(Drivable):
|
||||
"""switch it on or off....
|
||||
"""
|
||||
@ -53,6 +61,10 @@ class Switch(Drivable):
|
||||
),
|
||||
}
|
||||
|
||||
properties = {
|
||||
'description' : Property(StringType(), default='no description', mandatory=False, extname='description'),
|
||||
}
|
||||
|
||||
def read_value(self):
|
||||
# could ask HW
|
||||
# we just return the value of the target here.
|
||||
@ -117,7 +129,7 @@ class MagneticField(Drivable):
|
||||
datatype=StringType(), export=False,
|
||||
),
|
||||
}
|
||||
Status = Enum(Drivable.Status, PERSIST=101, PREPARE=301, RAMPING=302, FINISH=303)
|
||||
Status = Enum(Drivable.Status, PERSIST=PERSIST, PREPARE=301, RAMPING=302, FINISH=303)
|
||||
overrides = {
|
||||
'status' : Override(datatype=TupleOf(EnumType(Status), StringType())),
|
||||
}
|
||||
@ -141,7 +153,7 @@ class MagneticField(Drivable):
|
||||
|
||||
def read_status(self):
|
||||
if self._state == self._state.enum.idle:
|
||||
return (self.Status.PERSIST, 'at field') if self.value else \
|
||||
return (PERSIST, 'at field') if self.value else \
|
||||
(self.Status.IDLE, 'zero field')
|
||||
elif self._state == self._state.enum.switch_on:
|
||||
return (self.Status.PREPARE, self._state.name)
|
||||
@ -262,16 +274,16 @@ class Label(Readable):
|
||||
"""
|
||||
parameters = {
|
||||
'system': Parameter("Name of the magnet system",
|
||||
datatype=StringType, export=False,
|
||||
datatype=StringType(), export=False,
|
||||
),
|
||||
'subdev_mf': Parameter("name of subdevice for magnet status",
|
||||
datatype=StringType, export=False,
|
||||
datatype=StringType(), export=False,
|
||||
),
|
||||
'subdev_ts': Parameter("name of subdevice for sample temp",
|
||||
datatype=StringType, export=False,
|
||||
datatype=StringType(), export=False,
|
||||
),
|
||||
'value': Override("final value of label string", default='',
|
||||
datatype=StringType,
|
||||
datatype=StringType(),
|
||||
),
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import random
|
||||
|
||||
from secop.datatypes import FloatRange, StringType
|
||||
from secop.modules import Communicator, Drivable, Parameter, Readable, Override
|
||||
from secop.params import Command
|
||||
|
||||
try:
|
||||
# py2
|
||||
@ -99,5 +100,8 @@ class Temp(Drivable):
|
||||
|
||||
class Lower(Communicator):
|
||||
"""Communicator returning a lowercase version of the request"""
|
||||
command = {
|
||||
'communicate': Command('lowercase a string', StringType(), StringType(), export='communicate'),
|
||||
}
|
||||
def do_communicate(self, request):
|
||||
return unicode(request).lower()
|
||||
|
Reference in New Issue
Block a user