Ivi GSG C and VB 2011
Ivi GSG C and VB 2011
with
IVI Drivers
Your Guide to Using IVI with
Visual C# and Visual Basic .NET
Version 1.1
Chapter 1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Why Use an Instrument Driver? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Why IVI?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Why Use an IVI Driver? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Flavors of IVI Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Shared Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Download and Install IVI Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Familiarizing Yourself with the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3
Chapter 1
Introduction
••••••
Purpose
Welcome to Getting Started with IVI Drivers: Your Guide to Using IVI with
Visual C# and Visual Basic .NET. This guide introduces key concepts about IVI
drivers and shows you how to create a short program to perform a measurement.
The guide is part of the IVI Foundation’s series of guides, Getting Started with IVI
Drivers.
Getting Started with IVI Drivers is intended for individuals who write and run
programs to control test-and-measurement instruments. Each guide focuses on a
different programming environment. As you develop test programs, you face
decisions about how you communicate with the instruments. Some of your choices
include Direct I/O, VXIplug&play drivers, or IVI drivers. If you are new to using IVI
drivers or just want a quick refresher on the basics, Getting Started with IVI
Drivers can help.
Getting Started with IVI Drivers shows that IVI drivers can be straightforward,
easy-to-use tools. IVI drivers provide a number of advantages that can save time
and money during development, while improving performance as well. Whether
you are starting a new program or making improvements to an existing one, you
should consider the use of IVI drivers to develop your test programs.
So consider this the “hello, instrument” guide for IVI drivers. If you recall, the “hello
world” program, which originally appeared in Programming in C: A Tutorial, simply
prints out “hello, world.” The “hello, instrument” program performs a simple
measurement on a simulated instrument and returns the result. We think you’ll find
that far more useful.
4
the early 1990s a group of instrument manufacturers developed Standard
Commands for Programmable Instrumentation (SCPI). This defined set of
commands for controlling instruments uses ASCII characters, providing some
basic standardization and consistency to the commands used to control
instruments. For example, when you want to measure a DC voltage, the
standard SCPI command is “MEASURE:VOLTAGE:DC?”.
In 1993, the VXIplug&play Systems Alliance created specifications for instrument
drivers called VXIplug&play drivers. Unlike SCPI, VXIplug&play drivers do not
specify how to control specific instruments; instead, they specify some common
aspects of an instrument driver. By using a driver, you can access the instrument
by calling a subroutine in your programming language instead of having to format
and send an ASCII string as you do with SCPI. With ASCII, you have to create and
send the instrument the syntax “MEASURE:VOLTAGE:DC?”, then read back a
string, and build it into a variable. With a driver you can merely call a function called
MeasureDCVoltage( ) and pass it a variable to return the measured voltage.
Although you still need to be syntactically correct in your calls to the instrument
driver, making calls to a subroutine in your programming language is less error
prone. If you have been programming to instruments without a driver, then you are
probably all too familiar with hunting around the programming guide to find the right
SCPI command and exact syntax. You also have to deal with an I/O library to
format and send the strings, and then build the response string into a variable.
Why IVI?
The VXIplug&play drivers do not provide a common programming interface. That
means programming a Keithley DMM using VXIplug&play still differs from
programming an Agilent DMM. For example, the instrument driver interface for one
may be ke2000_read while another may be hp34401_get or something even
farther afield. Without consistency across instruments manufactured by different
vendors, many programmers still spent a lot of time learning each individual driver.
To carry VXIplug&play drivers a step (or two) further, in 1998 a group of end users,
instrument vendors, software vendors, system suppliers, and system integrators
joined together to form a consortium called the Interchangeable Virtual Instruments
(IVI) Foundation. If you look at the membership, it’s clear that many of the
foundation members are competitors. But all agreed on the need to promote
specifications for programming test instruments that provide better performance,
reduce the cost of program development and maintenance, and simplify
interchangeability.
For example, for any IVI driver developed for a DMM, the measurement command
is IviDmmMeasurement.Read, regardless of the vendor. Once you learn how to
program the commands specified by IVI for the instrument class, you can use any
vendor’s instrument and not need to relearn the commands. Also commands that
are common to all drivers, such as Initialize and Close, are identical regardless of
5
the type of instrument. This commonality lets you spend less time browsing
through the help files in order to program an instrument, leaving more time to
get your job done.
That was the motivation behind the development of IVI drivers.The IVI
specifications enable drivers with a consistent and high standard of quality,
usability, and completeness. The specifications define an open driver architecture,
a set of instrument classes, and shared software components. Together these
provide consistency and ease of use, as well as the crucial elements needed for
the advanced features IVI drivers support: instrument simulation, automatic range
checking, state caching, and interchangeability.
The IVI Foundation has created IVI class specifications that define the capabilities
for drivers for the following thirteen instrument classes:
Oscilloscope IviScope
Switch IviSwtch
Upconverter IviUpconverter
Downconverter IviDownconverter
Digitizer IviDigitizer
Counter/timer IviCounter
IVI Class Compliant drivers usually also include capability that is not part of the IVI
Class. It is common for instruments that are part of a class to have numerous
functions that are beyond the scope of the class definition. This may be because
the capability is not common to all instruments of the class or because the
instrument offers some control that is more refined than what the class defines.
6
IVI also defines custom drivers. Custom drivers are used for instruments that are
not members of a class. For example, there is not a class definition for network
analyzers, so a network analyzer driver must be a custom driver. Custom drivers
provide the same consistency and benefits described below for an IVI driver,
except interchangeability.
IVI drivers conform to and are documented according to the IVI specifications and
usually display the standard IVI logo.
7
interchangeability but may not provide behavioral interchangeability. In other
words, the program may run on two different instruments but the results may
not be the same due to differences in the way the instrument itself functions.
Shared Components
To make it easier for you to combine drivers and other software from various
vendors, the IVI Foundation members have cooperated to provide common
software components, called IVI Shared Components. 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.
Important! You must install the IVI Shared Components before an IVI driver
can be installed.
The IVI Shared Components can be downloaded from vendors’ web sites as well
as from the IVI Foundation Web site.
To download and install shared components from the IVI Foundation Web site:
1 Go to the IVI Foundation Web site at http://www.ivifoundation.org.
2 Locate Shared Components.
3 Choose the IVI Shared Components msi file for the Microsoft Windows Installer
package or the IVI Shared Components exe for the executable installer.
8
IVI Drivers are available from your hardware or software vendor’s web site or by
linking to them from the IVI Foundation web site.
To see the list of drivers registered with the IVI Foundation, go to
http://www.ivifoundation.org.
Examples
As we noted above, each guide in the Getting Started with IVI Drivers series
shows you how to use an IVI driver to write and run a program that performs a
simple measurement on a simulated instrument and returns the result. The
examples demonstrate common steps using IVI drivers. Where practical, every
example includes the steps listed below:
• Download and Install the IVI driver– covered in the Download and Install IVI
Drivers section above.
• Determine the VISA address string – Examples in Getting Started with IVI
Drivers use the simulate mode, so we chose the address string
GPIB0::23::INSTR, often shown as GPIB::23. If you need to determine the
VISA address string for your instrument and the ADE does not provide it
automatically, use an IO application, such as National Instruments
Measurement and Automation Explorer (MAX) or Agilent Connection Expert.
• Reference the driver or load driver files – For the examples in the IVI guides, the
driver is the IVI-COM/IVI-C Version 1.2.2.0 for 34401A, October 2008
(from Agilent Technologies) … or the Agilent 34401A IVI-C driver,
Version 4.4, July 2010 (from National Instruments).
• Create an instance of the driver in ADEs that use COM – For the examples in
the IVI guides, the driver is the Agilent 34401A (IVI-COM) or HP 34401 (IVI-C).
• Write the program:
• Initialize the instrument – Initialize is required when using any IVI driver.
Initialize establishes a communication link with the instrument and must
be called before the program can do anything with the instrument. We set
reset to true, ID query to false, and simulate to true.
Setting reset to true tells the driver to initially reset the instrument.
9
Setting the ID query to false prevents the driver from verifying that the
connected instrument is the one the driver was written for. Finally,
setting simulate to true tells the driver that it should not attempt to
connect to a physical instrument, but use a simulation of the
instrument.
• Configure the instrument – We set a range of 1.5 volts and a resolution of
0.001 volts (1 millivolt).
• Access an instrument property – We set the trigger delay to 0.01
seconds.
• Set the reading timeout – We set the reading timeout to 1000
milliseconds (1 second).
• Take a reading
• Close the instrument – This step is required when using any IVI driver,
unless the ADE explicitly does not require it. We close the session to free
resources.
Important! Close may be the most commonly missed step when using an
IVI driver. Failing to do this could mean that system resources are not
freed up and your program may behave unexpectedly on subsequent
executions.
• Check the driver for any errors.
• Display the reading.
Note: Examples that use a console application do not show the display.
Now that you understand the logic behind IVI drivers, let’s see how to get started.
10
Chapter 2
Using IVI with Visual C# and
Visual Basic .NET
••••••
The Environment
C# and Visual Basic are object-oriented programming languages developed by
Microsoft. They enable programmers to quickly build a wide range of applications
for the Microsoft .NET platform. This chapter provides detailed instructions in C#
as well as the code for Visual Basic. NET. If you are using Visual Basic 6.0, we
recommend another guide in this series, Getting Started with IVI Drivers: Your
Guide to Using IVI with Visual Basic 6.
Note: One of the key advantages of using C# and Visual Basic in the Microsoft®
Visual Studio® Integrated Development Environment is IntelliSense™.
InstelliSense is a form of autocompletion for variable names and functions and a
convenient way to access parameter lists and ensure correct syntax. The feature
also enhances software development by reducing the amount of keyboard input
required.
Example Requirements
• Visual C#
• Microsoft Visual Studio 2010
• Agilent 34401A IVI-COM, Version 1.2.2.0, October 2008 (from Agilent
Technologies)
• Agilent IO Libraries Suite 16.1
11
Create a New Project and Reference the Driver
Begin by creating a new project, and add a reference to the IVI Driver.
1 Launch Visual Studio and create a new Console Application in Visual C# by
selecting File -> New -> Project and selecting a Visual C# Console Application.
Note: When you select new, Visual Studio will create an empty program the
includes some necessary code, including using statements. Keep this required
code.
For the next steps you will need to ensure that the "Program.cs" editor window
is visible and the Solution Explorer is visible.
2 Select Project and click Add Reference. The Add Reference dialog appears.
3 Select the COM tab. All IVI drivers begin with IVI. Scroll to the IVI section and
select IVI Agilent 34401 (Agilent Technologies) 1.2 Type Library. Click OK.
Note: If you have not installed the IVI driver, it will not appear in this list. You must
close the Add Reference dialog, install the driver, and select Add Reference again
for the driver to appear.
12
Note: The program looks the same as it did before you added the reference, but
the driver is now available for use. To see the reference, select View and click
Solution Explorer. Solution Explorer appears and lists the reference.
13
Create an Instance of the Driver
To allow your program to access the driver without specifying the full path, type the
following line immediately below the other using statements:
using Agilent.Agilent34401.Interop;
Note: As soon as you type the A for Agilent, IntelliSense lists the valid inputs.
Congratulations! You may now write the program to control the simulated
instrument.
Note: To view the functions and parameters available in the instrument driver, right-
click the library in the References folder in Solution Explorer and select View in
Object Browser.
14
Initialize the Instrument
You can now write the main constructs for your program. Create a variable to
represent your instrument and set the Initialization parameters.
1 Type Agilent34401 dmm = new Agilent34401();
2 Type dmm.Initialize (“GPIB::23”, false, true,
“simulate=true”);
Note: IntelliSense helps ensure you use correct syntax and values.
15
Configure the Instrument
To set the range to 1.5 volts and the resolution to 1 millivolt, type
dmm.DCVoltage.Configure(1.5, 0.001);
16
2 To trigger the multimeter and take a reading with a timeout of 1 second, type
reading = dmm.Measurement.Read(1000);
3 Type Console.WriteLine("The measurement is {0}", reading);
4 Type Console.ReadLine();
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Agilent34401 dmm = new Agilent34401();
dmm.Initialize("GPIB::23", false, true, "sim-
ulate=true");
dmm.DCVoltage.Configure(1.5, 0.001);
dmm.Trigger.Delay = 0.01;
double reading;
reading = dmm.Measurement.Read(1000);
Console.WriteLine("The measurement is {0}",
reading);
Console.ReadLine();
dmm.Close();
}
}
}
17
Build and Run the Application
Build your application and run it to verify it works properly.
1 From the Build menu, click the name of your Console Application.
2 From the Debug menu, click Start Debugging.
Tips
The code for a Visual Basic console application in Visual Studio 2010 is almost
identical to the C# application:
Option Explicit On
Imports Agilent.Agilent34401.Interop
Module Module1
Sub Main()
Dim dmm As New Agilent34401
dmm.Initialize("GPIB::23", False, True,
"simulate=true")
dmm.Function =
Agilent34401FunctionEnum.Agilent34401FunctionDCVolts
dmm.DCVoltage.Configure(1.5, 0.001)
dmm.Trigger.Delay = 0.01
Dim reading As New Double
reading = dmm.Measurement.Read(1000)
dmm.Close()
Console.WriteLine(“The reading is {0}”, reading)
Console.ReadLine()
End Sub
End Module
The main differences include the following:
• To use Visual Basic, select Visual Basic in Project Types.
• To enforce type checking, insert a line at the start of the code. Type
Option Explicit On
• This example also shows how to set an enumerated property. This property
assignment sets the DMM function to Voltage: Type
dmm.Function =
Agilent34401FunctionEnum.Agilent34401FunctionDCVolts
18
• To dimension a variable for the instrument and reading, use Dim dmm and Dim
reading.
Further Information
• Learn more about Visual C# at http://msdn.microsoft.com/vcsharp/.
• Learn more about Visual Basic at http://msdn.microsoft.com/vbasic/.
19