# How to tune polling by code in a TANGO class

Intended audience: advanced developers,

This HowTo explains how it is easily possible to tune attribute or command polling parameters in the code of a Tango class

Since Tango 8, it is possible to configure command or attribute polling within a Tango class code. A new set of polling related methods has been added to the base class Tango::DeviceImpl. These methods are similar to those you find in the Tango::DeviceProxy class when you write a Tango client. With them, you can

- Check if a command or attribute is polled

- Start/Stop polling for a command or a attribute

- Get or update polling period for a polled attribute or command

## In C++

Programming language: c++

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

    1string att_name("TheAtt");
    2cout << "Attribute " << att_name;
    3
    4if (is_attribute_polled(att_name) == true)
    5   cout << " is polled with period " << get_attribute_poll_period(att_name) << " mS" << endl;
    6else
    7   cout << " is not polled" << endl;

To poll a command simply type:

    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, type:

    1stop_poll_command("TheCmd");

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

## In Python

Programming language: python

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

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

To poll a command, in a DeviceImpl context, simply type:

    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 the same command, in a DeviceImpl context type:

    1self.stop_poll_command("TheCmd")

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

## In Java

Programming language: java

The polling can be retrieved and modified from the DeviceManager class. Here is an example:

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