Writing your first C++ TANGO client¶
Intended audience: beginer developers, Programming language: c++
The quickest way of getting started is by studying this example :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /*
* example of a client using the TANGO C++ api.
*/
#include <tango.h>
using namespace Tango;
int main(unsigned int argc, char **argv)
{
try
{
//
// create a connection to a TANGO device
//
DeviceProxy *device = new DeviceProxy("sys/database/2");
//
// Ping the device
//
device->ping();
//
// Execute a command on the device and extract the reply as a string
//
string db_info;
DeviceData cmd_reply;
cmd_reply = device->command_inout("DbInfo");
cmd_reply >> db_info;
cout << "Command reply " << db_info << endl;
//
// Read a device attribute (string data type)
//
string spr;
DeviceAttribute att_reply;
att_reply = device->read_attribute("StoredProcedureRelease");
att_reply >> spr;
cout << "Database device stored procedure release: " << spr << endl;
}
catch (DevFailed &e)
{
Except::print_exception(e);
exit(-1);
}
}
|
Modify this example to fit your device server or client’s needs, compile it and link with the library -ltango. Forget about those painful early TANGO days when you had to learn CORBA and manipulate Any’s. Life’s going to easy and fun from now on !