make entangle mapping a dict

Change-Id: I38d863a907469674001f0721140f88c17b53635b
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30911
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
This commit is contained in:
Alexander Zaft 2023-03-23 07:09:15 +01:00 committed by Markus Zolliker
parent a334cc4f0a
commit d18e368ab9
4 changed files with 37 additions and 34 deletions

View File

@ -13,14 +13,14 @@ Mod('automatik',
'\n'
'selects between off, regulate on p1 or regulate on p2 sensor',
tangodevice = 'tango://localhost:10000/box/plc/_automatik',
mapping="{'Off':0,'p1':1,'p2':2}",
mapping={'Off':0,'p1':1,'p2':2},
)
Mod('compressor',
'frappy_mlz.entangle.NamedDigitalOutput',
'control the compressor (on/off)',
tangodevice = 'tango://localhost:10000/box/plc/_cooler_onoff',
mapping="{'Off':0,'On':1}",
mapping={'Off':0,'On':1},
)
Mod('gas',
@ -31,7 +31,7 @@ Mod('gas',
'note: activation de-activates the vacuum inlet\n'
'note: if the pressure regulation is active, it enslave this device',
tangodevice = 'tango://localhost:10000/box/plc/_gas_onoff',
mapping="{'Off':0,'On':1}",
mapping={'Off':0,'On':1},
)
Mod('vacuum',
@ -41,7 +41,7 @@ Mod('vacuum',
'note: activation de-activates the gas inlet\n'
'note: if the pressure regulation is active, it enslave this device',
tangodevice = 'tango://localhost:10000/box/plc/_vacuum_onoff',
mapping="{'Off':0,'On':1}",
mapping={'Off':0,'On':1},
)
Mod('p1',
@ -63,14 +63,14 @@ Mod('curve_p2',
'calibration curve for pressure sensor 2',
tangodevice = 'tango://localhost:10000/box/plc/_curve',
value = 0,
mapping = "{'0-10V':0, '0-1000mbar':1, '1-9V to 0-1 mbar':2, \
'DI200':3, 'DI2000':4, 'TTR100':7, 'PTR90':8, \
'PTR225/237':9, 'ITR90':10, 'ITR100-D':11, \
'ITR100-2':12, 'ITR100-3':13, 'ITR100-4':14, \
'ITR100-5':15, 'ITR100-6':16, 'ITR100-7':17, \
'ITR100-8':18, 'ITR100-9':19, 'ITR100-A':20, \
'CMR361':21, 'CMR362':22, 'CMR363':23, \
'CMR364':24, 'CMR365':25}",
mapping = {'0-10V':0, '0-1000mbar':1, '1-9V to 0-1 mbar':2,
'DI200':3, 'DI2000':4, 'TTR100':7, 'PTR90':8,
'PTR225/237':9, 'ITR90':10, 'ITR100-D':11,
'ITR100-2':12, 'ITR100-3':13, 'ITR100-4':14,
'ITR100-5':15, 'ITR100-6':16, 'ITR100-7':17,
'ITR100-8':18, 'ITR100-9':19, 'ITR100-A':20,
'CMR361':21, 'CMR362':22, 'CMR363':23,
'CMR364':24, 'CMR365':25},
)
Mod('T_tube_regulation',
@ -137,12 +137,12 @@ Mod('T_tube_regulation_heaterrange',
'frappy_mlz.entangle.NamedDigitalOutput',
'heaterrange for tube regulation',
tangodevice = 'tango://localhost:10000/box/tube/range1',
mapping="{'Off':0,'Low':1,'Medium':2, 'High':3}",
mapping={'Off':0,'Low':1,'Medium':2, 'High':3},
)
Mod('T_stick_regulation_heaterrange',
'frappy_mlz.entangle.NamedDigitalOutput',
'heaterrange for stick regulation',
tangodevice = 'tango://localhost:10000/box/stick/range2',
mapping="{'Off':0,'Low':1,'Medium':2, 'High':3}",
mapping={'Off':0,'Low':1,'Medium':2, 'High':3},
)

View File

@ -44,3 +44,10 @@ Mod('Lower',
'frappy_demo.test.Lower',
'something else',
)
Mod('Decision',
'frappy_demo.test.Mapped',
'Random value from configured property choices. Config accepts anything ' \
'that can be converted to a list',
choices = ['Yes', 'Maybe', 'No'],
)

View File

@ -23,8 +23,9 @@
import random
from frappy.datatypes import FloatRange, StringType
from frappy.modules import Communicator, Drivable, Parameter, Readable
from frappy.datatypes import FloatRange, StringType, ValueType
from frappy.modules import Communicator, Drivable, Parameter, Property, \
Readable
from frappy.params import Command
@ -93,3 +94,10 @@ class Lower(Communicator):
def communicate(self, command):
"""lowercase a string"""
return str(command).lower()
class Mapped(Readable):
value = Parameter(datatype=StringType())
choices = Property('List of choices',
datatype=ValueType(list))
def read_value(self):
return self.choices[random.randrange(len(self.choices))]

View File

@ -37,12 +37,12 @@ from time import sleep, time as currenttime
import PyTango
from frappy.datatypes import ArrayOf, EnumType, FloatRange, IntRange, \
LimitsType, StringType, TupleOf
LimitsType, StringType, TupleOf, ValueType
from frappy.errors import CommunicationFailedError, ConfigError, \
HardwareError, ProgrammingError
from frappy.lib import lazy_property
from frappy.modules import Command, Drivable, Module, Parameter, Readable, \
StatusType, Writable
StatusType, Writable, Property
#####
@ -812,19 +812,13 @@ class NamedDigitalInput(DigitalInput):
"""
# parameters
mapping = Parameter('A dictionary mapping state names to integers',
datatype=StringType(), export=False) # XXX:!!!
mapping = Property('A dictionary mapping state names to integers',
datatype=ValueType(dict))
def initModule(self):
super().initModule()
try:
mapping = self.mapping
if isinstance(mapping, str):
# pylint: disable=eval-used
mapping = eval(self.mapping.replace('\n', ' '))
if isinstance(mapping, str):
# pylint: disable=eval-used
mapping = eval(mapping)
self.accessibles['value'].setProperty('datatype', EnumType('value', **mapping))
except Exception as e:
raise ValueError(f'Illegal Value for mapping: {self.mapping!r}') from e
@ -889,19 +883,13 @@ class NamedDigitalOutput(DigitalOutput):
"""
# parameters
mapping = Parameter('A dictionary mapping state names to integers',
datatype=StringType(), export=False)
mapping = Property('A dictionary mapping state names to integers',
datatype=ValueType(dict))
def initModule(self):
super().initModule()
try:
mapping = self.mapping
if isinstance(mapping, str):
# pylint: disable=eval-used
mapping = eval(self.mapping.replace('\n', ' '))
if isinstance(mapping, str):
# pylint: disable=eval-used
mapping = eval(mapping)
self.accessibles['value'].setProperty('datatype', EnumType('value', **mapping))
self.accessibles['target'].setProperty('datatype', EnumType('target', **mapping))
except Exception as e: