Tango Attributes

The usage of some Tango elements are demonstrated. The first code snippet uses a DeviceAttribute which is allocated by declaration.

//
// the DeviceData and the DeviceAttribute are created by declaration, no 'delete'
//
// g++ -g -O0 -I /usr/include/tango attrTestNew.cpp -o attrTestNew -L/usr/lib/x86_64-linux-gnu -ltango -llog4tango -lomniORB4 -lomniDynamic4 -lomnithread
// valgrind --leak-check=full --track-origins=yes --verbose --show-leak-kinds=all --log-file=valgrind.log ./attrTestNew
//
#include <tango.h>
using namespace Tango;

int main( int argc, char **argv)
{
  Tango::DevLong devLong;
  Tango::DevDouble devDouble;
  DeviceData devdata; 
  DeviceAttribute da;
  DeviceProxy *timer = 0; 
  DeviceProxy *counter = 0;

  timer = new DeviceProxy( "p09/dgg2/eh.01");
  counter = new DeviceProxy( "p09/counter/eh.01");

  da.set_name( "SampleTime"); 
  da << 3.5; 

  timer->write_attribute( da);   

  cout << " starting timer with 3.5s " << endl; 
  timer->command_inout( "Start"); 
  devdata = counter->command_inout( "Reset"); 
  devdata = timer->command_inout( "Check"); 
  devdata >> devLong; 
  while( devLong)
    {
      da = counter->read_attribute( "Counts"); 
      da >> devDouble;
      cout << " read-counter  returns " << devDouble << endl; 
      devdata = timer->command_inout( "Check"); 
      devdata >> devLong; 
      cout << " check-timer  returns " << devLong << endl; 
      sleep(1); 
    }

  delete timer;
  delete counter;
  return 1; 
}

The next example shows how a device attribute is allocated by the new operator.

//
// the DeviceData and the DeviceAttribute are created using 'new', 'delete' needed
//
// g++ -g -O0 -I /usr/include/tango attrTestNew.cpp -o attrTestNew -L/usr/lib/x86_64-linux-gnu -ltango -llog4tango -lomniORB4 -lomniDynamic4 -lomnithread
// valgrind --leak-check=full --track-origins=yes --verbose --show-leak-kinds=all --log-file=valgrind.log ./attrTestNew
//
#include <tango.h>
using namespace Tango;

int main( int argc, char **argv)
{
  Tango::DevLong devLong;
  Tango::DevDouble devDouble;
  DeviceData *devdata = 0;  
  DeviceAttribute *da = 0;  
  DeviceProxy *timer = 0; 
  DeviceProxy *counter = 0;

  da = new DeviceAttribute();
  devdata = new DeviceData(); 
  
  timer = new DeviceProxy( "p09/dgg2/eh.01");
  counter = new DeviceProxy( "p09/counter/eh.01");

  da->set_name( "SampleTime"); 
  *da << 3.5; 

  timer->write_attribute( *da);   

  cout << " starting timer with 3.5s " << endl; 
  timer->command_inout( "Start"); 
  *devdata = counter->command_inout( "Reset"); 
  *devdata = timer->command_inout( "Check"); 
  *devdata >> devLong; 
  while( devLong)
    {
      *da = counter->read_attribute( "Counts"); 
      *da >> devDouble;
      cout << " read-counter  returns " << devDouble << endl; 
      *devdata = timer->command_inout( "Check"); 
      *devdata >> devLong; 
      cout << " check-timer  returns " << devLong << endl; 
      sleep(1); 
    }

  delete da;
  delete devdata;
  delete timer;
  delete counter;
  return 1; 
}

Here is almost the same code, just a little bit shorter.

 
//
// the DeviceData and the DeviceAttribute are created using 'new', 'delete' needed
//
// g++ -g -O0 -I /usr/include/tango attrTestShort.cpp -o attrTestShort -L/usr/lib/x86_64-linux-gnu -ltango -llog4tango -lomniORB4 -lomniDynamic4 -lomnithread
// valgrind --leak-check=full --track-origins=yes --verbose --show-leak-kinds=all --log-file=valgrind.log ./attrTestShort
//
#include <tango.h>
using namespace Tango;

int main( int argc, char **argv)
{
  Tango::DevLong devLong;
  Tango::DevDouble devDouble;

  DeviceAttribute *da = new DeviceAttribute();
  DeviceData *devdata = new DeviceData(); 
  
  DeviceProxy *timer = new DeviceProxy( "p09/dgg2/eh.01");
  DeviceProxy *counter = new DeviceProxy( "p09/counter/eh.01");

  da->set_name( "SampleTime"); 
  *da << 3.5; 
//
// void DeviceProxy::write_attribute(DeviceAttribute&)
//
  timer->write_attribute( *da);   

  cout << " starting timer with 3.5s " << endl; 
  timer->command_inout( "Start"); 
  *devdata = counter->command_inout( "Reset"); 
  *devdata = timer->command_inout( "Check"); 
  *devdata >> devLong; 
  while( devLong)
    {
      *da = counter->read_attribute( "Counts"); 
      *da >> devDouble;
      cout << " read-counter  returns " << devDouble << endl; 
      *devdata = timer->command_inout( "Check"); 
      *devdata >> devLong; 
      cout << " check-timer  returns " << devLong << endl; 
      sleep(1); 
    }

  delete da;
  delete devdata;
  delete timer;
  delete counter;
  return 1; 
}