Visual C++ 2005 Sample Program
Add visa32.lib to the project library when building the following
sample programs.
Sample program of setting and queries (USB)
#include "stdio.h"
#include "string.h"
#include "visatype.h"
#include "visa.h"
// Serial number of the multifunction generator
#define serial "0123456"
int main()
{
ViSession defaultRm, instr;
// Create VISA ResourceManager object
ViStatus status = viOpenDefaultRM(&defaultRm);
if (status < VI_SUCCESS)
{
// Initialization error
return -1;
}
ViChar rsc[256];
// USB
sprintf(rsc, "USB0::0x0D4A::0x000F::%s::INSTR", serial);
ViAccessMode accessMode = VI_NO_LOCK;
ViUInt32 timeout = 0;
// Connect the device
viOpen(defaultRm, rsc, accessMode, timeout, &instr);
ViUInt32 count;
// Set the frequncy as 5.0 kHz, and ask the value
ViBuf buf = (ViBuf)":FREQ 5000;:FREQ?\n";
viWrite(instr, buf, (ViUInt32)strlen((ViPChar)buf), &count);
ViChar result[257];
viRead(instr, (ViPBuf)result, 256, &count);
result[count] = 0;
printf("result=[%s]\n", result);
// Close the device
viClose(instr);
viClose(defaultRm);
return 0;
}
Sample program of setting and queries (GPIB)
#include "stdio.h"
#include "string.h"
#include "math.h"
#include "visatype.h"
#include "visa.h"
int main()
{
ViSession defaultRm, instr;
// Create VISA ResourceManager object
ViStatus status = viOpenDefaultRM(&defaultRm);
if (status < VI_SUCCESS)
{
// Initialization error
return -1;
}
ViChar rsc[256];
// (GPIB address:2)
strcpy(rsc, "GPIB0::2::INSTR");
ViAccessMode accessMode = VI_NO_LOCK;
ViUInt32 timeout = 0;
// Connect the device
viOpen(defaultRm, rsc, accessMode, timeout, &instr);
ViUInt32 count;
// Set the Offset as 0.0V, Amplitude as 20.0Vp-p and Output as on,
// and ask the value
ViBuf buf = (ViBuf)":SOUR1:VOLT:OFFS 0V;:SOUR1:VOLT 20VPP;OUTP1 1;:SOUR1:VOLT?";
viWrite(instr, buf_rst, (ViUInt32)strlen((ViPChar)buf_rst), &count);
ViChar result[257];
viRead(instr, (ViPBuf)result, 256, &count);
result[count] = 0;
printf("result=[%s]\n", result);
// Close the device
viClose(instr);
viClose(defaultRm);
return 0;
}