Attribute enum query in server code??

As part of a Device Server SKA we have a Tango Attribute defined as:

adminMode = attribute(
dtype='DevEnum',
access=AttrWriteType.READ_WRITE,
memorized=True,
doc="The admin mode reported for this device. It may interpret the current "
"device condition and condition of all managed devices to set this. "
"Most possibly an aggregate attribute.",
enum_labels=["ON-LINE", "OFF-LINE", "MAINTENANCE", "NOT-FITTED", "RESERVED", ],
)

and later in an inherited class in the same server we wish to check the current value of this attribute

Using DeviceProxy this is easy

admin_labels = list(dp.attribute_query('adminMode').enum_labels)
admin_online = admin_labels.index('ON-LINE')
admin_maintenance = admin_labels.index('MAINTENANCE')
admin_offline = admin_labels.index('OFF-LINE')
admin_not_fitted = admin_labels.index('NOT-FITTED')
current_admin_mode = self.read_adminMode()

BUT can we retrieve the ENUM directly from the Attribute itself???? It seems wrong to have to loopback to the server using DeviceProxy!

Ideally it would be good to replace line the
admin_labels = list(dp.attribute_query('adminMode').enum_labels)
by something like
admin_labels = adminMode.get_enum_labels()
Edited 4 years ago
Hi Brian

I agree the loopback would be a bad approach! You cannot read from the attribute itself, since it doesn't having a backing variable implicitly. There would be `read_adminMode` method that will return the current value. In the case of the SKA LMC base classes, the variable returned is `self._admin_mode`. Unfortunately this variable isn't actually an enumerated type - that's something that still needs to be fixed in the SKA Base classes - I guess I should do it soon!

For a more general example, see here:
https://pytango.readthedocs.io/en/stable/data_types.html#devenum-pythonic-usage

That same example shows that on the client side the DeviceProxy will actually give you an IntEnum object directly, so you don't need to bother with the labels.

Regards,

Anton
Edited 4 years ago
 
Register or login to create to post a reply.