Setting value of dynamic attributes on initialization

Hi all,

I have written a PyTango DS which creates a list of boolean dynamic attributes for a DIO DAQ device.

I am currently struggling with the situation, that all writable attributes are initialized as True and that this value is also not written to the DAQ which means, that the DO are actually all False, while Jive indicates a True after startup.

So my question is, how can I set the value of a dynamic attribute on initializaton?

Many thanks in advance!

Daniel
Edited 3 months ago
Hi, Daniel

I am not sure I correctly understand your quiestion. Why don`t you just call read function by yourself after add_attribute method?

E.g.


class TestDevice(Device):

def __init__(self, *args, **kwargs):
super(TestDevice, self).__init__(*args, **kwargs)
self._dyn_attr_value = None

def initialize_dynamic_attributes(self):
attr = attribute(
name="dyn_attr",
dtype=dtype,
max_dim_x=10,
access=AttrWriteType.READ_WRITE,
fget=self.read_attr,
fset=self.write_attr,
)
self.add_attribute(attr)

# and here we do initialisation
self.read_attr()

def read_attr(self, attr):
self._dyn_attr_value = some_function_to_read_attribute()
attr.set_value(self._dyn_attr_value )

def write_attr(self, attr):
self._dyn_attr_value = attr.get_write_value()
some_function_to_set_attribute(self._dyn_attr_value)



Or did I undestand something wrong?
Edited 2 months ago
Hi, Daniel
If you want the real DO value to be available after attribute creation, use set_write_value() function.
Something like during attribute creation procedure:

attr = attribute(name="dyn_attr_name", ..other_pars)
self.add_attribute(attr)
v = read_real_attribute value()
self.dyn_attr_name.set_write_value(v)
 
Register or login to create to post a reply.