// // attrName contains the name of the attribute // extern "C" int tng_attrStringArrRd( DeviceProxy *device, char *attrName, int lenMax, char **value) { int status = 1; DeviceAttribute da; vector<string> str; try { da = device->read_attribute( (const char *) attrName); } catch ( Tango::DevFailed &e) { DbDevImportInfo info = device->import_info(); 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()); status = 0; goto finish; } if( da.has_failed()) { DevErrorList err = da.get_err_stack(); fprintf( stderr, " reason: %s \n desc: %s \n origin: %s \n", err[0].reason.in(), err[0].desc.in(), err[0].origin.in()); status = 0; goto finish; } try { da >> str; } catch ( Tango::WrongData &e) { strcpy( value[0], ""); status = 1; goto finish; } for( int i=0; i < (int) str.size(); i++) { if( i == (lenMax-1)) { fprintf( stderr, "tng_attrStringArrRd: too many strings, size %d, lenMax %d", str.size(), lenMax); status = 0; goto finish; } strcpy( value[i], str[i].c_str()); strcpy( value[i+1], ""); } finish: return status; } \section{... change between real and simulation mode} A device property called SimulationMode tells each process (device) if it has to run in simulation (value 1) or real (value 0) mode. This property has to be set to the value corresponding to the selected mode before the process is started, the process access to the Tango database at the initialization (function init$\_$device) reading the value that has been set. The property can be set using jive or any program accesing the Tango database. {bf Example of cpp code:} \begin{verbatim} include <tango.h> using namespace Tango; main(unsigned int argc, char **argv) { // // create a connection to the new IK220 TANGO device // DeviceProxy *device = new DeviceProxy( "tango://has107k:10000/exp/line1/enc1"); unsigned long simulation_mode = 1; DbDatum simulation_mode_toput("SimulationMode"); DbData db_data; simulation_mode_toput << simulation_mode; db_data.push_back(simulation_mode_toput); device->put_property(db_data); }
Example with python script:
# Before running this script TANGO_HOST has to be set to the host where this device run. # For example: export TANGO_HOST=has107k:10000 from PyTango import * db = Database() device = 'exp/line1/mcs1' db.put_device_property(device,{'SimulationMode':['1']}) # Add this property with this value