Skip to content
Snippets Groups Projects
Commit 8da4a961 authored by Claudio Scafuri's avatar Claudio Scafuri :speech_balloon:
Browse files

create dynamic attributes with MagnetNames property

parent f8ddcc7b
No related branches found
No related tags found
No related merge requests found
Pipeline #2117 passed with warnings with stage
- add the possibilty of creating many dynamic attributes with a simple configuration Useful for handling the whole simulator with a single server, like in the real case - configure the MagnetNames property with real E2.0 magnet (sextupole) names
- usro un dictiory (map) per salvare i valor accanto al nome dell' attributo.
Useroò un poroerty per la lista dei nomi degli attributi
...@@ -23,6 +23,7 @@ from tango import DebugIt ...@@ -23,6 +23,7 @@ from tango import DebugIt
from tango.server import run from tango.server import run
from tango.server import Device from tango.server import Device
from tango.server import attribute, command from tango.server import attribute, command
from tango.server import device_property
from tango import AttrQuality, DispLevel, DevState from tango import AttrQuality, DispLevel, DevState
from tango import AttrWriteType, PipeWriteType from tango import AttrWriteType, PipeWriteType
# Additional import # Additional import
...@@ -36,15 +37,50 @@ class Simulatede2BbaSwitch(Device): ...@@ -36,15 +37,50 @@ class Simulatede2BbaSwitch(Device):
""" """
Simple boolen r/w variable. Simple boolen r/w variable.
The real thing will be a boolen attribute expoter by the Tango MPS interface The real thing will be a boolen attribute expoter by the Tango MPS interface
**Properties:**
- Device Property
MagnetNames
- name of magnets with a BBA switch
- Type:'DevVarStringArray'
""" """
# PROTECTED REGION ID(Simulatede2BbaSwitch.class_variable) ENABLED START # # PROTECTED REGION ID(Simulatede2BbaSwitch.class_variable) ENABLED START #
def add_attr(self, name):
attr = tango.Attr(name, tango.DevBoolean, tango.READ_WRITE)
self.add_attribute(attr, self.read_general, self.write_general)
self._dynamic_attrs[name] = False
dev_m_attr = self.get_device_attr()
wattr = dev_m_attr.get_w_attr_by_name(name)
wattr.set_write_value(False)
def read_general(self, attr):
name = attr.get_name()
self.debug_stream("Reading attribute %s", name)
attr.set_value(self._dynamic_attrs[name])
def write_general(self, attr):
name = attr.get_name()
data = attr.get_write_value()
self._dynamic_attrs[name] = data
self.debug_stream("Writing into attribute %s the value %s", name, data)
# PROTECTED REGION END # // Simulatede2BbaSwitch.class_variable # PROTECTED REGION END # // Simulatede2BbaSwitch.class_variable
# -----------------
# Device Properties
# -----------------
MagnetNames = device_property(
dtype='DevVarStringArray',
doc="name of magnets with a BBA switch",
mandatory=True
)
# ---------- # ----------
# Attributes # Attributes
# ---------- # ----------
enable = attribute( generic = attribute(
dtype='DevBoolean', dtype='DevBoolean',
access=AttrWriteType.READ_WRITE, access=AttrWriteType.READ_WRITE,
label="bba enable", label="bba enable",
...@@ -58,13 +94,20 @@ class Simulatede2BbaSwitch(Device): ...@@ -58,13 +94,20 @@ class Simulatede2BbaSwitch(Device):
def init_device(self): def init_device(self):
"""Initializes the attributes and properties of the Simulatede2BbaSwitch.""" """Initializes the attributes and properties of the Simulatede2BbaSwitch."""
Device.init_device(self) Device.init_device(self)
self._enable = False self._generic = False
# PROTECTED REGION ID(Simulatede2BbaSwitch.init_device) ENABLED START # # PROTECTED REGION ID(Simulatede2BbaSwitch.init_device) ENABLED START #
dev_m_attr = self.get_device_attr() dev_m_attr = self.get_device_attr()
wattr = dev_m_attr.get_w_attr_by_name("enable") wattr = dev_m_attr.get_w_attr_by_name("generic")
wattr.set_write_value(False) wattr.set_write_value(False)
self.set_state(tango.DevState.ON) self.set_state(tango.DevState.ON)
self.set_status("MPS BBA switches ready") self.set_status("MPS BBA switches ready")
# add dyn attributes
self._dynamic_attrs = {}
for magname in self.MagnetNames:
self.add_attr(magname)
# PROTECTED REGION END # // Simulatede2BbaSwitch.init_device # PROTECTED REGION END # // Simulatede2BbaSwitch.init_device
def always_executed_hook(self): def always_executed_hook(self):
...@@ -86,16 +129,16 @@ class Simulatede2BbaSwitch(Device): ...@@ -86,16 +129,16 @@ class Simulatede2BbaSwitch(Device):
# Attributes methods # Attributes methods
# ------------------ # ------------------
def read_enable(self): def read_generic(self):
# PROTECTED REGION ID(Simulatede2BbaSwitch.enable_read) ENABLED START # # PROTECTED REGION ID(Simulatede2BbaSwitch.generic_read) ENABLED START #
"""Return the enable attribute.""" """Return the generic attribute."""
return self._enable return self._generic
# PROTECTED REGION END # // Simulatede2BbaSwitch.enable_read # PROTECTED REGION END # // Simulatede2BbaSwitch.generic_read
def write_enable(self, value): def write_generic(self, value):
# PROTECTED REGION ID(Simulatede2BbaSwitch.enable_write) ENABLED START # # PROTECTED REGION ID(Simulatede2BbaSwitch.generic_write) ENABLED START #
"""Set the enable attribute.""" """Set the generic attribute."""
self._enable = value pass
# PROTECTED REGION END # // Simulatede2BbaSwitch.enable_write # PROTECTED REGION END # // Simulatede2BbaSwitch.generic_write
# -------- # --------
# Commands # Commands
# -------- # --------
......
<?xml version="1.0" encoding="ASCII"?> <?xml version="1.0" encoding="ASCII"?>
<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://tango.org/pogo/PogoDsl"> <pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://tango.org/pogo/PogoDsl">
<classes name="Simulatede2BbaSwitch" pogoRevision="9.9"> <classes name="Simulatede2BbaSwitch" pogoRevision="9.9">
<description description="Simple boolen r/w variable.&#xA;The real thing will be a boolen attribute expoter by the Tango MPS interface" title="Simulatede2BbaSwitch" sourcePath="/home/claudio/src/gitlab/dt/ds/simulatede2bbaswitch/src" language="PythonHL" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="Elettra - Sincrotrone Trieste S.C.p.A." hasMandatoryProperty="false" hasConcreteProperty="false" hasAbstractCommand="false" hasAbstractAttribute="false"> <description description="Simple boolen r/w variable.&#xA;The real thing will be a boolen attribute expoter by the Tango MPS interface" title="Simulatede2BbaSwitch" sourcePath="/home/claudio/src/gitlab/dt/ds/simulatede2bbaswitch/src" language="PythonHL" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="Elettra - Sincrotrone Trieste S.C.p.A." hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/> <inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at elettra.eu - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.eu" classFamily="Simulators" siteSpecific="" platform="All Platforms" bus="Not Applicable" manufacturer="none" reference=""> <identification contact="at elettra.eu - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.eu" classFamily="Simulators" siteSpecific="" platform="All Platforms" bus="Not Applicable" manufacturer="none" reference="">
<keyWords>simulator</keyWords> <keyWords>simulator</keyWords>
<keyWords>Eelttra 2.0</keyWords> <keyWords>Eelttra 2.0</keyWords>
</identification> </identification>
</description> </description>
<deviceProperties name="MagnetNames" mandatory="true" description="name of magnets with a BBA switch">
<type xsi:type="pogoDsl:StringVectorType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0"> <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0">
<argin description="none"> <argin description="none">
<type xsi:type="pogoDsl:VoidType"/> <type xsi:type="pogoDsl:VoidType"/>
...@@ -26,7 +30,7 @@ ...@@ -26,7 +30,7 @@
</argout> </argout>
<status abstract="true" inherited="true" concrete="true"/> <status abstract="true" inherited="true" concrete="true"/>
</commands> </commands>
<attributes name="enable" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> <attributes name="generic" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:BooleanType"/> <dataType xsi:type="pogoDsl:BooleanType"/>
<changeEvent fire="false" libCheckCriteria="false"/> <changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/> <archiveEvent fire="false" libCheckCriteria="false"/>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment