241
Appendix
3.
Programming
Examples
Example
1.
Program
Written
in
C
The
following
program
shows
the
control
over
the
instrument
using
the
C
language
with
the
VISA
library.
The
instrument
can
be
connected
via
Ethernet
using
VXI–11
protocol.
The
instrument
address
is
assigned
in
VISA
Resource
Name
format
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
instrument.
2.
Reads
out
and
displays
the
instrument
information
string.
3.
Sets
some
parameters
of
the
instrument.
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
//
Example1.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
int
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:
Example4
<VISA
address>\n\n"
);
printf(
"VISA
address
examples:\n"
);
printf(
"
TCPIP::nnn.nnn.nnn.nnn::INSTR\n"
);
printf(
"
TCPIP::devicename::INSTR\n"
);
return
–1;
}
status
=
viOpenDefaultRM(&defaultRM);