How to get the list of properties and attributes in the code of the device itself?

Hello!

I would like to ask if it is possible to get inside the code of a device class such information as commands, attributes and name of this device. I understand that it is possible in case of getting data from other devices using device proxy. But what about a device getting its data from itself?
Hi,

The easiest way is to do a DeviceProxy on yourself and execute the same commands as you would use on a classical client.

You can also explore the interface provided by the Device_5Impl class: https://tango-controls.github.io/cppTango-docs/classTango_1_1Device__5Impl.html

From there, you can for instance use Tango::DeviceImpl::get_device_class() method to get a pointer to the DeviceClass singleton.

The DeviceClass class provides some methods to explore the interface of the class like DeviceClass::get_command_list() for instance (https://tango-controls.github.io/cppTango-docs/classTango_1_1DeviceClass.html#a9e37d56d78b31cbc5c767f65c1b2117f)

Hoping this helps a bit.
Reynald
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
I forgot to say that if you're using Pogo, your Tango class is currently systematically inheriting from Device_5Impl.
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
Hi GTLeet

You say that you want to get it from within the device itself. I assume you don't know the names of these fields, or want to do it programmatically for some reason.

Expanding on Reynald's answer, at runtime a device instance can query itself with self.get_device_class(), which gives all the details about commands, attributes, properties, etc. This can be done without a DeviceProxy.

Similarly, at runtime a device instance can query its own name with self.get_name().

A while back a colleague of mine was experimenting in order to extract the API of the device from the Python code statically. I.e., without executing the device. The idea was to be able to make something like a Pogo XMI file directly from the Python source code. It was never completed, but the commands, attributes and device properties could easily be extracted. The example code is here:

https://gitlab.com/ska-telescope/ska-tmc/-/blob/1e848d2a0ce0ffef2159177ef5aae70331828ebf/tmcprototype/CentralNode/test/unit/pytango_parsel_test.py#L50
 
Register or login to create to post a reply.