How can we delete a dynamic attribute in a DS written in python? Is there any api in PyTango?
I need to create an attribute on a particular condition and delete it as the condition goes away. I could create dynamic attributes on the conditions but I did not find a way to delete them. Kindly help!
Thank you so much. I could delete the dynamic attribute whenever my processing was done.
However, I am facing problem in updating/writing the attribute during processing.
I have created an attribute as follows:
def write_general(self, attr):
name = attr.get_name()
data = attr.get_write_value()
self.info_stream(“Writing into attribute %s the value %s”, name, data)
I could create the attribute with initial value ‘99.99’. I created device proxy of this device and used write_attribute(srcid,‘False’) to write it. When I am reading the attribute after the write action, I am still getting value as ‘99.99’
class MyDevice(Device_4_impl):
def launch(self, name, script_id):
attr = PyTango.Attr(script_id, PyTango.DevString, PyTango.READ_WRITE)
self.add_attribute(attr, self.read_general, self.write_general)
""" code to create a process to execute script """
def write_general(self, attr):
name = attr.get_name()
data = attr.get_write_value()
self.info_stream("Writing into attribute %s the value %s", name, data)
def read_general(self, attr):
self.info_stream("Reading attribute %s", attr.get_name())
attr.set_value('99.99')
So, whenever I call ‘launch’ command on my/test/device (device on instance of MyDevice), a dynamic attribute is created at my/test/device with name that was passed as script_id argument. It’s values is also initialized to ‘99.99’. It further creates a process and executes a script. The script also receives script_id as its argument through sys.argv.
I want to pass various values to this dynamic attribute through the script. So I wrote in my script test.py:
I do not get any error or exception but the updated value is not reflected on jive. I also added dev_proxy.read_attribute(script_id) before and after writing attribute in the script. Both values return ‘99.99’
Please tell me if I am doing anything wrong. I need to update this dynamic attribute value throughout the life of the script.
Dynamic tango attribute behaviour works just like any other standard tango attribute.
In your case it seems that you are looking for a pure software attribute semantics. I propose you initialize the attribute value when you create the dynamic attribute with a default value.
When a client does a write, the value it should be updated and when a client asks to read the same attribute it should simply return the last written value (or the default if there was no write before).
Example:
class MyDevice(Device_4_impl):
def init_device(self):
# ...
self._dynamic_attrs = {}
def launch(self, name, script_id):
attr = PyTango.Attr(script_id, PyTango.DevString, PyTango.READ_WRITE)
self.add_attribute(attr, self.read_general, self.write_general)
self._dynamic_attrs[script_id] = '99.99'
""" code to create a process to execute script """
def write_general(self, attr):
name = attr.get_name()
data = attr.get_write_value()
self._dynamic_attrs[name] = data
self.info_stream("Writing into attribute %s the value %s", name, data)
def read_general(self, attr):
name = attr.get_name()
self.info_stream("Reading attribute %s", name)
attr.set_value(self._dynamic_attrs[name])