C# GPIB communication program has changed with the deprecation of the NI library

2020年9月9日

I recommend C # for instrument control. There are several ways to control instruments with C #, but I think the best way is GPIB. The interface device widely used in GPIB is a USB-GPIB conversion cable from National Instruments (NI), and I think this is the best.

However, recently NI has finished developing the GPIB library (VISA library) and has recommended the IVI Foundation library. The library used by GPIB is not provided from Ver 19 of the driver DVD (NI-488) provided by NI.

Therefore, the setup method has changed a little since 2019. This article will show you how to set up a new GPIB.

Drivers to install

This section describes the usage confirmed under the following conditions.

• Windows 10 Pro
• USB-GPIB-HS+
• Visual Studio 2019 （C#）
• Keysight 34461A

When you purchase USB-GPIB-HS +, as of January 2020, you will receive a Version 19 NI-488 driver DVD. Version 19 does not include NationalInstruments.Common and NationalInstruments.VisaNS, which were previously used for GPIB connections. When installing Version 19, you will use other library files.

To install the new library files, install the NI Package Manager on the NI-488 Driver DVD. This software is for managing files and drivers to be installed on the PC, so install with the default settings.

After installing the package manager and running it, you can install individual drivers and libraries. You can install each file individually, but I installed NI-VISA and NI-488.

Visual Studio Reference setting

Same as Version 19 or earlier, but add the two previously installed files to the Visual Studio reference settings. You can find additional instructions in the previous article, right-click on the reference in the Solution Explorer window and select Add Reference.

For version 19 or later adds the following two files.

• C:\Program Files (x86)\IVI Foundation\VISA\Microsoft.NET\Framework32\v2.0.50727\VISA.NET Shared Components 5.11.0\Ivi.Visa.dll
• C:\Program Files (x86)\IVI Foundation\VISA\Microsoft.NET\Framework32\v4.0.30319\NI VISA.NET 19.0\NationalInstruments.Visa.dll

Next, add the following to the beginning of the source code.

using Ivi.Visa;
using NationalInstruments.Visa;


Next, add the following to the beginning of the source code.

MessageBasedSession mbsession = (MessageBasedSession)(new ResourceManager()).Open("GPIB::10::INSTR");


Read, Write, and Dispose are as follows. Query is gone.

mbsession.RawIO.Write("*IDN?");
label.Text = mbsession.RawIO.ReadString();
mbsession.RawIO.Dispose();


These are the parts that have changed since Version 19. In addition to this, I think the buffer size and the method of setting the timeout period have also changed, but I think that there is no problem if you refer to the code so far. The problem is that the query command has been lost, so if you just replace the existing code, it will not work.

Conclusion

In this article, we introduced a new method because the C # code for GPIB communication has changed. The summary of the changes looks like this:

• Changing the referenced library file
• Changing “Using ~”
• Changing commands

Recently, NI’s GPIB related development was not very aggressive, so I thought the library would not be updated frequently. IVI Fundation will play a central role in GPIB driver development in the future, but I hope that there will be no problems.