Appendix 3. Programming Examples
Example. Program Written in C
The following program shows the control over the Analyzer using the C language
with the VISA library.
The Analyzer address is passed as parameter in the command line at the start of the
program. For more detail on VISA Resource Name see the VISA library
documentation.
Program description:
1. Sets up the communication with the Analyzer.
2. Reads out and displays the Analyzer information string.
3. Sets some parameters of the Analyzer.
4. Triggers the measurement and waits for the sweep completion.
5. Reads out the measurement data and the frequency values at the measurement
points.
6. Displays the measurement data
// Example.cpp
//
// VISA Header: visa.h (must be included)
// VISA Library: visa32.lib (must be linked with)
#include "stdafx.h"
#include "visa.h"
int main(int argc, char* argv[])
{
ViStatus status; // Error checking
ViSession defaultRM, instr; // Communication channels
ViUInt32 retCount; // Return count from string I/O
ViByte buffer[255]; // Buffer for string I/O
ViUInt32 temp;
int NOP = 21; // Number of measurement points
const int maxCnt = 100; // Maximum reading count
double Data[maxCnt*2]; // Measurement data array
double Freq[maxCnt]; // Frequency array
if (argc < 2)
{
printf("\nUsage: Example <VISA address>\n\n");
printf("VISA address examples:\n");
printf(" TCPIP::nnn.nnn.nnn.nnn::5025::SOCKET\n");
printf(" TCPIP::hostname::5025::SOCKET\n");
return –1;