Chapter 6 Application Programs

C++ Example for GPIB(IEEE 488)

...continued

/* Open communication (session) with power supply */ viOpenDefaultRM (&defaultRM);

viOpen (defaultRM, Visa_address, 0,0, &power_supply);

/* Query the power supply id, read response and print */ viPrintf (power_supply, "*IDN?\n");

viScanf (power_supply, "%s", &reply_string);

 

printf ("Instrument identification string:\n

%s\n\n", reply_string);

/* Initialize Power Supply */ viPrintf (power_supply, "*RST\n"); viPrintf (power_supply, "Current 2\n"); viPrintf (power_supply, "Output on\n");

printf("Voltage Current\n\n");

/* Set power on condition

*/

/* Set Current

limit to 2A

*/

/*

Turn output

on

*/

/*

Print heading

*/

/* Step from 0.6v to 0.8 volt in .02volt steps */

 

 

for(voltage =.6;voltage <<=.8001;voltage +=.02)

 

 

{

 

 

 

viPrintf (power_supply, "Volt %f\n",voltage);

/*set voltage

*/

printf("%.3f",voltage);

/* print power supply setting */

delay(500);

/* allow output to settle for 500 msec */

viPrintf(power_supply,"Measure:Current?\n");

/*measure output current

*/

viScanf (power_supply, "%lf",¤t);

/* retrieve reading

*/

printf("

%.3lf\n",current);

/* print reading

*/

}

 

 

 

viPrintf (power_supply, "Output Off\n");

/* turn off output

*/

/* Close communication session */

 

 

viClose (power_supply); viClose (defaultRM);

}

/* Pauses for a specified number of milliseconds. */ void delay( clock_t wait )

{

clock_t goal; clock_t delay; wait = wait/1000;

delay = (clock_t)wait * CLOCKS_PER_SEC; goal = delay + clock();

while( goal > clock() );

}

End of Program

134

Page 135
Image 135
Agilent Technologies E3632A manual Application Programs ++ Example for Gpibieee, End of Program 134