Problem with dynamic attributes using pytango 9.3.4 - read-parameter() missing 1 argument

Hi,

I am posting a problem we discovered with PyTango 9.3.4 with dynamic attributes. Dynamic attributes fail with this error: Description - TypeError: read_parameter() missing 1 required positional argument: 'attr'

Here is an example of a client:

>>> from PyTango import DeviceProxy
>>> ab = DeviceProxy("cm01/metadata/ingest")
>>> ab.read_attribute("EM_voltage")
> /users/blissadm/conda/miniconda/envs/multivisor/lib/python3.7/site-packages/tang/device_proxy.py(155)__check_read_attribute()
-> def __check_read_attribute(dev_attr):
(Pdb) dev_attr
DeviceAttribute(data_format = tango._tango.AttrDataFormat.FMT_UNKNOWN, dim_x = 0, dim_y = 0, has_failed = True, is_empty = True, name = 'EM_voltage', nb_read = 0, nb_written = 0, quality = tango._tango.AttrQuality.ATTR_INVALID, r_dimension = AttributeDimension(dim_x = 0, dim_y = 0), time = TimeVal(tv_nsec = 0, tv_sec = 0, tv_usec = 0), type = tango._tango.CmdArgType(100), value = None, w_dim_x = 0, w_dim_y = 0, w_dimension = AttributeDimension(dim_x = 0, dim_y = 0), w_value = None)


The same call with pytango from conda forge 9.3.3 is fine

>>> from PyTango import DeviceProxy
>>> ab = DeviceProxy("cm01/metadata/ingest")
>>> ab.read_attribute("EM_voltage")
DeviceAttribute(data_format = tango._tango.AttrDataFormat.SCALAR, dim_x = 1, dim_y = 0, has_failed = False, is_empty = False, name = 'EM_voltage', nb_read = 1, nb_written = 1, quality = tango._tango.AttrQuality.ATTR_VALID, r_dimension = AttributeDimension(dim_x = 1, dim_y = 0), time = TimeVal(tv_nsec = 0, tv_sec = 1658238511, tv_usec = 901670), type = tango._tango.CmdArgType.DevString, value = '', w_dim_x = 1, w_dim_y = 0, w_dimension = AttributeDimension(dim_x = 1, dim_y = 0), w_value = '30000')


The problem is on the server side. When a device server is started with pytango 9.3.4, it gives the attribute error. When started with 9.3.3, even a 9.3.4 client works fine.

Any tips or explanations of what we are doing wrong are welcome!

Andy + Antonia
Hello,

The problem is related to the fix of PyTango: issue 401...

The general solution is, that when you add dynamic attribute, for f_get, g_set and f_is_allowed you should use "f_set = self.my_read_method" statement. I guess you do something like "f_set = <My_Class_name>.my_read_method" - this won't work.

Here there is a related discussion and explanation: PyTango: issue 454...
Edited 1 year ago
Hi Yury,

thank you for this answer - it solves the problem!

For anyone who encounters this problem the solution is as described by Yury above (with slightly different example names):

replace
<Your_Class_name>.your_read_method
with
self.your_read_method
in the self.add_attribute() call e.g.

self.add_attribute(param, self.read_parameter, self.write_parameter, None)


The same for the write method of course. If you do this then your device server will work with pytango 9.3.4

Q: is this compatible with previous versions of pytango?

Q: why was the syntax with the <class name> used in the first place?

The whole thing has something to do with bound and unbound variables in Python but don't ask me to explain it!

Andy
Andy
Q: is this compatible with previous versions of pytango?
- yes, statements like
self.add_attribute(param, self.read_parameter, self.write_parameter, None)

are compatible with previous pytango
Andy
Q: why was the syntax with the <class name> used in the first place?

- this I do not know.

Actually, for me, usage of unbound methods to read|write attribute of the particular device is at least strange.
Edited 1 year ago
 
Register or login to create to post a reply.