Got my first program in Visual Studio C++ controlling the scope and reading the memory.
#include "VISA\WinNT\Include\visa.h"
#define NUM_CMDS 10
#define CMD_SIZE 64
static ViSession rmSession, scopeSession;
static ViFindList resourceList;
static ViUInt32 numResources;
static ViStatus status;
static char usbResource[VI_FIND_BUFLEN];
// Execute each command in a list
void run_commands(char commands[NUM_CMDS][CMD_SIZE])
{
int i;
for (i = 0; i < NUM_CMDS; i++)
{
status = viWrite(scopeSession, (ViBuf)commands[i], strlen(commands[i]), VI_NULL);
if (status != VI_SUCCESS)
{
printf("Error executing %s\n", commands[i]);
exit(-1);
}
}
}
void CRigolDlg::OnBnClickedScopemem()
{
// The list of commands
static char cmds[NUM_CMDS][CMD_SIZE] =
{ ":CHAN1:SCAL 0.1\n",
":CHAN1:BWL 20M\n",
":TIM:MAIN:SCAL 0.001\n",
":WAV:MODE RAW\n",
":WAV:SOUR CHAN1\n",
":WAV:STAR 1\n",
":WAV:STOP 10000\n",
":SING\n",
":RUN\n",
":TFOR\n" };
// Open session with the resource manager
status = viOpenDefaultRM(&rmSession);
if (status != VI_SUCCESS)
{
viClose(rmSession);
exit(1);
}
// Find USB resources
status = viFindRsrc(rmSession, "USB?*INSTR", &resourceList, &numResources, usbResource);
if (status != VI_SUCCESS)
{
viClose(rmSession);
exit(2);
}
// Open session to the resource
status = viOpen(rmSession, usbResource, VI_NULL, VI_NULL, &scopeSession);
if (status != VI_SUCCESS)
{
viClose(rmSession);
exit(3);
}
// Configure the device and start measurement
run_commands(cmds);
//viWrite(scopeSession, (ViBuf)cmds[6], strlen(cmds[6]), VI_NULL);
// Wait for the scope's measurement
Sleep(1000);
// Read the response
viWrite(scopeSession, (ViBuf)":STOP\n", 6, VI_NULL);
viWrite(scopeSession, (ViBuf)":WAV:DATA?\n", 11, VI_NULL);
viReadToFile(scopeSession, "wave.dat", 20000, VI_NULL);
// Close the session to the resource
viClose(scopeSession);
viClose(rmSession);
}