Tune polling from inside device classes

Tune polling from inside device classes#

audience:developers lang:all

It is possible to configure command or attribute polling from within a device class, i.e. an instance of Tango::DeviceImpl. The available functionality is similiar to the one found in Tango::DeviceProxy.

With them, you can:

  • Check if a command or attribute is polled

  • Start/stop polling for a command or an attribute

  • Get or update the polling period for a polled attribute or command

To display some information related to polling of the attribute named TheAtt:

 1std::string att_name{"TheAtt"};
 2TANGO_LOG_DEBUG << "Attribute" << att_name;
 3
 4if(is_attribute_polled(att_name))
 5{
 6   TANGO_LOG_DEBUG << " is polled with period " << get_attribute_poll_period(att_name) << " ms" << std::endl;
 7}
 8else
 9{
10   TANGO_LOG_DEBUG << " is not polled" << std::endl;
11}

To poll a command:

1poll_command("TheCmd", 250);

If the command is already polled, this method will update its polling period to 250 ms.

Finally, to stop polling the same command:

1stop_poll_command("TheCmd");

All these DeviceImpl polling related methods are documented in the DeviceImpl class documentation.

To display some information related to polling of the attribute named TheAtt in a DeviceImpl class:

1att_name = "TheAtt"
2
3if self.is_attribute_polled(att_name):
4    print(f"{} is polled with period {} ms", att_name, self.get_attribute_poll_period(att_name))
5else:
6    print(f"{} is not polled", att_name)

To poll a command:

1self.poll_command("TheCmd", 250)

If the command is already polled, this method will update its polling period to 250 ms.

Finally, to stop polling:

1self.stop_poll_command("TheCmd")

All these DeviceImpl polling related methods are documented in DeviceImpl.

The polling can be retrieved and modified from the DeviceManager class.

 1import org.tango.server.annotation.Device;
 2import org.tango.server.annotation.DeviceManagement;
 3import org.tango.server.device.DeviceManager;
 4import fr.esrf.Tango.DevFailed;
 5
 6@Device
 7public class Test {
 8    @DeviceManagement
 9    private DeviceManager deviceManager;
10     ...
11        final String attName = "TheAttr";
12        if (deviceManager.isPolled(attName)) {
13            System.out.println(attName + " is polled with period " + deviceManager.getPollingPeriod(attName) + " mS");
14        } else {
15            System.out.println(attName + " is not polled");
16        }
17        deviceManager.startPolling("TheCmd", 250);
18        deviceManager.stopPolling("TheCmd")
19        ...
20
21   public void setDeviceManager(final DeviceManager deviceManager) {
22        this.deviceManager = deviceManager;
23    }
24}