44 Chapter 2
Programming Examples
GPIB Programming Examples
viPrintf(vi, "OUTP OFF\n"); // Turns source RF state off
viPrintf(vi, "OUTP?\n"); // Querys the signal generator's RF state
viScanf(vi, "%1i", &num); // Reads the response (integer value)
// Prints the on/off RF state
if (num > 0 ) {
printf("Source RF state is : on\n");
}else{
printf("Source RF state is : off\n");
}
// Close the sessions
viClose(vi);
viClose(defaultRM);
}
Generating a CW Signal Using VISA and C
This example uses VISA library functions to control the signal generator. The signal generator is set for a
CW frequency of 500 kHz and a power level of −2.3 dBm. Launch
Microsoft Visual C++ 6.0, add the required files, and enter the code into your .cpp source file.
The following program example is available on the PSG Documentation CD-ROM as visaex4.cpp.
//****************************************************************************************
// PROGRAM FILE NAME: visaex4.cpp
//
// PROGRAM DESCRIPTION: This example demonstrates query commands. The signal generator
// frequency and power level.
// The RF state of the signal generator is turn on and then the state is queried. The
// response will indicate that the RF state is on. The RF state is then turned off and
// queried. The response should indicate that the RF state is off. The query results are
// printed to the to the display window.
//
//****************************************************************************************
#include "StdAfx.h"