#include "stdafx.h"
/*idn.c
This example program queries a GPIB device for an identification string
and prints the results. Note that you must change the address.
*/
#include
#include "C:\Program Files\IVI Foundation\VISA\WinNT\agvisa\include\visa.h"
#pragma comment(lib,"C:\\Program Files\\IVI Foundation\\VISA\\WinNT\\agvisa\\lib\\msc\\agvisa32.lib")
#include
void main () {
ViSession defaultRM, vi;
char buf [256] = {0};
/* Open session to GPIB device at address 22 */
viOpenDefaultRM (&defaultRM);
viOpen (defaultRM, "GPIB0::22::INSTR", VI_NULL,VI_NULL, &vi);
/* Initialize device(Reset) */
viPrintf (vi, "*RST\n");
/* Send an *IDN? string to the device */
viPrintf (vi, "*IDN?\n");
/* Read results */
viScanf (vi, "%t", &buf);
//viQueryf(vi, "*IDN?\n","%t",%buf);//上两条语句可用此条代替
/* Print results */
printf ("Instrument identification string: %s\n", buf);
//信号源---特定的信号源可能命令不一样,需要参考编程文档
int freq=999;
viPrintf(vi, "FREQ %dMHz\n",freq);
viPrintf(vi, "POW 0dBm\n");
viPrintf(vi, "OUTP ON\n"); //RF ON
viPrintf(vi, "MOD ON\n"); //调制开
//频谱仪
viPrintf(vi, "SYST:DISP:UPDate ON\n");//屏幕显示,不显示速度较快
viPrintf(vi, "FREQ:CENT 999MHz\n");
viPrintf(vi, "FREQ:SPAN 10MHz\n");
viPrintf(vi, "CALC:MARK:AOFF\n");
viPrintf(vi, "SWE:TIME 2s\n");//扫描时间
viPrintf(vi, "SYST:PSAVE ON\n");//省电模式
viPrintf(vi, "DISP:TRAC:Y:RLEV 10dBm\n");
viPrintf(vi, "DISP:WIND:TRAC:Y:RLEV:OFFS 10dB\n");
viPrintf(vi, "CALC:MARK:X 999MHz\n");//MARK ON
viPrintf(vi, "BAND:RES 100kHz\n");//RBW
viPrintf(vi, "BAND:VID 300kHz\n");//VBW
//自动校准需要单次扫描,连续扫描不准确
viPrintf(vi, "INIT:CONT OFF\n");
//WAI用于同步,还有OPC等也可用于同步,仅用于overlapping command,sequential command
//无用,不过用
viPrintf(vi, "INIT:IMM;*WAI\n");
viPrintf(vi, "CALC:MARK:MAX\n");
//读取mark的值
viQueryf(vi, "CALC:MARK:Y?\n","%t",buf);
printf("The mark value is:%s.\n",buf);
//功率计
viPrintf(vi, "SENS:CORR:OFFS 31\n");//外部补偿电平 db!!!!ok
viPrintf(vi, "DISP:TRAC:VCENT 55dBm\n");//参考电平
viPrintf(vi, "TRIG:LEV 40dBm\n");//触发电平 dBm
viPrintf(vi, "TRIG:DEL 0\n");//触发事件位置us ns/div us/div ms/div
viPrintf(vi, "DISP:PULS:TIMEBASE 10us\n");//时间单位 (moren s) 100us
viPrintf(vi, "DISP:TRAC:VSCALe 5dB\n");//db/格 db dBm,dBV,dBmV,dbuV dBuV
//网分仪
viPrintf(vi, "SYST:DISP:UPDate ON\n");
viPrintf(vi, "SWE:COUnt 12\n");
viPrintf(vi, "CALC:PAR:SEL 'CH1_S11_1'\n");
viPrintf(vi, "CALC:PAR:DEF 'My_S11',s11\n");
//////
viPrintf(vi, "CALCulate1:PARameter:SELect 'Ch1Trc2' 'S21'\n");
viPrintf(vi, "SYST:DISP:UPDate ON\n");
viPrintf(vi, "CALC:FORM PHAS\n");
viPrintf(vi, "FORMat ASCII\n");
viQueryf(vi, "INITiate1:CONTinuous OFF;*OPC?\n","%s", buf);
viPrintf(vi, "SENS1:FREQ:STAR 1000MHz\n");
viPrintf(vi, "SENS1:FREQ:STOP 1125MHz\n");
viPrintf(vi, "SENS1:SWE:POIN 126\n");
viPrintf(vi, "OUTP1 OFF\n");
viPrintf(vi, "SOUR:POW -7\n");
viPrintf(vi, "CALC1:MARK1 ON\n");
//////////////////////////////////////////////////////
/* Close session */
viClose(vi);
viClose(defaultRM);
while(1);//pause for see the result.
}
//只是调用API(头文件visa.h,库agvisa32.lib),API常用的就是几个,
//viOpenDefaultRM,viOpen,viPrintf,viQueryf,viClose ,,,
//还有viSetAttribute,viScanf,
//主要是SCPI命令,大多是标准化的,查查文档即可。
/* 自动搜索仪器,根据*IDN知道什么仪器
ViChar buffer[255];
ViRsrc mathes=buffer;
ViUInt32 nmatched;
ViFindList list;
viFindRsrc(defaultRM,"GPIB?*INSTR",&list,&nmatched,
matched);
viFindNext(list,matches);
viFindNext(list,matches);
...
viClose(list);
//*/