Programming instructions
Programming Examples
GPIB Programming Examples
Chapter 2 61
ViStatus viStatus = 0; // Declares a variable of type ViStatus
// for GPIB verifications
char rdBuffer[MAX_CNT]; // Declare a block of memory data
viStatus=viOpenDefaultRM(&defaultRM);// Initialize VISA session
if(viStatus < VI_SUCCESS){ // If problems, then prompt user
printf("ERROR initializing VISA... exiting\n");
printf("\n");
return -1; }
// 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("ERROR: Could not open communication with
instrument\n");
printf("\n");
return -1; }
viClear(vi); // Clears the signal generator
viPrintf(vi, "*RST\n"); // Resets signal generator
// Print program header and information
printf("** End of Sweep Service Request **\n");
printf("\n");
printf("The signal generator will be set up for a step sweep mode
operation.\n");
printf("An ’*’ will be printed while the instrument is sweeping. The end of
\n");
printf("sweep will be indicated by an SRQ on the GPIB and the program will
end.\n");
printf("\n");
printf("Press Enter to continue\n");
printf("\n");
getch();
viPrintf(vi, "*CLS\n"); // Clears signal generator status byte
viPrintf(vi, "STAT:OPER:NTR 8\n");// Sets the Operation Status Group
// Negative Transition Filter to indicate a
// negative transition in Bit 3 (Sweeping)
// which will set a corresponding event in
// the Operation Event Register. This occurs
// at the end of a sweep.
viPrintf(vi, "STAT:OPER:PTR 0\n");// Sets the Operation Status Group
// Positive Transition Filter so that no
// positive transition on Bit 3 affects the
// Operation Event Register. The positive
// transition occurs at the start of a sweep.
viPrintf(vi, "STAT:OPER:ENAB 8\n");// Enables Operation Status Event Bit 3
// to report the event to Status Byte
// Register Summary Bit 7.
viPrintf(vi, "*SRE 128\n"); // Enables Status Byte Register Summary Bit 7
// The next line of code indicates the
// function to call on an event