This section describes how to write your first VISA.NET program. It assumes that you have installed Keysight IO Libraries Suite, and that all hardware and software requirements have been met. See the IO Libraries Suite Readme or the IO Libraries Suite web page at www.keysight.com/find/iosuite for system requirements and revision information.
The sample assumes that you have an instrument that uses a standard SCPI command set. Though the sample assumes a specific GPIB address for the instrument, you can tweak the sample to make it work with almost any SCPI instrument that uses I/O connections supported by Keysight IO Libraries Suite – for example, GPIB, LAN, USB, or serial. Almost any SCPI instrument created in the last twenty years will work.
Additional sample programs may be found at http://www.keysight.com/find/iosuite. (Click Visit Technical Support, then click Drivers, Firmware & Software, then Programming Example.)
As the first step in creating any program that uses VISA.NET, you must:
The sample assumes that you have connected an IEEE 488.2 instrument that responds to a *IDN? command with a string that describes the instrument manufacturer and model (and optionally a firmware revision and serial number).
Using Keysight Connection Expert (part of Keysight IO Libraries Suite), configure this instrument with an alias, MyInstr. All of the samples in this help address the instrument using this alias.
For example, if you have connected an instrument to your PC using a GPIB connection, Connection Expert will list the instrument as soon as it is discovered. If you look at the instrument's details, you will see its VISA address, which will look something like GPIB0::22::0::INSTR. You can assign the MyInstr alias by clicking Add or Change Aliases on the right side of the window.
The Getting Started sample is a C# program developed in Visual Studio 2013. C# is one of several languages that may be used for .NET programming, and an overall good choice because of its familiarity to many in the scientific and technical communities.
Start Visual Studio and select File > New > Project... from the main menu. When the New Project dialog box opens, expand Visual C# in the list in the left pane, and then select Windows Desktop (Windows in older versions of Visual Studio). In the center pane, select Console Application. Type IdnSample in the Name: and Solution name: boxes and select a suitable location. Click OK to create the project.
Once the project is created, Visual Studio opens a window and displays the default C# source code file program.cs.
You must add project references to the VISA.NET assemblies before the C# program can use VISA.NET.
To add the references, first make sure that the Solution Explorer pane is open. By default, this pane appears on the right side of the Visual Studio window. If it is not open, select View > Solution Explorer from the main menu to open it.
The solution is at the top level of the Solution Explorer window, with the IdnSample project directly below it. Right-click the References node under the IdnSample project and click Add Reference. Visual Studio opens the Reference Manager dialog box. Select Assemblies from the list in the left pane, and then select Extensions. Select Ivi.Visa and Keysight.Visa from the list by highlighting them and then checking the box to the left of each, then click OK to add the references to the project. This adds references to the IVI VISA.NET and Keysight VISA.NET assemblies, respectively. Note that the process for adding a reference is slightly different in previous versions of Visual Studio – refer to the MSDN documentation for instructions.
The last bit of preparation allows the C# program to access items in the VISA.NET assemblies. To do this, add the following lines of code to program.cs just under the other using statements.
| using Statements |
Copy Code |
|---|---|
|
using Ivi.Visa; using Keysight.Visa; | |
Now that the necessary preparation is done, you can add the sample code.