User`s guide
97
Programming Your Instruments
Example Programs
Example: Simple Sine Waveform (Visual C++ and VISA)
This example program is intended for use with Microsoft Visual C++ 6.0 and
requires VISA to be installed. This program uses the arbitrary waveform
function to download and output a square wave pulse with a calculated rise
time and fall time. The waveform consists of 4000 points downloaded to the
function generator as ASCII data.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <visa.h>
#define CHECK(func)\
do {\
ViStatus _s = (func);\
if (_s < 0)\
{\
fprintf(stderr, "Error: %s returned %d\n", #func, _s);\
exit(0);\
}\
} while (0)
/* Specify the default address */
#define DEFAULT_LOGICAL_ADDRESS "GPIB0::10::INSTR"
void main()
{
ViSession viDefaultRM, Instrument;
ViRsrc TxtAddress = DEFAULT_LOGICAL_ADDRESS;
ViUInt32 actual;
char SCPIcmd[10000];
unsigned short i;
CHECK(viOpenDefaultRM(&viDefaultRM));
CHECK(viOpen(viDefaultRM, TxtAddress, VI_NULL, VI_NULL,
&Instrument));
/* Specify long seconds timeout for waveform download */
CHECK(viSetAttribute(Instrument, VI_ATTR_TMO_VALUE, 40000));
strcpy(SCPIcmd,"*RST\n"); /* Reset the function generator */
CHECK(viWrite(Instrument, SCPIcmd, (ViUInt32)strlen(SCPIcmd),
&actual));