在Delphi中使用NI的GPIB卡

一、准备工作

1. 安装硬件

安装PCI板到主板,启动机器。

2. 安装驱动

安装ni488225.exe,虽然开发环境不需要安装GPIB卡,但是程序运行时,还是需要相应的驱动dll文件,所以还是要安装,其中的nispy和communicator是很好的辅助工具。

 

二、编程接口

1. Delphi接口

Language Interface: 32-bit Borland Delph下载示例工程(包含接口单元),其中的dpib32单元就是ni4882的接口单元。

使用方法:

添加以下到uses当中即可。

Uses DPIB32;

2. VS接口

.NET Programming Instructions

Before you start using the NI-488.2 .NET API, you will need to add two assembly references to your C#/VB.NET project:

NationalInstruments.Common

NationalInstruments.NI4882

With the Microsoft .NET Framework version 1.1 or later, you can use NI-488.2 to create applications using Visual C# and Visual Basic .NET without Measurement Studio. You need Microsoft Visual Studio .NET 2003 for the API documentation to be installed.

The installed documentation contains the NI-488.2 API overview, concepts, and function reference. This help is fully integrated into the Visual Studio .NET documentation.

To view the NI-488.2.NET documentation, go to Start»Programs»Microsoft Visual Studio .NET 2003»Microsoft Visual Studio .NET 2003 Documentation. Under Contents, expand NI Measurement Studio Help»NI Measurement Studio .NET Class Library»Reference»NationalInstruments.NI4882 to view the function reference.

Expand NI Measurement Studio Help»NI Measurement Studio .NET Class Library»Using the Measurement Studio .NET Class Libraries to view conceptual topics for using NI-488.2 with Visual C# and Visual Basic .NET.

To get to the same help topics from within Visual Studio .NET 2003, go to Help»Contents. Select Measurement Studio from the Filtered By drop-down list and follow the previous instructions.

For Visual C# and Visual Basic .NET examples, go to the National InstrumentsMeasurementStudioVS2003DotNETExamplesGPIB subdirectory. This directory and the examples are added when you select the .NET Framework 1.1 Languages Support feature in the NI-488.2 Installer.

三、使用方法

一般的使用方法:

Initialization

Step 1. Open a Device

First use ibdev to open a device handle. The ibdev function requires the following parameters:

  • Connect board index (typically 0, for GPIB0)
  • Primary address for the GPIB instrument (refer to your instrument user manual)
  • Secondary address for the GPIB instrument (0 if the GPIB instrument does not use secondary addressing)
  • Timeout period (typically set to T10s, which is 10 seconds)
  • End-of-transfer mode (typically set to 1 so that EOI is asserted with the last byte of writes)
  • EOS detection mode (typically 0 if the GPIB instrument does not use EOS characters)

A successful ibdev call returns a device handle that is used for all device-level traditional NI-488.2 calls that communicate with the GPIB instrument.

Step 2. Clear the Device

Use ibclr to clear the device. This resets the device’s internal functions to the default state.

Device Communication

Step 3. Communicate with the Device

Communicate with the device by sending it a "*IDN?" query and then reading back the response. Many devices respond to this query by returning a description of the device. You must refer to the documentation that came with your GPIB device to see specific instructions on the proper way to communicate with it.

Step 3a.

Use ibwrt to send the "*IDN?" query command to the device.

Step 3b.

Use ibrd to read the response from the device.

Continue communicating with the GPIB device until you are finished.

Cleanup

Step 4. Place the Device Offline before Exiting Your Application

Use ibonl to put the device handle offline before you exit the application.

在实际Delphi编程中,ibrd中返回的buff要存在char 的array中,然后就可以转成string进行处理了。

当然,大部分都可以参考示例进行。

四、其他

涉及到的大部分资料,都可以从ni4882的帮助文件中获取,或者是ni的官方网站获得。

建议,首先从这两个地方获取所需资料。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据