MLZ: Fix mapping in NamedDigitalOutput device

Change-Id: Iaef2c4672eb3eceeaba2ec5750f964864ce76aa9
Reviewed-on: https://forge.frm2.tum.de/review/17733
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
This commit is contained in:
Enrico Faulhaber
2018-04-16 13:17:43 +02:00
parent f54e8ccb45
commit b7ab6036e5

View File

@ -27,6 +27,7 @@
Here we support devices which fulfill the official Here we support devices which fulfill the official
MLZ TANGO interface for the respective device classes. MLZ TANGO interface for the respective device classes.
""" """
from __future__ import division
import re import re
from time import sleep, time as currenttime from time import sleep, time as currenttime
@ -397,10 +398,9 @@ class Sensor(AnalogInput):
# we support the adjust method # we support the adjust method
commands = { commands = {
'setposition' : Command('Set the position to the given value.', 'setposition': Command('Set the position to the given value.',
arguments=[FloatRange()], arguments=[FloatRange()], result=None,
result=None ),
),
} }
def do_setposition(self, value): def do_setposition(self, value):
@ -422,22 +422,22 @@ class AnalogOutput(PyTangoDevice, Drivable):
parameters = { parameters = {
'userlimits': Param('User defined limits of device value', 'userlimits': Param('User defined limits of device value',
datatype=TupleOf(FloatRange(), FloatRange()), datatype=TupleOf(FloatRange(), FloatRange()),
default=(float('-Inf'),float('+Inf')), default=(float('-Inf'), float('+Inf')),
unit='main', readonly=False, poll=10, unit='main', readonly=False, poll=10,
), ),
'abslimits': Param('Absolute limits of device value', 'abslimits': Param('Absolute limits of device value',
datatype=TupleOf(FloatRange(), FloatRange()), datatype=TupleOf(FloatRange(), FloatRange()),
unit='main', unit='main',
), ),
'precision': Param('Precision of the device value (allowed deviation ' 'precision': Param('Precision of the device value (allowed deviation '
'of stable values from target)', 'of stable values from target)',
unit='main', datatype=FloatRange(1e-38), unit='main', datatype=FloatRange(1e-38),
readonly=False, readonly=False,
), ),
'window': Param('Time window for checking stabilization if > 0', 'window': Param('Time window for checking stabilization if > 0',
unit='s', default=60.0, readonly=False, unit='s', default=60.0, readonly=False,
datatype=FloatRange(0, 900), datatype=FloatRange(0, 900),
), ),
} }
def init(self): def init(self):
@ -557,18 +557,17 @@ class Actuator(AnalogOutput):
parameters = { parameters = {
'speed': Param('The speed of changing the value', 'speed': Param('The speed of changing the value',
unit='main/s', readonly=False, datatype=FloatRange(0), unit='main/s', readonly=False, datatype=FloatRange(0),
), ),
'ramp': Param('The speed of changing the value', 'ramp': Param('The speed of changing the value',
unit='main/min', readonly=False, datatype=FloatRange(0), unit='main/min', readonly=False, datatype=FloatRange(0),
poll=30, poll=30,
), ),
} }
commands = { commands = {
'setposition' : Command('Set the position to the given value.', 'setposition': Command('Set the position to the given value.',
arguments=[FloatRange()], arguments=[FloatRange()], result=None,
result=None ),
),
} }
def read_speed(self, maxage=0): def read_speed(self, maxage=0):
@ -598,13 +597,13 @@ class Motor(Actuator):
parameters = { parameters = {
'refpos': Param('Reference position', 'refpos': Param('Reference position',
datatype=FloatRange(), unit='main', datatype=FloatRange(), unit='main',
), ),
'accel': Param('Acceleration', 'accel': Param('Acceleration',
datatype=FloatRange(), readonly=False, unit='main/s^2', datatype=FloatRange(), readonly=False, unit='main/s^2',
), ),
'decel': Param('Deceleration', 'decel': Param('Deceleration',
datatype=FloatRange(), readonly=False, unit='main/s^2', datatype=FloatRange(), readonly=False, unit='main/s^2',
), ),
} }
def read_refpos(self, maxage=0): def read_refpos(self, maxage=0):
@ -814,17 +813,20 @@ class NamedDigitalOutput(DigitalOutput):
"""A DigitalOutput with numeric values mapped to names. """A DigitalOutput with numeric values mapped to names.
""" """
# parameters = { parameters = {
# 'mapping': Param('A dictionary mapping state names to integers', 'mapping': Param('A dictionary mapping state names to integers',
# datatype=EnumType(), export=False), # XXX: !!! datatype=StringType(), export=False),
# } }
#
# def init(self): def init(self):
# super(NamedDigitalOutput, self).init() super(NamedDigitalOutput, self).init()
# try: # XXX: !!! try:
# self.parameters['value'].datatype = EnumType(**eval(self.mapping)) # pylint: disable=eval-used
# except Exception as e: self.parameters['value'].datatype = EnumType(**eval(self.mapping))
# raise ValueError('Illegal Value for mapping: %r' % e) # pylint: disable=eval-used
self.parameters['target'].datatype = EnumType(**eval(self.mapping))
except Exception as e:
raise ValueError('Illegal Value for mapping: %r' % e)
def write_target(self, value): def write_target(self, value):
# map from enum-str to integer value # map from enum-str to integer value
@ -919,8 +921,8 @@ class StringIO(PyTangoDevice, Module):
arguments=[], result=IntRange(0)), arguments=[], result=IntRange(0)),
'multicommunicate': Command('perform a sequence of communications', 'multicommunicate': Command('perform a sequence of communications',
arguments=[ArrayOf( arguments=[ArrayOf(
TupleOf(StringType(), IntRange()),100)], TupleOf(StringType(), IntRange()), 100)],
result=ArrayOf(StringType(),100)), result=ArrayOf(StringType(), 100)),
} }
def do_communicate(self, value=StringType()): def do_communicate(self, value=StringType()):