string_scalar

The following piece of code shows how the string_scalar attribute of the Tango test server is written and read. The Tango test server has to run for the device sys/tg_test/1.

#include <tango.h>
using namespace Tango;

main(unsigned int argc, char **argv)
{
  string attrName = "string_scalar"; 
  string str = "hello3"; 
  string str_out; 

  DeviceProxy *device = new DeviceProxy( "//has107k:10000/sys/tg_test/1");

  DeviceAttribute *da = new DeviceAttribute( attrName, str); 

  try 
    {
      device->write_attribute( *da); 
    }
  catch ( Tango::DevFailed &e)
    {
      fprintf( stderr, 
      	       "TangoTest, DevFailed exception \n attr: %s\n",
      	       attrName.c_str()); 
      fprintf( stderr, " reason:  %s \n desc:    %s \n origin:  %s \n", 
	       e.errors[0].reason.in(), 
	       e.errors[0].desc.in(), 
	       e.errors[0].origin.in());  
    }
  DeviceAttribute dd = device->read_attribute( attrName); 

  dd >> str_out; 
  cout << " received " << str_out << endl;
}