找到一个并使用它来使用VC ++ 2008Create在“win32控制台应用程序”下的一个newm项目包括Visa32.lib #include“stdafx.h”#include #include #include #include #include #include #include #pragma warning(disable:
4996)#define CHECK(func) do { ViStatus _s =(func); if(_s { fprintf(stderr,“错误:%s返回%d n”,#func,_s); exit(
0); } } while(0)/ *指定默认地址* / #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)); / *指定long
波形下载的秒超时* / CHECK(viSetAttribute(Instrument,VI_ATTR_TMO_VALUE,40000)); strcpy(SCPIcmd,“* RST n”); / *重置函数发生器* / CHECK(viWrite(Instrument,(ViBuf)SCPIcmd,
(ViUInt32)strlen的(SCPIcmd),安培;实际)); strcpy的(SCPIcmd,”
* CLS n“);
/ *清除错误和状态寄存器* / CHECK(viWrite(仪器,(ViBuf)SCPIcmd,(ViUInt32)strlen(SCPIcmd),& actual)); / *计算波形* / fprintf(stderr,“计算波形......
n“); strcpy(SCPIcmd,”DATA VOLATILE“); for(i = 1; i
以上来自于谷歌翻译
以下为原文
Found one and got it to work with VC++ 2008
Create A newm project under "win32 console application"
Include Visa32.lib
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
#pragma warning(disable:4996)
#define CHECK(func)
do {
ViStatus _s = (func);
if (_s < 0)
{
fprintf(stderr, "Error: %s returned %dn", #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,"*RSTn"); /* Reset the function generator */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd,"*CLSn"); /* 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 Completen");
/* Set up arbitrary waveform and output */
strcpy(SCPIcmd,"DATA:COPY PULSE, VOLATILEn");
/* Copy arb to non-volatile memory */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "FUNCtion:USER PULSEn");
/* Select the active arb waveform */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "FUNCtion:SHAPe SQUAREn");
/* Output the selected arb waveform */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "OUTPut:LOAD 50n");
/* Output termination is 50 Ohms*/
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "FREQuency 5000;VOLTage 5n");
/* Output frequency is5 kHz @ 5 Vpp */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
strcpy(SCPIcmd, "OUTPut ONn");
/* Enable output */
CHECK(viWrite(Instrument, (ViBuf)SCPIcmd, (ViUInt32)strlen(SCPIcmd),&actual));
CHECK(viClose(Instrument));
CHECK(viClose(viDefaultRM));
}