#include /* for printf */
#include
#include "StdAfx.h"
#include"powertest.h"
#include "C:Program FilesIVI FoundationVISAWin64agvisaincludevisa.h"
#pragma comment(lib,"C:\Program Files\IVI Foundation\VISA\Win64\agvisa\lib\msc\agvisa32.lib")
int n=10000;
char dc[40];
char rms[40];
char max[40];
char min[40];
char hig[40];
char low[40];
ViStatus powertest(void)
{
ViSession defRM, instrumentHandle;
ViStatus err;
ViReal64 measvoltage, meascurrent;
//ViReal64 resultDC, resultRMS, resultMIN, resultMAX, resultHIGH, resultLOW;
double resultDC, resultRMS, resultMIN, resultMAX, resultHIGH, resultLOW;
//char dc[10];
ViReal64 currArray[100];
ViInt32 i, numReadings ;
/* initialize the VISA session */
err = viOpenDefaultRM(&defRM);
if (err)
{
printf("viOpenDefaultRM error, check your hardware connections
");
exit (-1);
}
/* Open the instrument at address 5 for Communication */
err = viOpen(defRM, "GPIB0::16::INSTR", VI_NULL, 5000, &instrumentHandle);
if (err)
{
viClose(defRM);
printf("viOpen error, check the device at address 5
");
exit (-1);
}
/* Reset the instrument */
//viPrintf(instrumentHandle, "*RST
");
/* turn on the output */
viPrintf(instrumentHandle, "OUTP 1
");
/* Set output voltage (2V) and current (1A) levels, turn output on*/
//viPrintf(instrumentHandle, "VOLT %.5lg;:CURR %.5lg
", 5.0, 1.0);
/* Measure the dc voltage level at the output terminals */
//viQueryf(instrumentHandle, "MEAS:VOLT?
", "%lf", &measvoltage);
/* Measure the dc current level at the output terminals */
//viQueryf(instrumentHandle, "MEAS:CURR?
", "%lf", &meascurrent);
//printf ("Output Voltage = %f; Output Current = %f
",measvoltage,meascurrent);
/* configure dc source for dynamic measurements */
/* change sweep parameters */
viPrintf(instrumentHandle, "SENS:SWE:TINT %.5lg;POIN %ld;OFFS:POIN %ld
",
980.2E-6,/* sampling rate = 20us*/
2048, /* sweep size = 256 points */
-4); /* pre-trigger offset = 4 points (~125us) */
/* setup the voltage sensing triggered measurement parameters */
/* voltage trigger level to 2.75V */
/* hysteresis band to +/- 0.1V */
/* positive slope */
/* trigger count */
/* acquisition triggered by measurement */
viPrintf(instrumentHandle, "SENS:FUNC "CURR"
");
viPrintf(instrumentHandle, "TRIG:ACQ:LEV:CURR %.5lg
", 0.092);
viPrintf(instrumentHandle, "TRIG:ACQ:HYST:CURR %.5lg
", 0.001);
viPrintf(instrumentHandle, "TRIG:ACQ:SLOP:CURR POS
");
viPrintf(instrumentHandle, "TRIG:ACQ:COUN:CURR %ld
", 1);
viPrintf(instrumentHandle, "TRIG:ACQ:SOUR INT
");
/* initiate the acquisition system for measurement trigger */
printf ("Arm acquisition system...
");
viPrintf(instrumentHandle, "INIT:NAME ACQ
");
/* must allow time for pre-triggered samples */
printf ("Pre-trigger delay...
");
//while(n*10)
// n--;
/* trigger the acquisition by changing the output voltage level to 5V */
printf ("Trigger acquisition...
");
//viPrintf(instrumentHandle, "VOLT %.5lg
", 5.0);
/* fetch dynamic measurements from the same measurement data */
viQueryf(instrumentHandle, "FETCH:CURR?
", "%lf", &resultDC);
viQueryf(instrumentHandle, "FETCH:CURR:ACDC?
", "%lf", &resultRMS);
viQueryf(instrumentHandle, "FETCH:CURR:MAX?
", "%lf", &resultMAX);
viQueryf(instrumentHandle, "FETCH:CURR:MIN?
", "%lf", &resultMIN);
viQueryf(instrumentHandle, "FETCH:CURR:HIGH?
", "%lf", &resultHIGH);
viQueryf(instrumentHandle, "FETCH:CURR:LOW?
", "%lf", &resultLOW);
/* display measurement results */
printf("Dynamic voltage measurements:
");
printf("dc=%f A
rms=%f A
max=%f A
min=%f A
high=%f A
low=%fA
",resultDC, resultRMS, resultMAX, resultMIN, resultHIGH, resultLOW);
/* fetch first 10 data points from the measurement */
numReadings = 100;
viQueryf(instrumentHandle, "FETCH:ARR:CURR?
", "%,#lf%*t", &numReadings,
&currArray[0]);
for (i=0; iVs2010写的通过gpib调用visa库控制安捷伦电源66309 d的代码,这段代码是读取一段电流波形的平均值,最大值,最小值等,适用于模块的功率测试。