Hi there,
I am new to programming agilent devices thru VC++. Does anyone have the code to Generate a Standard(sine) wave on the waveform generator thru a VC++ or C++ program ?
Cheers,
MIshra
I am new to programming agilent devices thru VC++. Does anyone have the code to Generate a Standard(sine) wave on the waveform generator thru a VC++ or C++ program ?
Cheers,
MIshra
Create A newm project under "win32 console application"
Include Visa32.lib
#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <visa.h>
#include <visatype.h>
#include <vpptype.h>
#include <visaext.h>
#pragma warning(disable:4996)
#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 "USB0::0x0957::0x0407::MY44028438::0::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, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd,"*CLS\n"); /* Clear errors and status registers */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
/* Compute waveform */
fprintf(stderr, "Computing Waveform...\n");
strcpy(SCPIcmd, "DATA VOLATILE");
for(i = 1; i <= 5; i++) /* Set rise time (5 points) */
sprintf(SCPIcmd, "%s,%3.1f", SCPIcmd, (double)(i - 1)/5);
for(i = 6; i <= 205; i++)
strcat(SCPIcmd, ",1"); /* Set pulse width (200 points) */
for(i = 206; i <= 210; i++) /* Set fall time (5 points) */
sprintf(SCPIcmd, "%s,%3.1f", SCPIcmd, (double)(210 - i)/5);
for(i = 211; i <= 4000; i++)
strcat(SCPIcmd, ",0"); /* Set remaining points to zero */
strcat(SCPIcmd,"\n");
/* Doccwnload data points to volatile memory */
fprintf(stderr,"Downloading Arb...\n");
CHECK(viWrite(Instrument,(ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
fprintf(stderr,"Download Complete\n");
/* Set up arbitrary waveform and output */
strcpy(SCPIcmd,"DATA:COPY PULSE, VOLATILE\n");
/* Copy arb to non-volatile memory */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "FUNCtion:USER PULSE\n");
/* Select the active arb waveform */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "FUNCtion:SHAPe SQUARE\n");
/* Output the selected arb waveform */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "OUTPut:LOAD 50\n");
/* Output termination is 50 Ohms*/
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "FREQuency 5000;VOLTage 5\n");
/* Output frequency is5 kHz @ 5 Vpp */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "OUTPut ON\n");
/* Enable output */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
CHECK(viClose(Instrument));
CHECK(viClose(viDefaultRM));
}