HP Drive User Manual

Getting S tarted Guide

Your Guide to Getting
Started with IVI Drivers
Revision 1.0
Contents
• • • • • •
Chapter 1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
Why Use an Instrument Driver?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Why IVI?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Why Use an IVI Driver? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
Flavors of IVI Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
Shared Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Download and Install IVI Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
Familiarizing Yourself with the Driver. . . . . . . . . . . . . . . . . . . . . . . . . . .14
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
Chapter 2 Using IVI with Visual C++. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
The Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Example Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Download and Install the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Using IVI-COM in C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Create a New Project and Import the Driver Type Libraries. . . . . . . . . . 18
Initialize COM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Create an Instance of the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Initialize the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Configure the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Set the Trigger Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Set the Reading Timeout/Display the Reading . . . . . . . . . . . . . . . . . . . 21
Error Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Close the Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Build and Run the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Using IVI-C in Visual C++. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22
Contents
3
Create a New Project and Import the Driver Type Libraries. . . . . . . . . . 22
Declare Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
Define Error Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
Initialize the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Configure the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Set the Trigger and Trigger Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26
Set the Reading Timeout/Display the Reading . . . . . . . . . . . . . . . . . . . 26
Close the Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Build and Run the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Further Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Chapter 3 Using IVI with Visual C# and Visual Basic .NET . . . . . . . . . . . . . . . 29
The Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Example Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Download and Install the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Create a New Project and Reference the Driver . . . . . . . . . . . . . . . . . .30
Create an Instance of the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Initialize the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Configure the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Set the Trigger Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Set the Reading Timeout/Display the Reading . . . . . . . . . . . . . . . . . . . 33
Close the Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Build and Run the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Tips. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
Further Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Chapter 4 Using IVI with LabVIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
Example Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
Download and Install the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Using IVI-C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
4
Contents
Create a Project and Access the Driver. . . . . . . . . . . . . . . . . . . . . . . . . 38
Initialize the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Configure the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Take the Reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
Display the Reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
Close the Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Add Error Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
Run the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Setting a Property in an IVI-C Driver . . . . . . . . . . . . . . . . . . . . . . . . . . .42
Using IVI-COM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Create a Project and Access the Driver. . . . . . . . . . . . . . . . . . . . . . . . . 42
Initialize the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Configure the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Take the Reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
Display the Reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
Close the Driver and Automation Sessions . . . . . . . . . . . . . . . . . . . . . .46
Add Error Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
Run the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Further Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Chapter 5 Using IVI with LabWindows/CVI . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
The Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49
Example Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49
Download and Install the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Create a New Project and Add Instrument Driver Files . . . . . . . . . . . . . 49
Initialize the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Configure the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Set the Reading Timeout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .53
Display the Reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54
Close the Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Contents
5
Further Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Chapter 6 Using IVI with MATLAB® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
The Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Example Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .57
Download and Install the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Configure the IVI Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Generate an Instrument Wrapper. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61
Configure and Control the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Create an Instance of the Instrument . . . . . . . . . . . . . . . . . . . . . . . 61
Connect to the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Configure the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61
Set the Trigger Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62
Set Reading Timeout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Display Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Disconnect from the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . .62
Remove the Driver from Memory . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Further Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Chapter 7 Using IVI with Measure Foundry®. . . . . . . . . . . . . . . . . . . . . . . . . . . 65
The Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
Example Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
Download and Install the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Data Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Control Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Data Sink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Compile and Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70
Close Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Further Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Chapter 8 Using IVI with PAWS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
The Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
Example Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
Download and Install the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6
Contents
Prepare the PAWS Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Add the WCEM Interface Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . .76
Connect to the IVI-COM Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Build the Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Prepare the Run-Time System Environment . . . . . . . . . . . . . . . . . . . . .82
Load and Run the Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .83
Further Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Chapter 9 Using IVI with Visual Basic 6.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
The Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .85
Example Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .85
Download and Install the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Create a New Project and Reference the Driver . . . . . . . . . . . . . . . . . .85
Add a Button. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86
Create an Instance of the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Initialize the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Configure the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Set the Trigger Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Display the Reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89
Close the Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Tips. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90
Further Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Chapter 10 Using IVI with Agilent VEE Pro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
The Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Example Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93
Download and Install the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Launch the Instrument Manager and Select the Driver . . . . . . . . . . . . .93
Create an Instance of the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Initialize the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Configure the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Contents
7
Set the Trigger Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Set the Reading Timeout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
Close the Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Display the Reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
Tips. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
Another Method to Display the Reading. . . . . . . . . . . . . . . . . . . . . 98
Further Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Chapter 11 Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
IVI Architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101
Driver API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Driver Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Instrument I/O. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Shared Components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104
Interchangeability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
IVI Configuration Store. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106
IVI-COM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109
IIviDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
IIviDmm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
IVI-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Editing the Configuration Store. . . . . . . . . . . . . . . . . . . . . . . . . . . .112
Future Development of IVI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
IVI Drivers in Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112
8
Contents

Purpose

Chapter 1 Introduction
• • • • • •
Welcome to IVI drivers and shows you how to create a short program to perform a measurement. The guide also provides a brief introduction to several advanced topics.
IVI Getting Started Guide
to control test-and-measurement instruments. 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 how to get started,
Started Guide
IVI Getting Started Guide
is intended for individuals who write and run programs
can help.
. This guide introduces key concepts about
IVI Getting
IVI Getting Started Guide
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.

Why Use an Instrument Driver?

To understand the benefits of IVI drivers, we need to start by defining instrument drivers in general and describing why they are useful. An instrument driver is a set of software routines that controls a programmable instrument. Each routine corresponds to a programmatic operation, such as configuring, writing to, reading from, and triggering the instrument. Instrument drivers simplify instrument control and reduce test program development time by eliminating the need to learn the programming protocol for each instrument.
shows you that IVI drivers can be straightforward, easy-
9
Starting in the 1970s, programmers used device-dependent commands for computer control of instruments. But lack of standardization meant even two digital multimeters from the same manufacturer might not use the same commands. In 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.
10
Chapter 1

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.
T o 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 the type of instrument. This commonality lets you spend less time hunting around the help files and programming 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 eight instrument classes:
Class IVI Driver
Digital multimeter (DMM) IviDmm Oscilloscope IviScope Arbitrary waveform/function generator IviFgen DC power supply IviDCPwr Switch IviSwitch Power meter IviPwrMeter Spectrum analyzer IviSpecAn RF signal generator IviRFSigGen
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.
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.
Introduction
11
IVI drivers conform to and are documented according to the IVI specifications and usually display the standard IVI logo.
Note
: For more information on the types of IVI drivers, refer to Chapter 11,
Advanced Topics.

Why Use an IVI Driver?

Why choose IVI drivers over other possibilities? Because IVI drivers can increase performance and flexibility for more intricate test applications. Here are a few of the benefits:
Consistency
instrument. That saves you time when you
Ease of use
Development Environments (ADEs). The APIs provide fast, intuitive access to functions. IVI drivers use technology that naturally integrates in many differen t software environments.
– IVI drivers all follow a common model of how to control the
need to use a new instrument.
– IVI drivers feature enhanced ease of use in popular Application
12
Chapter 1
Quality
IVI drivers focus on common commands, desirable options, and
rigorous testing to ensure driver quality.
Simulation –
IVI drivers allow code development and testing even when an instrument is unavailable. That reduces the need for scarce hardware resources and simplifies test of
measurement applications. The example programs in this
document use this feature.
Range checking –
IVI drivers ensure the parameters you use are within
appropriate ranges for an instrument.
State caching –
IVI drivers keep track of an instrument’s status so that I/O is only performed when necessary, preventing redundant configuration commands from being sent. This can significantly improve test system performance.
Interchangeability –
IVI drivers enable exchange of instruments with minimal code changes, reducing the time and effort needed to integrate measurement devices into new or existing systems. The IVI class specifications provide syntactic 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.

Flavors of IVI Drivers

To support all popular programming languages and development environments, IVI drivers provide either an IVI-C or an IVI-COM (Component Object Model) API. Driver developers may provide either or both interfaces, as well as wrapper interfaces optimized for specific development environments.
Although the functionality is the same, C development environments; IVI-COM drivers are optimized for environment s that support the VXIplug&play driver specification and their usage is similar. IVI-COM drivers provide easy access to instrument functionality through methods and properties.
All IVI drivers communicate to the instrument through an I/O Library. Our examples use the Virtual Instrument Software Architecture (VISA), a widely used standard library for communicating with instruments from a personal computer.

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.
IVI-C drivers are optimized for use in ANSI
Component Object Model (COM). IVI-C drivers extend the

Download and Install IVI Drivers

After you’ve installed Shared Components, you’re ready to download and install an IVI driver. For most ADEs, the steps to download and install an IVI driver are identical. For the few that require a different process, the relevant chapter in
Getting Started Guide
IVI Drivers are available from your hardware or software vendor’s web site or by linking to them from the IVI Foundation web site.
provides the information you need.
IVI
Introduction
13
To see the list of drivers registered with the IVI Foundation, go to
http://www.ivifoundation.org

Familiarizing Yourself with the Driver

Although the examples in likely
employ a variety of IVI drivers task, you’ll want to familiarize yourself quickly with drivers you haven’t used before. Most ADEs provide a way to explore IVI drivers to learn their functionality. In each chapter, where applicable, we add a note explaining how to view the available functions. In addition, browsing an IVI driver’s help file often proves an excellent way to learn its functionality.

Examples

As we noted above, each example chapter in 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. 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 use the simulate mode, so we chose the address string 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 this guide, the driver is the
March 2006 (from Agilent Technologies) Specific driver, Version 4.1, October 2006 (from National Instruments).
Create an instance of the driver in ADEs that use COM – For the examples in this guide, the driver is the
Write the program:
Agilent 34401A IVI-COM Specific Driver, Version 1.1.0.11,
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
.
IVI Getting Started Guide
to develop test programs. To jumpstart that
Agilent 34401A (IVI-COM) or HP 34401 (IVI-C)
false
, and simulate to
use a DMM driver, you will
IVI Getting Started Guide
Where practical, every example
IVI Getting Started Guide
GPIB0::23::INSTR,
or the
Agilent 34401A IVI-C
true
.
shows
.
14
Chapter 1
Setting reset to true tells the driver to initially reset the instrument. 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 simula tio n of the instrument.
Configure the instrument – We set a range of
0.001 volts (1 millivolt)
.
1.5 volts
and a resolution of
Access an instrument property – We set the trigger delay to
seconds
Set the reading timeout – We set the reading timeout to
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.
.
0.01
1000
Introduction
15
16
Chapter 1
Chapter 2 Using IVI with Visual C++
• • • • • •

The Environment

Microsoft Visual C++ is a software development environment for the C++ programming language and is available as part of Microsoft Visual Studio. Visual C++ allows you to create, debug, and execute conventional applications as well as applications that target the .NET Framework.

Example Requirements

Visual C++
Microsoft Visual Studio 2005
IVI-COM: Agilent 34401A IVI-COM, Version 1.1.0.11, March 2006 (from Agilent Technologies); or
IVI-C: Agilent 34401A IVI-C, Version 4.1, October 2006 (from National Instruments)
Agilent IO Libraries Suite 14.2

Download and Install the Driver

If you have not already installed the driver, go to the vendor W eb site and follow the instructions to download and install it.
Since Visual C++ supports both IVI-COM and IVI-C drivers, this example is written two ways, first to show how to use an IVI-COM driver in Visual C++, and second to show how to use an IVI-C driver in Visual C++.
Note
because the referenced files are not included in the program. If you need to download and install a driver, you do not need to exit V isual Studio. Install the driver and continue with your program.

Using IVI-COM in C++

The following sections show how to get started with an IVI-COM driver in Visual C++
: If you do not install the appropriate instrument driver , the project will not build
17

Create a New Project and Import the Driver Type Libraries

To use an IVI Driver in a Visual C++ program, you must provide the path to the driver DLL.
18
Chapter 2
1 Launch Visual Studio 2005 and create a Win32 Console Application in C++
with the name IVI demo.
Note:
The program already includes some required code, including the header file
#include stdafx.h
.
2 From the Tools menu select Options. 3 Expand “Projects and Solutions”, then click on “VC++ Directories” 4 Click on the “Show directories for” combo box and choose “Library files” 5 Add the following two entries to your path.
The first entry will point to the default directory for IVI drivers. This is typically:
“C:\Program Files\Ivi\Bin”
The second entry points to the VISA DLL that many drivers require:

Initialize COM

“$(VXIPNPPATH)VisaCom”
Note:
These steps need only be done once for each computer you use. All subsequent Visual Studio projects will continue to use these settings and will be able to locate your IVI-COM drivers.
6 Click OK 7 To import the type libraries, type the following statements following the header
file reference:
#import “IviDriverTypeLib.dll” no_namespace #import “IviDmmTypeLib.dll” no_namespace #import “GlobMgr.dll” no_namespace #import “Agilent34401.dll” no_namespace
Note:
The
import
statements access the driver type libraries used by the Agilent 34401 DMM. The no_namespace attribute allows the code to access the interfaces in the typelibraries from the global namespace.
1 To initialize the COM library, type the following lines after the { following the int
statement:
HRESULT hr; hr = CoInitialize(NULL); IF(FAILED(hr))
exit(1);
Note: Including error handling in your programs is good practice. This code
checks for errors in your program.
2 To close the COM library before exiting, type the following line at the end of
your code, right before the return line:
CoUninitialize();

Create an Instance of the Driver

To create an instance of the driver, type
IIviDmmPtr dmm(__uuidof(Agilent34401));
Note:
This creates a smart pointer that provides easy access to the COM object.
You are now ready to write the program to control the simulated instrument.
Using IVI with Visual C++
19

Initialize the Instrument

You can now write the main constructs for your program. Below the smart pointer statement, type dmm->Initialize("GPIB::23", false, true, "simulate=true");
Note
: As soon as you type ->, Intellisense displays options and helps ensure you
use correct syntax and values.

Configure the Instrument

To set the range to 1.5 volts and resolution to 0.001 volts, type
dmm->Configure(IviDmmFunctionDCVolts, 1.5, 0.001);
20
Chapter 2

Set the Trigger Delay

To set the trigger delay to 0.01 seconds, type
dmm->Trigger->Delay = 0.01;

Set the Reading Timeout/Display the Reading

Create a variable to represent the reading and make a reading with a timeout of 1 second (1000 milliseconds).
1 Type
double reading = dmm->Measurement->Read(1000);
2 To display the reading, use printf. Type
wprintf(L“Reading: %g\n”, reading);

Error Checking

To catch errors in the code, activate error checking.
1 Surround the preceding statement s with a try block. Add the following lines as
shown in the illustration above:
try {
}
2 Process errors in a catch block. Type
catch (_com_error e) {
wprintf(L“Error: %s”, e.ErrorMessage());
}

Close the Session

To close out the instance of the driver and free resources, type
dmm->Close();
The final code should look like the following:
#include "stdafx.h" #import "IviDriverTypeLib.dll" no_namespace #import "IviDmmTypeLib.dll" no_namespace #import "GlobMgr.dll" no_namespace #import "Agilent34401.dll" no_namespace int IVI_Demo()
{
HRESULT hr; hr = CoInitialize(NULL);
if(FAILED(hr))
Using IVI with Visual C++
21
exit(1);
{
IAgilent34401Ptr dmm(__uuidof(Agilent34401));
try{
dmm->Initialize("GPIB::23",false,true,"simulate=true");
dmm->DCVoltage->Configure(1.5, 0.001); dmm->Trigger->Delay = 0.01;
double reading = dmm->Measurement->Read(1000);
wprintf(L“Reading: %g\n”, reading); }
catch(_com_error e){
wprintf(L“Error: %s\n”, e.ErrorMessage); } dmm->Close();
} CoUninitialize();
return 0;
}
22
Chapter 2

Build and Run the Application

Build your application and run it to verify it works properly.
1 From the Start Menu, select Build, and click Build IVIDemo. 2 From the Start Menu, select Debug, and run the application.

Using IVI-C in Visual C++

The following sections show to get started with IVI-C in Visual C++.

Create a New Project and Import the Driver Type Libraries

To use an IVI-C Driver in a Visual C++ program, you must provide paths to the header files and libraries it uses.
1 Launch Visual Studio 2005 and create a Win32 Console Application in C++
with the name IVI demo.
Note:
The program already includes some required code, including the header file
#include stdafx.h
.
2 From the Tools menu select Options. 3 Expand “Projects and Solutions”, then click on “VC++ Directories” 4 Click on the “Show directories for” combo box and choose “Library files” 5 Add the following entry to your “Library files” path.
This entry points to the default directory for IVI drivers. This is typically:
“C:\Program Files\IVI\Lib\msc”
6 Click on the “Show directories for” combo box and choose “Include files” 7 Add the following entries to your “Include files” path.
The first entry will point to the default directory for IVI drivers. This is typically:
“C:\Program Files\IVI\include”
The second entry points to the VISA header files that IVI-C drivers require:
“$(VXIPNPPATH)WinNT\include”
8 Click OK
Note:
These initial steps need only be done once for each computer you use. All subsequent Visual Studio projects will continue to use these settings and will be able to locate your IVI-COM drivers.
9 Select Project and click Properties. The IVIDemo.cpp “Property pages” dialog
box appears.
Using IVI with Visual C++
23
10 Expand “Configuration Properties” 11 Expand “Linker” 12 Select Input. In the Additional Dependencies field, type
13 Select OK. 14 To add the hp34401a instrument driver header file to your program, type the
15 From the Main Menu, select Build and click Build IVIDemo.

Declare V ariables

1 Y ou will need to declare some variables that will be used in your program. T ype
“hp34401a.lib”
following statement following the existing header file reference:
#include “hp34401a.h”
the following lines after the { in the int main () statement: ViSession session; ViStatus error = VI_SUCCESS;
ViReal64 reading;
24
Chapter 2

Define Error Checking

1 Next define error checking for your program. First you will define a macro to
catch the errors. It is better to define it once at the beginning of the program that to add the logic to each of your program statements. After the #include statements, type the following lines:
#ifndef checkErr #define checkErr(fCall) \ if (error = (fCall), (error = (error < 0) ? \ error : VI_SUCCESS)) \ {goto Error;} else error = error #endif
2 Next you will type the following lines at the end of the program to handle any
errors that occur:
Error: if (error != VI_SUCCESS) { ViChar errStr[2048];
hp34401a_GetError (session, &error, 2048, errStr); printf ("Error!", errStr); }
Note: Including error handling in your programs is good practice. This code checks for errors in your program.

Initialize the Instrument

1 To initialize the instrument, add the following Initialize with Options function
right after the variable declarations you added in the previous section
checkErr( hp34401a_InitWithOptions (“GPIB::23::INSTR”,
This initializes the instrument with the following parameters:
• GPIB0::23::INSTR as the Resource Name (instrument at GPIB address 23)
• VI_FALSE Does not perform an ID Query
• VI_TRUE Resets the device
VI_FALSE, VI_TRUE, “Simulate = 1”, &session));
Using IVI with Visual C++
25
• Simulate=1 in the Options parameter sets the driver to simulation mode
• &session assigns the Instrument Handle to the variable “session” defined above

Configure the Instrument

1 To set the range to 1.5 volts and resolution to 0.001 millivolts, type:
checkErr( hp34401a_ConfigureMeasurement (session,
HP34401A_VAL_DC_VOLTS, 1.5, 0.001));

Set the Trigger and Trigger Delay

1 To set the trigger source to immediate and the trigger delay to 0.01 seconds,
type:
checkErr( hp34401a_ConfigureTrigger (session,
HP34401A_VAL_IMMEDIATE, 0.01));

Set the Reading Timeout/Display the Reading

1 To take a reading from the instrument and to set the reading timeout to 1
second (1000 ms) type:
checkErr( hp34401a_Read (session, 1000, &reading);
Note: The Read function takes a reading from the instrument and assigns the result to the variable “reading” defined above.
2 To display the reading, use a pr int f statemen t. Type
printf (“Reading = %f”, reading);
26
Chapter 2

Close the Session

To close out the instance of the driver and free resources, type
If (session) hp34401a_Close(session);
The final code should contain the code below:
#include "stdafx.h" #include <hp34401a.h>
#ifndef checkErr #define checkErr(fCall) \ if (error = (fCall), (error = (error < 0)? error : VI_SUCCESS)) \ {goto Error;} else error = error
#endif
int main(int argc, _TCHAR* argv[]) { ViSession session; ViStatus error = VI_SUCCESS; ViReal64 reading;
checkErr( hp34401a_InitWithOptions ("GPIB::23::INSTR",
VI_FALSE, VI_TRUE, "Simulate=1", &session));
checkErr( hp34401a_ConfigureMeasurement (session,
HP34401A_VAL_DC_VOLTS, 1.5, 0.0001));
checkErr( hp34401a_ConfigureTrigger (session,
HP34401A_VAL_IMMEDIATE, 0.01)); checkErr( hp34401a_Read (session, 1000, &reading)); printf ("Reading = %f", reading);
Error: if (error != VI_SUCCESS) { ViChar errStr[2048];
hp34401a_GetError (session, &error, 2048, errStr); printf ("Error!", errStr); }
if (hp34401a) hp34401a_close (hp34401a); }

Build and Run the Application

Build your application and run it to verify it works properly.
Using IVI with Visual C++
27
1 From the Start Menu, select Build, and click Build IVI Demo. 2 From the Start Menu, select Debug, and run the application.

Further Information

Learn more about Visual C++ at http://msdn.microsfot.com/visualc/.
Microsoft® and Visual Studio® are registered tradem arks of Microsoft Corporation in the United States and/or other countries.
28
Chapter 2
Chapter 3 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. Visual Basic 6.0, refer to Chapter 9.
Note:
One of the key advantages of using C# and Visual Basic in the Microsoft® Visual Studio 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 2005
Agilent 34401A IVI-COM, Version 1.1.0.11, March 2006 (from Agilent Technologies)
Agilent IO Libraries Suite 14.2
®
Integrated Development Environment is IntelliSense™.
If you are looking for an example using

Download and Install the Driver

If you have not already installed the driver, go to the vendor W eb site and follow the instructions to download and install it. You can also refer to Chapter 1, Download and Install IVI Drivers, for instructions.
This example uses an IVI-COM driver. IVI-COM is the preferred driver for C#, but IVI-C is also supported.
29

Create a New Project and Reference the Driver

To use an IVI Driver in a Visual C# program, you must first add a reference to it.
1 Launch Visual Studio and start a new Console Application in Visual C#.
Note:
The program already includes some required code, including using statements. Keep this required code.
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.1 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.
30
Chapter 3
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.
Loading...
+ 84 hidden pages