cpp

Simple cpp example showing how to read attributes and properties.

/* 
 * example of a client using the TANGO C++ api.
 */
#include <tango.h>
using namespace Tango;



main(unsigned int argc, char **argv)
{
  unsigned long temp;
  float out;  
  int nb_read;
  DeviceAttribute da; 
  long acceleration;
  long base_rate;
  long slew_rate;
  double current_unit_position; 
 
  //  
  // create a connection to a TANGO device
  //

  DeviceProxy *device = new DeviceProxy( "tango://has107k:10000/exp/line1/mot1");

  // Read the state

  DevState dev_state;
  dev_state = device->state();


  // Read attributes
  
  da = device->read_attribute("Acceleration");
  da >> acceleration;
  cout << "Acceleration " << acceleration << endl;  
  da = device->read_attribute("BaseRate");
  da >> base_rate;
  cout << " BaseRate " << base_rate << endl;

  da = device->read_attribute("SlewRate");
  da >> slew_rate;
  cout << "SlewRate " << slew_rate << endl;

  // Write value to attribute

  DeviceAttribute *da_write = new DeviceAttribute( "Acceleration", (long)20);

  device->write_attribute(*da_write);



  // Read Properties

  DbData prop;

  prop.push_back(DbDatum("Base"));
  prop.push_back(DbDatum("Channel"));
  prop.push_back(DbDatum("AccuMin"));
  prop.push_back(DbDatum("AccuMax"));
  prop.push_back(DbDatum("SlewRateMinHw"));
 
  device->get_property(prop);

  unsigned long base;
  unsigned long channel;
  long accu_min;
  long accu_max; 
  unsigned long slew_rate_min_hw;

  prop[0] >> base;
  prop[1] >> channel;
  prop[2] >> accu_min;
  prop[3] >> accu_max;
  prop[4] >> slew_rate_min_hw;

  cout << "Base " << base << " Channel " << channel << " AccuMin " << accu_min << " AccuMax " << accu_max << " SlewRateMinHw " << slew_rate_min_hw << endl;

  // Write new value to existing properties or insert new ones.
 
  unsigned long base_temp = 61440;
  unsigned long channel_temp = 0;

  DbDatum base_toput("Base"), channel_toput("Channel");
  DbData db_data;
  base_toput << base_temp;
  channel_toput << channel_temp;
  db_data.push_back(base_toput);
  db_data.push_back(channel_toput);
  device->put_property(db_data);

   // Execute command without arguments

  device->command_inout( "StartMove");

  // Execute command with arguments

  DeviceData units_to_move_to_tmp;
  double units_to_move_to = 1000;
  
  units_to_move_to_tmp << units_to_move_to;
  device->command_inout( "SetupUnitMove", units_to_move_to_tmp);


// Read string properties (for example for dynamic attributes) 
 
  DbData prop1;
  prop1.push_back(DbDatum("dyNbUnitsToMoveTo"));
  prop1.push_back(DbDatum("dyNbMotorName"));
   

  DeviceProxy *device1 = new DeviceProxy( "tango://has107k:10000/exp/test/mm1");
  
  device1->get_property(prop1);
  if ((prop1[0].is_empty() == false)){
	  vector<string> temp;
	  short int length;
	  prop1[0] >> temp;
	  length = prop1[0].size();
	  cout << "Teresa: de prop1 "  << prop1[0].size() << " " << temp[0].c_str() << " " << temp[1].c_str() << endl;
  }
  if ((prop1[1].is_empty() == false)){
	  vector<string> temp;
	  short int length;
	  prop1[1] >> temp;
	  length = prop1[1].size();
	  cout << "Teresa: de prop1 " << length << " " << prop1[1].size() << " " << temp[0].c_str() << " " << temp[1].c_str() << endl;
  }
  
}

Cpp example for setting the properties and attributes of a new OmsVme58 Device to default values.

/* 
 * File for setting the properties and attributes of a new OmsVme58 device to
 * default values.
 *
 */
#include <tango.h>
using namespace Tango;


main(unsigned int argc, char **argv)
{

 
  //  
  // create a connection to the new OmsVme58 TANGO device
  //

  DeviceProxy *device = new DeviceProxy( "tango://has107k:10000/exp/line1/mot2");

  // Write value to attributes

  DeviceAttribute *da_write1 = new DeviceAttribute( "Acceleration", (long)500000);
  device->write_attribute(*da_write1);

  DeviceAttribute *da_write2 = new DeviceAttribute( "BaseRate", (long)1000);
  device->write_attribute(*da_write2);

  DeviceAttribute *da_write3 = new DeviceAttribute("Conversion", (double)10);
  device->write_attribute(*da_write3);

  DeviceAttribute *da_write4 = new DeviceAttribute("SettleTime", (double)0.1);
  device->write_attribute(*da_write4);

  DeviceAttribute *da_write5 = new DeviceAttribute("SlewRate", (long)1000);
  device->write_attribute(*da_write5);

  DeviceAttribute *da_write6 = new DeviceAttribute("SlewRateMax", (long)134938064);
  device->write_attribute(*da_write6);

  DeviceAttribute *da_write7 = new DeviceAttribute("SlewRateMin", (long)1);
  device->write_attribute(*da_write7);

  DeviceAttribute *da_write8 = new DeviceAttribute("UnitCalibration", (double)0);
  device->write_attribute(*da_write8);

  DeviceAttribute *da_write9 = new DeviceAttribute("StepCalibration", (long)0);
  device->write_attribute(*da_write9);

  DeviceAttribute *da_write10 = new DeviceAttribute("StepBacklash", (long)100);
  device->write_attribute(*da_write10);

  DeviceAttribute *da_write11 = new DeviceAttribute("StepLimitMax", (long)1000000);
  device->write_attribute(*da_write11);

  DeviceAttribute *da_write12 = new DeviceAttribute("StepLimitMin", (long)-1000000);
  device->write_attribute(*da_write12);



  // Write default values to properties
 
  unsigned long base = 61440;
  unsigned long channel = 0;
  long accu_min = -3350000;
  long accu_max = 3350000; 
  unsigned long slew_rate_min_hw = 0;
  unsigned long slew_rate_max_hw = 1044000;
  unsigned long acceleration_min_hw = 0;
  unsigned long acceleration_max_hw = 1000000000;
  unsigned short type = 0;

  DbDatum base_toput("Base"), channel_toput("Channel");
  DbDatum accu_min_toput("AccuMin"), accu_max_toput("AccuMax");
  DbDatum slew_rate_min_hw_toput("SlewRateMinHw"), slew_rate_max_hw_toput("SlewRateMaxHw");
  DbDatum acceleration_min_hw_toput("AccelerationMinHw"), acceleration_max_hw_toput("AccelerationMaxHw");
  DbDatum type_toput("Type");
  DbData db_data;
  base_toput << base;
  channel_toput << channel;
  accu_min_toput << accu_min;
  accu_max_toput << accu_max;
  slew_rate_min_hw_toput << slew_rate_min_hw;
  slew_rate_max_hw_toput << slew_rate_max_hw;
  acceleration_min_hw_toput << acceleration_min_hw;
  acceleration_max_hw_toput << acceleration_max_hw;
  type_toput << type;
  db_data.push_back(base_toput);
  db_data.push_back(channel_toput);
  db_data.push_back(accu_min_toput);
  db_data.push_back(accu_max_toput);
  db_data.push_back(slew_rate_min_hw_toput);
  db_data.push_back(slew_rate_max_hw_toput);
  db_data.push_back(acceleration_min_hw_toput);
  db_data.push_back(acceleration_max_hw_toput);
  db_data.push_back(type_toput);

  device->put_property(db_data);

}