How to Use an Instrument Driver in LabWindows™/CVI Tutorial

Updated Dec 18, 2023

Environment

Software

  • LabWindows/CVI

An instrument driver is a set of software routines that control a programmable instrument. Each routine corresponds to a programmatic operation such as configuring, reading from, writing to, 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.
NI provides instrument drivers for a wide variety of instruments; these instrument drivers are written in LabVIEW and/or LabWindows/CVI and use either the Virtual Instrumentation Software Architecture (VISA) or the Interchangeable Virtual Instrument (IVI) protocol. 

Where to Find Instrument Drivers and How to Download Them

You can find instrument drivers for more than 5,000 instruments on the Instrument Driver Network. Look here to find an instrument driver for your particular instrument. If you find one, follow the procedure below to load it into CVI

You can load and unload instrument drivers manually using the Instruments Folder in the Library Tree or using the Instrument menu. Instrument drivers loaded through the Instruments folder or Instrument menu do not have to be listed in the project, and you can load or unload them at any time except during program execution. You also can load instrument drivers by dropping .fp files onto the Library Tree directly.
 

To incorporate instrument drivers into the project, select File»Add to Project in a Function Panel window or the Function Tree Editor or select Edit»Add Files to Project in the Workspace window. If you drop the .fp file onto a project in the Project Tree, LabWindows/CVI adds the file to the project and loads the instrument driver if the project is the active project. If you drop the .fp file onto an inactive project, LabWindows/CVI adds the .fp to that project, but does not load the .fp. If you drop the .fp file onto the Library Tree, LabWindows/CVI loads the instrument driver but does not add it to any project. The .fp file represents the instrument driver in the project. If the .fp file is in the project when you open the project, LabWindows/CVI automatically loads the instrument driver and removes it when you unload or deactivate the project.

 

LabWindows/CVI Instrument Driver Example

The following figure shows the function tree layout for the Agilent 34401A driver. You can double-click on any of the functions to open that function and edit or run it.
 


Figure 1. Agilent 34401 Function Tree Layout


 

For example, if you double-click on the Initialize function, that function panel will open. This function performs the following initialization actions:
 

  • Opens a session to the Default Resource Manager resource and a session to the specified device using the interface and address specified in the Resource_Name control.
  • Performs an identification query on the instrument.
  • Resets the instrument to a known state.
  • Sends initialization commands to the instrument that set any necessary programmatic variables such as Headers Off, Short Command form, and Data Transfer Binary to the state necessary for the operation of the instrument driver.
  • Returns an Instrument Handle which is used to differentiate between different sessions of this instrument driver.
  • Each time this function is invoked a Unique Session is opened. It is possible to have more than one session open for the same resource.
 


Figure 2. Agilent 34401 Initialize Function

 

Instrument Driver Organization

The following figure shows the organization of a typical instrument driver.



Figure 3. Instrument Driver Organization

 

A LabWindows/CVI instrument driver typically consists of the following three or four files. Each file has the same base file name, which is typically an abbreviation of the actual instrument name. The instrument driver files must reside in the same directory on your disk, or they must be in the appropriate VXIplug&play directories or in the appropriate IVI directories.

  • The function panels are in a .fp file.
  • For instrument drivers that use an attribute model, such as IVI drivers, there can be an additional .sub file that contains attribute information displayed in the function panels.
  • The function, variable, and defined constant declarations are in a .h include file.
  • The instrument driver program can be in one of several different types of files.
    • .c source file
    • .obj object file that contains one or more compiled C modules
    • .lib library file

You must compile these files in LabWindows/CVI or in a compatible external compiler.

For example, the instrument module files for the Agilent (HP) 34401A multimeter are hp34401a.fp, hp34401a.c, and hp34401a.h. A Word document that describes the functionality of that particular instrument driver is also included when you download an instrument driver. This document is intended to be used as a programming reference manual.

You can load an instrument driver into the LabWindows/CVI interactive program whether the instrument program is in the form of a .c, .obj, or .lib file. The presence of the .h file is essential because you must include it in your program to refer to functions, global variables, and constants in the instrument driver.
 

Similar to a LabVIEW instrument driver, a LabWindows/CVI instrument driver is usually composed of the following functions/classes:
 

Initialize:
This function initializes the instrument and sets it to a default configuration.
 

Configuration Functions: (Class)
This class of functions configures the instrument by setting acquisition and system configuration parameters.
 

Action/Status Functions: (Class)
This class of functions begins or terminates an acquisition. It also
provides functions which allow the user to determine the current status of the instrument.
 

Data Functions: (Class)
This class of functions transfers data to or from the instrument.
 

Utility Functions: (Class)
This class of functions provides lower level functions to communicate with the instrument, and change instrument parameters.
 

Close:
This function takes the instrument offline.

Next Steps