In the previous part of our TANGO tutorial trail we put our TANGO device into production by registering it with a TANGO database. The TANGO tools allowed for basic interaction with our device. Now we want to improve the device with the TANGO way of configuration: properties.
TANGO device configuration
TANGO devices are configured with properties, which are not to confuse with OO-properties or TANGO attributes. TANGO properties are read on initialisation of a device and saved to the TANGO database. That way they live across server restarts. TANGO properties replace simple configuration files or registry-like configuration frameworks. As they are saved in the TANGO database it makes our devices location-agnostic – they can run on any host system on the network. Let us add a format properties to our TimeDevice to change the output to our liking. Again, we use pogo to define the property:
The property will be generated as a member variable of our TANGO device manage by the framework. We do not need to read it from the database ourselves – the corresponding code is generated by pogo – we just use it (
format in line 5):
/*----- PROTECTED REGION ID(TimeDevice::read_CurrentTime) ENABLED START -----*/ attr_CurrentTime_read = new Tango::DevString; TimeProvider timeProvider; *attr_CurrentTime_read = Tango::string_dup(timeProvider.now(format).c_str()); // Set the attribute value attr.set_value(attr_CurrentTime_read, 1, 0, true); /*----- PROTECTED REGION END -----*/ // TimeDevice::read_CurrentTime
Managing device state
The state of a TANGO device is extremely important for TANGO clients because they often decide how to interact with a device based on its state. We will cover state and the TANGO state machine in a later post but for now we make our TimeDevice sane by setting the its state to ON after correct initialisation, so that it reflects the operating state of the TimeDevice:
/*----- PROTECTED REGION ID(TimeDevice::init_device) ENABLED START -----*/ set_state(Tango::ON); set_status("Ready to accept time queries."); /*----- PROTECTED REGION END -----*/ // TimeDevice::init_device
Here is the result in Jive and AtkPanel:
We extended our to device with some real world features like configuration by the means of device properties and rudimentary state management. Real state management is an important topic on its own and deserves a separate blog post. Feel free to play with the full source code.