Visual C++ 2005 Sample Program
Add visa32.lib to the project library when building the following sample programs.
@
Sample program of settings and queries
#include "stdio.h"
#include "string.h"
#include "visatype.h"
#include "visa.h"
// Serial number of the programmable AC/DC power source
#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];
sprintf(rsc, "USB0::0x0D4A::12::%s::INSTR", serial);
ViAccessMode accessMode = VI_NO_LOCK;
ViUInt32 timeout = 0;
// Connect the device
viOpen(defaultRm, rsc, accessMode, timeout, &instr);
ViUInt32 count;
// Set the frequency as 50.0Hz, and ask the value
ViBuf buf = (ViBuf)":FREQ 50.0;: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 transferring ARB data
#include "stdio.h"
#include "string.h"
#include "math.h"
#include "visatype.h"
#include "visa.h"
#define PI 3.141592654
// Serial number of the programmable AC/DC power source
#define serial "0000000"
int main()
{
ViSession defaultRm, instr;
// Create VISA ResourceManager object
ViStatus status = viOpenDefaultRM(&defaultRm);
if (status < VI_SUCCESS)
{
// Initialization error
return -1;
}
ViChar rsc[256];
sprintf(rsc, "USB0::0x0D4A::12::%s::INSTR", serial);
ViAccessMode accessMode = VI_NO_LOCK;
ViUInt32 timeout = 0;
// Connect the device
viOpen(defaultRm, rsc, accessMode, timeout, &instr);
// Create the waveform data
int buff[4096];
int i;
double p = 2 * PI / 2048;
for (i = 0; i < 4096; ++i)
{
buff[i] = (int)(sin(p * i) * 16383);
}
// Convert the message and the waveform data into byte data
ViChar data[9000] = ":TRACe ARB1,#48192";
int j = (ViUInt32)strlen((ViPChar)data);
for (i = 0; i < 4096; ++i)
{
ViChar b = (ViChar)((buff[i] >> 8) & 0x00FF);
data[j++] = b;
b = (ViChar)(buff[i] & 0x00FF);
data[j++] = b;
}
ViUInt32 count;
// Transfer the data
viWrite(instr, (ViBuf)data, j, &count);
// Close the device
viClose(instr);
viClose(defaultRm);
return 0;
}