把Tango安装文件夹(D:\Program Files\tango\win64)下的lib和Include文件夹复制到项目所在目录,在.pro文件中添加头文件及其路径和相应的库:
# For tango config
INCLUDEPATH += $$PWD/include/vc12/
INCLUDEPATH += $$PWD/lib/vc12_dll/
DEPENDPATH += $$PWD/lib/vc12_dll/
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lCOS4_rt
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lCOS421_rtd
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lomniDynamic4_rt
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lomniDynamic4_rtd
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lomnithread40_rt
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lomnithread40_rtd
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lomniORB421_rt
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lomniORB421_rtd
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/vc12_dll -ltango
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/vc12_dll -ltangod
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lzmq
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/vc12_dll -lzmqd
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/vc12_dll -llog4tango
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/vc12_dll -llog4tangod
else:win32:CONFIG(debug, debug|release): LIBS += -LD:/tango/win64/lib/vc12_dll/ -llog4tangod
头文件添加:
#include <tango.h>
using namespace Tango;
DeviceProxy *device;//device
DeviceAttribute att_reply;//get Attribute from server
首先连接设备:
device = new DeviceProxy("sys/tg_test/1");
//
// Ping the device
//
device->ping();
读取设备属性Attributes:
try
{
//
// Read a device attribute
//
//**********Attribute ampli**********/
att_reply = device->read_attribute("ampli");
qDebug()<<att_reply.DoubleSeq[0];
//**********Attribute boolean_image**********/
att_reply = device->read_attribute("boolean_image");
for(int i=0;i<(att_reply.dim_x)*(att_reply.dim_y);i++)
{
qDebug()<<att_reply.BooleanSeq[i];
}
//**********Attribute boolean_scalar**********/
att_reply = device->read_attribute("boolean_scalar");
qDebug()<<att_reply.BooleanSeq[0];
//**********Attribute boolean_spectrum**********/
att_reply = device->read_attribute("boolean_spectrum");
for(int i=0;i<att_reply.dim_x;i++)
{
qDebug()<<att_reply.BooleanSeq[i];
}
//**********Attribute double_image**********/
att_reply = device->read_attribute("double_image");
for(int i=0;i<(att_reply.dim_x)*(att_reply.dim_y);i++)
{
qDebug()<<att_reply.DoubleSeq[i];
}
//**********Attribute double_scalar**********/
att_reply = device->read_attribute("double_scalar");
qDebug()<<att_reply.DoubleSeq[0];
//**********Attribute double_spectrum**********/
att_reply = device->read_attribute("double_spectrum");
for(int i=0;i<att_reply.dim_x;i++)
{
qDebug()<<att_reply.DoubleSeq[i];
}
//**********Attribute float_scalar**********/
att_reply = device->read_attribute("float_scalar");
qDebug()<<att_reply.FloatSeq[0];
//**********Attribute long64_scalar**********/
att_reply = device->read_attribute("long64_scalar");
qDebug()<<att_reply.Long64Seq[0];
//**********Attribute short_scalar**********/
att_reply = device->read_attribute("short_scalar");
qDebug()<<att_reply.ShortSeq[0];
//**********Attribute State**********/
vector<DeviceAttribute> *devattr;
vector<string> attr_names;
attr_names.push_back("State");
devattr = device->read_attributes(attr_names);
DevState state;
(*devattr)[0] >> state;
qDebug() << "my_attribute value " << state;
delete devattr;
//**********Attribute Status**********/
att_reply = device->read_attribute("Status");
qDebug()<<att_reply.StringSeq[0];
//**********Attribute string_scalar**********/
att_reply = device->read_attribute("string_scalar");
qDebug()<<att_reply.StringSeq[0];
//**********Attribute uchar_scalar**********/
att_reply = device->read_attribute("uchar_scalar");
qDebug()<<att_reply.UCharSeq[0];
//**********Attribute wave**********/
att_reply = device->read_attribute("wave");
for(int i=0;i<att_reply.dim_x;i++)
{
qDebug()<<att_reply.DoubleSeq[i];
}
qDebug()<<'\n';
}
catch (DevFailed &e)
{
Except::print_exception(e);
exit(-1);
}
写入设备属性Attributes:
try
{
//
// Write a device attribute
//
/**********Write Attribute boolean_scalar**********/
vector<DeviceAttribute> attr_boolean_scalar;
string boolean_scalar_name("boolean_scalar");
bool bool_attr = false;
attr_boolean_scalar.push_back(DeviceAttribute(boolean_scalar_name,bool_attr));
device->write_attributes(attr_boolean_scalar);
/**********Write Attribute ampli**********/
vector<DeviceAttribute> attr_ampli;
string ampli_name("ampli");
double ampli_attr = 2.2 ;
attr_ampli.push_back(DeviceAttribute(ampli_name,ampli_attr));
device->write_attributes(attr_ampli);
/**********Write Attribute double_scalar**********/
vector<DeviceAttribute> attr_double_scalar;
string double_scalar_name("double_scalar");
double double_scalar_attr=1.12;
attr_double_scalar.push_back(DeviceAttribute(double_scalar_name,double_scalar_attr));
device->write_attributes(attr_double_scalar);
}
catch (DevFailed &e)
{
Except::print_exception(e);
exit(-1);
}
写入命令Command:
try
{
//
// Execute a command on the device and extract the reply as a string
//
//**********State Command**********/
string db_info;
DeviceData cmd_reply;
cmd_reply = device->command_inout("State");
cmd_reply >> db_info;
cout << "Command reply " << db_info << endl;
//**********Status Command**********/
cmd_reply = device->command_inout("Status");
cmd_reply >> db_info;
cout << "Command reply " << db_info << endl;
//**********DevVarLongArray Command**********/
DeviceData din_LongArray,dout_LongArray;
DevVarLongArray *in_LongArray = new DevVarLongArray();
in_LongArray->length(256);
(*in_LongArray)[0] = 2;
(*in_LongArray)[1] = 4;
din_LongArray << in_LongArray;
try
{
dout_LongArray = device->command_inout("DevVarLongArray",din_LongArray);
cout << "Command DevVarLongArray reply \n" << dout_LongArray << endl;
}
catch(DevFailed &e)
{
Except::print_exception(e);
exit(-1);
}
/**********DevBoolean Command**********/
DeviceData din_Boolean,dout_Boolean;
DevBoolean *in_bool = new DevBoolean();
*in_bool = true;
din_Boolean << in_bool;
try
{
dout_Boolean = device->command_inout("DevBoolean",din_Boolean);
cout << "Command DevBoolean reply " << dout_Boolean << endl;
}
catch(DevFailed &e)
{
Except::print_exception(e);
exit(-1);
}
}
catch (DevFailed &e)
{
Except::print_exception(e);
exit(-1);
}