get_attribute_config

Hi,

I am trying to change the format and unit of my PyTangoDS attributes dynamically.

For that I want to use the get_attribute_config() method within the DS.
I got it working in Python2 but now with Python3 and PyTango9.2.5 I get the following error:

DevError[
desc = RuntimeError: unidentifiable C++ exception

origin = File "/usr/lib/python3/dist-packages/tango/device_class.py", line 568, in __DeviceClass__device_factory
device = self._new_device(deviceImplClass, klass, dev_name)
File "/usr/lib/python3/dist-packages/tango/device_class.py", line 547, in __DeviceClass__new_device
return klass(dev_class, dev_name)
File "/usr/lib/python3/dist-packages/tango/server.py", line 573, in __init__
self.init_device()
File "/usr/lib/python3/dist-packages/tango/server.py", line 362, in init_device
return get_worker().execute(init_device_orig, self)
File "/usr/lib/python3/dist-packages/tango/green.py", line 98, in execute
return fn(*args, **kwargs)
File "/home/pi/TangoDS/MCC2/PhytronMCC2Axis.py", line 174, in init_device
ac = self.get_attribute_config("sw_limit_minus")

reason = PyDs_PythonError
severity = ERR]
]
Segmentation fault


Any ideas what might have changes?
Hi,
Generally the segfault indicates something is going wrong on a low level, i.e. nothing wrong with your code but the PyTango library.
If you were using your own threads etc., I would say it might be related to thread safety, but here you seem to be using only PyTango provided stuff, right?, so it should work (and actually also in your own threads it should be thread safe).

On Windows, this would point toward a compilation error for the PyTango package, not sure what can go wrong on Linux. How did you install it? (Pip, Conda tango channel, self compiled, other?)

As a quick first step I recommend trying a different version of PyTango, e.g.
pip install PyTango==9.3.1
(Note that on Windows the 9.3.2 has it's own install problems right now, but 9.3.1 seems to be OK, and on Linux probably both are fine)

What OS are you on, what is the hardware (Raspberry Pi)?

Regards, Lenny
PS: Seeing your class is called PhytronMCC, we are also using Phytron (here several phymotion controllers and PyTango device servers), so if you have any troubles there I'm happy to discuss.
Hi Leonard,

thanks for the quick reply.
I just updated from PyTango 9.2.0 to 9.2.5 for Py3 compatibility.
With PyTango 9.2.0 and Py2 it was working fine.

I actually installed PyTango and Tango all via apt from the official channels for the Raspi.
I use Raspberian Buster, the latest release 32bit.

I actually want/learned that the Tango and PyTango versions should only differ at the last digit.
So in order to get Tango 9.3.x and PyTango 9.3.x installed on the Raspi I would need to compile a lot myself, which I wanted to avoid, since they are not available in the official software channels so far.

P.S.: thanks for offering help with the Phytron. Actually we are only using the MCC2 controller for now and we are pretty happy with that. Our TangoDS can be found here:
https://github.com/dschick/pytango-PhytronMCC2
I was wondering if it might be worth to list it also in the official DS list?
However, I am not very familiar with SVN - only git.
dschick
Hi,

I am trying to change the format and unit of my PyTangoDS attributes dynamically.

For that I want to use the get_attribute_config() method within the DS.
I got it working in Python2 but now with Python3 and PyTango9.2.5 I get the following error:

DevError[
desc = RuntimeError: unidentifiable C++ exception

origin = File "/usr/lib/python3/dist-packages/tango/device_class.py", line 568, in __DeviceClass__device_factory
device = self._new_device(deviceImplClass, klass, dev_name)
File "/usr/lib/python3/dist-packages/tango/device_class.py", line 547, in __DeviceClass__new_device
return klass(dev_class, dev_name)
File "/usr/lib/python3/dist-packages/tango/server.py", line 573, in __init__
self.init_device()
File "/usr/lib/python3/dist-packages/tango/server.py", line 362, in init_device
return get_worker().execute(init_device_orig, self)
File "/usr/lib/python3/dist-packages/tango/green.py", line 98, in execute
return fn(*args, **kwargs)
File "/home/pi/TangoDS/MCC2/PhytronMCC2Axis.py", line 174, in init_device
ac = self.get_attribute_config("sw_limit_minus")

reason = PyDs_PythonError
severity = ERR]
]
Segmentation fault


Any ideas what might have changes?

I'm having the same problem :

RuntimeError: unidentifiable C++ exceptionTraceback (most recent call last):
File "GenericDevice.py", line 754, in init_device
self._init_modules()
File "GenericDevice.py", line 830, in _init_modules
self.Connect()
File "GenericDevice.py", line 877, in Connect
self.create_attribute_dynamic()
File "GenericDevice.py", line 2249, in create_attribute_dynamic
self.create_modul_attribute_dynamic(iLogicalModulAdr)
File "GenericDevice.py", line 2284, in create_modul_attribute_dynamic
self.db_update_modul_unit_label(iLogicalModulAdr)
File "GenericDevice.py", line 1083, in db_update_modul_unit_label
",".join(self.ptAcqDevice.GetLstRawUnitFromAcqModule(iMod)) + ",ms")
File "GenericDevice.py", line 1104, in device_update_attribute_config
config = self.get_attribute_config(attr_name)[0]
RuntimeError: unidentifiable C++ exception


Have you solved your problem ?
Hi dschick

I tried it out with a simple test case in Pytango 9.3.2 and get the same kind of failure. It looks like a problem in the conversion of the string parameter from a Python object to a C++ string. The failure is specifically for Unicode strings (so native Python 3 strings). Changing the parameter to a byte string works in Python 3 (and is probably why it was working in Python 2).

So as a workaround:

ac = self.get_attribute_config(b"sw_limit_minus")


Another note, unrelated to this issue:
Looking at the code in the repo you linked, and I suggest you call the super class's `init_device` instead of `get_device_properties` directly. The high level API automatically gets the device properties, if you call its `init_device` or don't override it.


def init_device(self):
super().init_device()
self.info_stream("init_device()")
# remove this: self.get_device_properties(self.get_device_class())


Regards,
Anton
Hi Anton,

many thanks for the help. So both suggestions are working perfectly fine.

However, it seems, that there is no set_attribute_config anymore available for the Device class.
This method is only available for the DeviceProxy.

So what would be the correct way for setting/changing AttributeConfigs like the unit of an Attribute from within the actual TangoDS class?

I tried already with self.get_device_attr() but it seems that I cannot change the unit of the returned WAttribute.

Of course I could do a workaround to open a DeviceProxy within the class to change the Attribute Config, but I do not think that this a really elegant way of doing this.

Best

Daniel
I also opened an issue at Github: https://github.com/tango-controls/pytango/issues/361
Hi Daniel

Yes, I see the set_attribute_config method is not exposed in Python. On closer inspection, I notice that PyTango is missing quite a few methods from the C++ layer. The get_attribute_config we are calling above is the implementation for the original device version 1 of the IDL. PyTango is also exposing get_attribute_config_2 and get_attribute_config_3 methods which provide the newer implementations. The latest, get_attribute_config_5 is missing.

As for setting, PyTango exposes set_attribute_config_2 and set_attribute_config_3, but not set_attribute_config_5.

You could try something like this:

ac3 = self.get_attribute_config_3(b"sw_limit_minus")
ac3[0].unit = "Foo"
self.set_attribute_config_3(ac3)


We'll need to add the missing methods in PyTango.

Anton
okay I see. that is also why it is a bit hard to find some things in the PyTango Documenation, that are available in C++.
Anyhow, many thanks. it is working now as expected and as before in PyTango9.2.0 in Py3.

I just want to mention, that the inputs for the unit and format, etc., also need to be byte strings. So here is the working snippet:
ac3 = self.get_attribute_config_3(b"sw_limit_minus")
ac3[0].unit = b"Foo"
self.set_attribute_config_3(ac3)
Edited 4 weeks ago
 
Register or login to create to post a reply.