The following example can be linked on any PC which has Online and Tango installed. It consists of Makefile, onlineDemo.c, onlineDemo.h and onlineCPP.cpp.
This is the Makefile:
SRC_DIR=/usr/local/experiment/Spectra/src TANGO_LIB = -L/usr/lib/x86_64-linux-gnu -ltango -llog4tango -lomniORB4 -lomniDynamic4 -lomnithread SIS3100_LIB=-L/usr/lib -l_sis3100 PYTHON_LIB=-L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 GPIB_LIB=-L/usr/lib -lgpib TINE_LIB=-L/usr/lib -ltinemt -ltbufsrv PERL_LIB=-Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lperl -ldl -lm -lpthread -lc -lcrypt LIB_DIR=/usr/local/experiment/Spectra/lib LIBS=$(SRC_DIR)/cmc_dummy.o \ $(SRC_DIR)/can_dummy.o \ -L$(LIB_DIR) -lgra -ltng_ifc -ladslib \ $(PERL_LIB) \ $(SIS3100_LIB) $(PYTHON_LIB) $(GPIB_LIB) $(TINE_LIB) \ -lnsl -ldl -lm -lc -lpthread -lstdc++ \ $(TANGO_LIB) -ljsoncpp \ -L/usr/X11R6/lib -lX11 all: onlineDemo onlineDemo.o: onlineDemo.c onlineDemo.h gcc -c -o onlineDemo.o -I/usr/local/experiment/Spectra/src onlineDemo.c onlineCPP.o: onlineCPP.cpp onlineDemo.h g++ -c -Wall -std=c++0x -I/usr/include/tango -o onlineCPP.o onlineCPP.cpp onlineDemo: onlineCPP.o onlineDemo.o g++ onlineDemo.o onlineCPP.o $(LIBS) -o onlineDemo
The main function:
/* file: onlineDemo.c ./onlineDemo -online -novme -nographic */ #include "onlineDemo.h" #include "gra_common.h" int main( int argc, char **arg, char **env) { void *p; char command[320]; char buffer[320]; double temp; int i; // // demonstrate some cpp code // getProxy( &p); exp_init( argc, arg); // // execute /online_dir/TkIrc.pl which loads online.xml // gra_perl( "init_tki", 0, 0); // // suppress logging output to stdout // gra_command( "set log off"); fprintf( stderr, "Say:\n 'bye' to finish \n"); fprintf( stderr, " 'exp' to call exp_input() \n"); fprintf( stderr, " '<command>', passed to gra_command() \n"); // // example for gra_decode_text() // gra_decode_text( "date()", buffer); fprintf( stdout, "date(): %s \n", buffer); // // example for gra_decode_int() // gra_decode_int( "2*3", &i); fprintf( stdout, "2*3: %d\n", i); // // example for gra_decode_double() // gra_decode_double( "gmup(d1_mot01)", &temp); fprintf( stdout, "gmup(d1_mot01): %g\n", temp); while(1) { command[0] = 0; read_line( "Enter> ", command, 0); fprintf( stdout, "\n"); //fprintf( stdout, "\nreceived <%s>\n", gra_ascii_format( command)); if( !strcmp( command, "bye")) { goto finish; } // // to start an interactive session // if( !strcmp( command, "exp")) { exp_input(); continue; } // // execute any command // gra_command( command); } finish: return 1; }
The header file:
// // file onlineDemo.h // #ifdef __cplusplus extern "C" int getProxy( void **p); #else int getProxy( void **p); #endif
The file onlineDemo.cpp:
// // file: onlineDemo.cpp // #include <iostream> #include <tango.h> #include "onlineDemo.h" using namespace std; int getProxy( void **p) { Tango::DeviceProxy *device = 0; Tango::DeviceAttribute da; Tango::DevDouble gain; try { device = new Tango::DeviceProxy( "p09/vfc/d1.01"); } catch( Tango::DevFailed &e) { cout << "error devFailed" << endl; fprintf( stderr, "error \n reason: %s \n desc: %s \n origin: %s \n", e.errors[0].reason.in(), e.errors[0].desc.in(), e.errors[0].origin.in()); return 0; } da = device->read_attribute( "gain"); da >> gain; cout << "vfc gain: " << gain << endl; *p = device; return 1; }