Chapter 2 57
Programming Examples
GPIB Programming Examples
// Open session to GPIB device at address 19
viStatus=viOpen(defaultRM, "GPIB::19::INSTR", VI_NULL, VI_NULL, &vi);
if(viStatus){ // If problems, then prompt user
printf("Could not open ViSession!\n");
printf("Check instruments and connections\n");
printf("\n");
exit(0);}
printf("\n");
viClear(vi);// Clears the signal generator
// Prints user information
printf("Programming example to demonstrate reading the signal generator's
Status Byte\n");
printf("\n");
printf("Manually set up the sig gen for an unleveled output condition:\n");
printf("* Set signal generator output amplitude to +20 dBm\n");
printf("* Set frequency to maximum value\n");
printf("* Turn On signal generator's RF Output\n");
printf("* Check signal generator's display for the UNLEVEL annuniator\n");
printf("\n");
printf("Press Enter when ready\n");
printf("\n");
getch(); // Waits for keyboard user input
viPrintf(vi, "STAT:QUES:POW:ENAB 2\n"); // Enables the Data Questionable
// Power Condition Register Bits
// Bits '0' and '1'
viPrintf(vi, "STAT:QUES:POW:COND?\n"); // Querys the register for any
// set bits
viScanf(vi, "%s", rdBuffer); // Reads the decimal sum of the
// set bits
num=(int (rdBuffer[1]) -('0')); // Converts string data to
// numeric