VC编程控制安捷伦电源

xiaoxiao2021-02-28  122

#include <stdio.h> /* for printf */ #include <stdlib.h> #include "StdAfx.h" #include"powertest.h" #include "C:\Program Files\IVI Foundation\VISA\Win64\agvisa\include\visa.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\n"); 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\n"); exit (-1); } /* Reset the instrument */ //viPrintf(instrumentHandle, "*RST\n"); /* turn on the output */ viPrintf(instrumentHandle, "OUTP 1\n"); /* Set output voltage (2V) and current (1A) levels, turn output on*/ //viPrintf(instrumentHandle, "VOLT %.5lg;:CURR %.5lg\n", 5.0, 1.0); /* Measure the dc voltage level at the output terminals */ //viQueryf(instrumentHandle, "MEAS:VOLT?\n", "%lf", &measvoltage); /* Measure the dc current level at the output terminals */ //viQueryf(instrumentHandle, "MEAS:CURR?\n", "%lf", &meascurrent); //printf ("Output Voltage = %f; Output Current = %f \n",measvoltage,meascurrent); /* configure dc source for dynamic measurements */ /* change sweep parameters */ viPrintf(instrumentHandle, "SENS:SWE:TINT %.5lg;POIN %ld;OFFS:POIN %ld\n", 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\"\n"); viPrintf(instrumentHandle, "TRIG:ACQ:LEV:CURR %.5lg\n", 0.092); viPrintf(instrumentHandle, "TRIG:ACQ:HYST:CURR %.5lg\n", 0.001); viPrintf(instrumentHandle, "TRIG:ACQ:SLOP:CURR POS\n"); viPrintf(instrumentHandle, "TRIG:ACQ:COUN:CURR %ld\n", 1); viPrintf(instrumentHandle, "TRIG:ACQ:SOUR INT\n"); /* initiate the acquisition system for measurement trigger */ printf ("Arm acquisition system...\n"); viPrintf(instrumentHandle, "INIT:NAME ACQ\n"); /* must allow time for pre-triggered samples */ printf ("Pre-trigger delay...\n"); //while(n*10) // n--; /* trigger the acquisition by changing the output voltage level to 5V */ printf ("Trigger acquisition...\n"); //viPrintf(instrumentHandle, "VOLT %.5lg\n", 5.0); /* fetch dynamic measurements from the same measurement data */ viQueryf(instrumentHandle, "FETCH:CURR?\n", "%lf", &resultDC); viQueryf(instrumentHandle, "FETCH:CURR:ACDC?\n", "%lf", &resultRMS); viQueryf(instrumentHandle, "FETCH:CURR:MAX?\n", "%lf", &resultMAX); viQueryf(instrumentHandle, "FETCH:CURR:MIN?\n", "%lf", &resultMIN); viQueryf(instrumentHandle, "FETCH:CURR:HIGH?\n", "%lf", &resultHIGH); viQueryf(instrumentHandle, "FETCH:CURR:LOW?\n", "%lf", &resultLOW); /* display measurement results */ printf("Dynamic voltage measurements:\n"); printf("dc=%f A\n rms=%f A\n max=%f A\n min=%f A\n high=%f A\n low=
转载请注明原文地址: https://www.6miu.com/read-30482.html

最新回复(0)