Programming instructions

Programming Examples
GPIB Programming Examples
Chapter 2 53
Generating a Step-Swept Signal Using VISA and C
In this example the VISA library is used to set the signal generator for a continuous step
sweep on a defined set of points from 500 MHz to 800 MHz. The number of steps is set for 10
and the dwell time at each step is set to 500 ms. The signal generator will then be set to local
mode which allows the user to make adjustments from the front panel. Launch Microsoft
Visual C++ 6.0, add the required files, and enter the following code into your .cpp source file.
The following program example is available on the ESG Documentation CD-ROM as
visaex7.cpp.
//****************************************************************************************
// PROGRAM FILE NAME:visaex7.cpp
//
// PROGRAM DESCRIPTION:This example will program the signal generator to perform a step
// sweep from 500-800 MHz with a .5 sec dwell at each frequency step.
//
//****************************************************************************************
#include <visa.h>
#include "StdAfx.h"
#include <iostream>
void main ()
{
ViSession defaultRM, vi; // Declares variables of type ViSession
// vi establishes instrument communication
ViStatus viStatus = 0; // Declares a variable of type ViStatus
// for GPIB verifications
viStatus=viOpenDefaultRM(&defaultRM); // Initialize VISA session
// 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);}
viClear(vi); // Clears the signal generator
viPrintf(vi, "*RST\n"); // Resets the signal generator
viPrintf(vi, "*CLS\n"); // Clears the status byte register
viPrintf(vi, "FREQ:MODE LIST\n"); // Sets the sig gen freq mode to list
viPrintf(vi, "LIST:TYPE STEP\n"); // Sets sig gen LIST type to step
viPrintf(vi, "FREQ:STAR 500 MHz\n"); // Sets start frequency
viPrintf(vi, "FREQ:STOP 800 MHz\n"); // Sets stop frequency
viPrintf(vi, "SWE:POIN 10\n"); // Sets number of steps (30 mHz/step)
viPrintf(vi, "SWE:DWEL .5 S\n"); // Sets dwell time to 500 ms/step
viPrintf(vi, "POW:AMPL -5 dBm\n"); // Sets the power level for -5 dBm
viPrintf(vi, "OUTP:STAT ON\n"); // Turns RF output on