最近在做一个项目,关于TR组件自动测试系统,其中对测试系统仪器的设置,想底层用IVI 来实现,新的仪器大多支持lan口,厂家都自带IVI 驱动程序,只要按指定步骤就能实现多个厂家的IVI 仪器设置,实现同类仪器的可互换性。
本项目中用到示波器、频谱仪、宽带信号源、微波信号源等仪器。下面讲一下开发IVI 步骤:
1、首先要对IVI 有所了解,IVI 相关信息可从下面网址获得:http://www.ivifoundation.org/default.aspx
- overview 中大家可以学习IVI 的定义,了解IVI 的好处。
The IVI standards define an open driver architecture, a set of instrument classes, and shared software components. Together these provide critical elements needed for instrument interchangeability.
- IVI 的结构如下图所示:
IVI 驱动类型有IVI-C 、IVI-COM的,驱动程序通过I/O库和硬件通信,两种支持的上层开发语言不太一样,本人用C#开发因此项目中所有IVI 驱动都选择IVI-COM类型的。
Driver API
To support all popular programming languages and development environments, IVI drivers provide either a IVI-C or an IVI-COM API. Driver developers may provide both interfaces, as well as wrapper interfaces optimized for specific development environments.
Instrument I/O
All IVI drivers communicate to the instrumentation hardware through an I/O Library. The VISA library is used for the GPIB and VXI buses, while other buses can either utilize VISA or another library.
Shared Components
IVI Foundation members have cooperated to provide common software components, called IVI shared components, that ensure multi-vendor system compatibility. These components provide services to drivers and driver clients that need to be common to all drivers. For instance, the IVI Configuration Server enables administration of system-wide configuration.
2、IVI 驱动程序下载
All Classes
Custom
IviACPwr
IviCounter
IviDCPwr
IviDigitizer
IviDmm
IviDownconverter
IviFgen
IviPwrMeter
IviRFSigGen
IviScope
IviSpecAn
IviSwtch
IviUpconverter
上面是目前IVI 支持的几种IVI仪器类。
IVI shared components 在该网站是可以下载的,对于大家平时用的仪器应该是安捷伦的比较多,安捷伦的网站上软件下载可下载
IO Libraries Suite 16.3 Update 2
http://www.home.agilent.com/agilent/software.jspx?cc=CN&lc=chi&nid=-33330.977662&id=2175637
该IO库中下载安装后会自动安装IVI Shared Component 组件。
IVI Shared Component主要支持多厂家的仪器的一致性。安装完I/O库后,就需要安装各个仪器的IVI 驱动程序了。大家可能会问:我怎么知道我用的仪器是否支持IVI 呢?有IVI 驱动吗? 这个大家可以从http://www.ivifoundation.org/default.aspx 网站的"Driver Registry" 页面去查看,但凡支持IVI的厂商仪器的IVI 驱动都会列出来,只要从这个列表里查找是否有你要的IVI-C 或IVI-COM 驱动,再点击链接进入相关厂商官网去下载对应驱动程序。
例如查找泰克的AWG7122C 的IVI 驱动,得到结果如下图示:
3、安装驱动程序,按照驱动帮助文件逐个配置开发环境,添加指定COM 引用,进入开发调用,此项目用C#开发,都以C# 为例。
记住安装软件的顺序:
先安装IO Libraries Suite 库,再安装单个仪器的IVI 驱动,已经下载了泰克AWG7122C 的IVI 驱动,安装后大家可以打开C:\Documents and Settings\All Users\Application Data\IVI Foundation\IVI\IviConfigurationStore.xml ,IviConfigurationStore文件中会看到相应驱动信息
并且相应IVI 安装路径下也会驱动安装文件和帮助信息:C:\Program Files\IVI Foundation\IVI\Drivers\TekFgen
该目录下有帮助文件打开之后会有详细介绍驱动程序开发步骤,需要引入的COM组件,以及简单的调用例子,如图所示:
4、编写IVI IviConfigurationStore.xml 文件
参考帮助文档基本上就能开始编写调用IVI 驱动接口的程序了,在写程序中你会发现,在介绍可互换编程时,例子里面提到 "MyLogicalName",这个很重要,需要我们提前做好的一步,就是还需要编写上面提到的:IviConfigurationStore.xml 文件。
// If true, this will query the instrument model and fail initialization
// if the model is not supported by the driver
bool idQuery = false;
// If true, the instrument is reset at initialization
bool reset = false;
// Setup IVI-defined initialization options
string standardInitOptions =
"Cache=true, InterchangeCheck=false, QueryInstrStatus=true, RangeCheck=true, RecordCoercions=false, Simulate=false";
// Setup driver-specific initialization options
string driverSetupOptions =
"DriverSetup= Model=AWG7052, Trace=false";
fgen.Initialize("MyLogicalName", idQuery, reset, standardInitOptions + "," + driverSetupOptions)
在调用每个驱动时都要传入一个logicName ,它是写在配置文件IviConfigurationStore中,调用过程会从这个文件读取相关设备物理地址,使用的驱动信息等。
下面是简单的调用泰克AWG7122C 的C# 程序和配置文件例子:
C# 程序调用:(初始化实例,并且调用产生一个正弦波形)
IIviSessionFactory factory = new IviSessionFactoryClass();
;
IIviFgen siggen = (IIviFgen)factory.CreateDriver("AWG7122C");//logicName ----AWG7122C
try
{
siggen.Initialize("AWG7122C", false, false, "");
// Get a string property
string description = siggen.Identity.Description;
siggen.InitiateGeneration();
siggen.Arbitrary.Waveform.Configure("Ch1,", 0x00000001, 0.1, 0.2);//配置通道1 输出波形, 0x00000001----波形数字
siggen.Arbitrary.SampleRate = 24;
siggen.Trigger.InternalRate = 0.3;
siggen.Output.set_OperationMode("Ch1", IviFgenOperationModeEnum.IviFgenOperationModeContinuous);
siggen.Output.set_Enabled("Ch1", true);
siggen.Trigger.SendSoftwareTrigger();
// Close the session
siggen.Close();
return true;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
对应配置文件设置:HardwareAssets、 DriverSessions、LogicalNames这几部分是需要自己手动添加的项,IOResourceDescriptor 是指通过 Aglient Connection Expert 所发现的VISA String。至于相关信息的细节解释大家可以参考http://www.ivifoundation.org/default.aspx 上的Specifications 页面中的
IVI Specifications 文档。
<HardwareAssets>
<IviHardwareAsset id="p179">
<Name>AWG7122C</Name>
<Description>Resource Name for Arbitrary Waveform Generators</Description>
<DataComponents/>
<IOResourceDescriptor>TCPIP0::AWG-3289382193::inst0::INSTR</IOResourceDescriptor>
</IviHardwareAsset>
</HardwareAssets>
<DriverSessions>
<IviDriverSession id="p183">
<Name>AWG7122C</Name>
<Description>Logic Name for Arbitrary Waveform Generators</Description>
<DataComponents/>
<IviHardwareAsset idref="p179"/>
<IviSoftwareModuleRef idref="p176"/>
<VirtualNames/>
<SoftwareModuleName>AWG7122C</SoftwareModuleName>
<Cache>0</Cache>
<DriverSetup/>
<InterchangeCheck>0</InterchangeCheck>
<QueryInstrStatus>0</QueryInstrStatus>
<RangeCheck>0</RangeCheck>
<RecordCoercions>0</RecordCoercions>
<Simulate>0</Simulate>
</IviDriverSession>
</DriverSessions>
<LogicalNames>
<IviLogicalName id="p187">
<Name>AWG7122C</Name>
<Description>Logic Name for Arbitrary Waveform Generators</Description>
<IviDriverSession idref="p183"/>
</IviLogicalName>
</LogicalNames>
试了一下终于通了。所以记录一下,作个总结。
IVI 技术在自动测试系统中的应用研究