自动化技术得到飞跃发展的今天,测试中各种仪表也都支持IEEE 488协议,可以利用PC完成控制。在GPIB总线编程中,将总结过去用到的基于GPIB总线控制仪表的开发经验。首先总结一下Agent 663系列电源的控制。
开发工具 VC++6.0,必备文件:visa库。说到visa库,谈谈我对它的认识。VISA是虚拟仪器软件结构(Virtual Instrument Software Architectuere)的简称,是由VXI plug & play系统联盟所统一制定的I/O接口软件标准及其相关规范的总称。一般称这个I/O函数库为VISA库(用于仪器编程的标准I/O函数库)。VISA函数库驻留于计算机系统中,是计算机与仪器之间的标准软件通信接口,用以实现对仪器的控制。 VISA采用这种金字塔型的结构模型,为各种虚拟仪器系统软件提供了一个形式统一的I/O操作函数库,VISA将不同厂商的仪器软件统一于同一平台。
VISA的内部结构是一个先进的面向对象的结构,这一结构使得VISA与在它之前的I/O控制软件相比,接口无关性有很大提高。VISA的可扩展性使它远远超出了一般I/O控制软件的范畴,而且由于VISA内部结构的灵活性,使得VISA在功能和灵活性上也超过了其它I/O控制库。www.mulu001.com)
一般情况下,对稳压电源的操作有设置和读数两种。首先,需要将电源的各种参数设置到指定值。比如,输出电压、限流值、采样周期等。在获取电源地址和GPIB地址后,就可用visa函数对仪表进行操作:
//包含头文件:
#include "visa.h"
#include "visatype.h"
resource file中添加visa32.lib
//定义三个全局变量,接收仪表Handle
static ViSession Test_Handle;
static ViSession Default_Handle;
static ViSession Agilent_Handle;
int InitDCSource(int GPIBADD,int INSTRUMNETADD)
{
int status=-1;
char Temp[1024]="",*StrMatch;
if (viOpenDefaultRM(&Default_Handle) != 0)
{
return -1;
}
sprintf (Temp, "GPIB%d::%d::0::INSTR",GPIBADD,INSTRUMNETADD);
if (viOpen (Default_Handle, Temp, VI_NULL, VI_NULL, &Test_Handle) != 0)
{
viClose(Default_Handle);
return -1;
}
viSetAttribute(Test_Handle, VI_ATTR_TMO_VALUE, 20000); //必须足够长
viPrintf (Test_Handle,"*RST/n");
viQueryf (Test_Handle, "*IDN?/n","%100c", Temp);
return 1;
}
//设置电压、电流
int Set_Agilent_DC_SOURCE_Instrument(int handle,double voltage,double Current_LIM)
{
ViStatus viStatus;
Agilent_Handle=handle;
viStatus = viPrintf(Agilent_Handle, "VOLT %f/n", voltage); //设置输出电压
viStatus = viPrintf(Agilent_Handle, "CURR %f/n", Current_LIM); //电流
viPrintf (Agilent_Handle,"CURR:PROT:STAT ON /n");
viPrintf(Agilent_Handle, "OUTP ON/n");
return 0;
}
//读取电流
double Read_Agilent_Current(int mode)
{
char Temp[124]="";
double currentvalue;
ViStatus viStatus;
switch(mode)
{
case 1:
viStatus = viQueryf(Agilent_Handle, "MEAS:CURR?/n", "%lf", ¤tvalue);//读取平均值
break;
case 2:
viStatus = viQueryf(Agilent_Handle, "MEAS:CURR:MAX?/n", "%lf", ¤tvalue);//读取最大值
break;
case 3:
viStatus = viQueryf(Agilent_Handle, "MEAS:CURR:MIN?/n", "%lf", ¤tvalue);//读取最小值
break;
}
if(viStatus!=VI_SUCCESS) return -1;
else return currentvalue;
}
//设置输出使能
int Set_Agilent_Out_Put_Status(int Status)
{
if(Status==1)viPrintf(Agilent_Handle, "OUTP ON/n");
else if(Status==0)viPrintf(Agilent_Handle, "OUTP OFF/n");
else return -1;
}
吉时利电源的代码如下:
static ViSession Keithley_Handle;
int Init_Keithley_DC_SOURCE(int handle)
{
Keithley_Handle=handle;
viPrintf(Keithley_Handle, "SENS:FUNC 'CURR'/n");
viPrintf (Keithley_Handle,"OUTP1 ON/n");
return 0;
}
int Init_Keithley_DC_SOURCE_Instrument(int handle,double voltage,double Current_LIM)
{
ViStatus viStatus;
Keithley_Handle=handle;
viStatus = viPrintf(Keithley_Handle, "SOUR1:VOLT %5.1f/n", voltage); //设置输出电压
viStatus = viPrintf(Keithley_Handle, "SOUR1:CURR %5.1f/n", Current_LIM); //设置输出电压
viPrintf(Keithley_Handle, "SENS:NPLC 1/n");
viPrintf(Keithley_Handle, "SENS:AVER 1/n");
viPrintf(Keithley_Handle, "SENS:FUNC 'CURR'/n");
viPrintf (Keithley_Handle,"OUTP1 ON/n");
return 0;
}
double Read_Keithley_Current()
{
double currentvalue;
ViStatus viStatus;
viStatus = viQueryf(Keithley_Handle, "Read?/n", "%lf", ¤tvalue);
if(viStatus!=VI_SUCCESS) return -1;
return currentvalue;
}
int Set_Keithley_Out_Put_Status(int Status)
{
ViStatus viStatus;
if(Status==1)
{
viStatus = viPrintf(Keithley_Handle,"SOUR1:VOLT %f/n",dKeithleyVoltage);
viPrintf (Keithley_Handle,"OUTP1 ON/n");
}
else if(Status==0) viPrintf (Keithley_Handle,"OUTP1 OFF/n");
else return -1;
}
上述就是简单的设置参数,读取电流的代码。详细的介绍还得参考仪表的相关文档,这一般在仪表厂家的网站上可下载