Instrument Control in LabVIEW Tutorial

Publish Date: Oct 16, 2019 | 28 Ratings | 3.61 out of 5 | Print | Submit your review


This tutorial will cover how to control your instrument in LabVIEW using the following tools: instrument drivers, the Instrument I/O Assistant, and the VISA Application Programming Interface (API).

Table of Contents

  1. Introduction
  2. Instrument Drivers
  3. Instrument I/O Assistant
  5. Creating an Instrument Driver
  6. Related Links

1. Introduction

With a wide array of instrument connectivity interfaces, it is important to choose the proper one for your application. The following flowchart will guide you through the choices you need to make when choosing the appropriate interface.

Figure 1. Flowchart on Choosing the Correct Interface

Back to Top

2. Instrument Drivers

In LabVIEW, an instrument driver is a set of VIs that communicates with an instrument. Each VI corresponds to a programmatic operation, such as configuring, reading from, writing to, and triggering an instrument. LabVIEW instrument drivers simplify instrument control and reduce test program development time by eliminating the need for you to learn the complex, low-level programming commands for each instrument.

Back to Top

3. Instrument I/O Assistant

The Instrument I/O Express VI, found on the Functions>>Instrument I/O palette, launches the Instrument I/O Assistant, which you can use to communicate with message-based instruments and graphically parse the response. For example, you can communicate with an instrument that uses a serial, Ethernet, or GPIB interface.

Using the Instrument I/O Assistant

The Instrument I/O Assistant organizes instrument communication into ordered steps. To use the Instrument I/O Assistant, you place steps into a sequence. As you add steps to the sequence, they appear in the step sequence window. Use the view associated with a step to configure instrument I/O. Four steps are available in the Instrument I/O Assistant.

-Select Instrument—Use this step to select the instrument you want to communicate with and to configure basic instrument properties. This step appears in the step sequence window when you launch the Instrument I/O Assistant and must always be the first step in any Instrument I/O Assistant sequence.
-Query and Parse—Use this step to send a command to the instrument, read a response from the instrument, and parse the returned data.
-Write—Use this step to send a command to the instrument.
-Read and Parse—Use this step to read a response from the instrument and parse the returned data.

Once you build a sequence of steps, you then execute the sequence to communicate with the instrument. When execution completes, use the response window in the Read and Parse view and Query and Parse view to interactively parse data into tokens and assign new data types to the tokens you create. Refer to figure 2 to see the Instrument I/O Assistant.

Note You must have the Instrument I/O Assistant installed to use the Instrument I/O Assistant Express VI. You install the Instrument I/O Assistant from the National Instruments Device Drivers CD.

Figure 2. Instrument I/O Assistant

For more information about configuring the steps, click Show Help to view the embedded help within the Instrument I/O Assistant.

Back to Top


VISA is a standard I/O API for instrumentation programming. VISA can control GPIB, serial, USB, Ethernet, PXI, or VXI instruments, making the appropriate driver calls depending on the type of instrument you use so you do not have to learn instrument-specific communication protocol. Before you begin using VISA, make sure you choose the appropriate method of instrument control.

Creating a Typical VISA Application

Use the I/O controls on the Controls>>I/O and Controls>>Classic>>Classic I/O palettes to specify the instrument or device resource you want to communicate with. Use the VIs and functions on the Functions>>Instrument I/O>>VISA palette to build VIs that control instruments.

For most simple instrument applications, you need only two VISA functions, VISA Write and VISA Read. Refer to the Basic Serial Write and Read Example VI in the labview\examples\instr\smplserl.llb for an example of how to use VISA functions.

Figure 3. Basic Serial Write and Front Panel

This VI allows the user to select the VISA resource and operation they would like to perform, write, read or both. If the user selects to write to and read from the instrument, the VI will write the data to the instrument, read the response from the instrument and display it in the “read string” indicator, and then close the VISA session. Refer to the block diagram to see how this VI is programmed.

Figure 4. Basic Serial Write and Block Diagram

The VISA Configure Serial is used to configure the serial port with the specified baud rate, data bits, parity, stop bits and flow control. Next, the VI checks to see whether the user has selected to write to the instrument. If yes, the VI sends the string to the instrument using the VISA and then waits for the specified amount of time. The VI then checks to see if the user selected to read from the instrument. If yes, the VI reads the data from the instrument using the VISA and displays the result on the front panel. Finally, the VI closes the session to the port using the VISA This is important to do so another application can access the port without having to exit LabVIEW.

Use the VIs in the Functions>>Instrument I/O>>VISA>>VISA Advanced palette to build advanced VISA VIs. Refer to the labview\examples\instr\visa.llb for examples of using advanced VISA VIs.

Verifying VISA Communication

To verify that VISA and the device driver are installed correctly and VISA detects the instrument, first view the resource names that appear in the VISA resource name pull-down menu. If no resource names appear in this list, VISA or the device driver might not be installed correctly. Use Measurement & Automation Explorer to configure and test instrument communication. If resource names appear in the VISA resource name pull-down menu, but a particular instrument does not appear in the list, you might have a cable connection problem.

If VISA is installed correctly and VISA detects the instrument, but you receive errors when you run the instrument control application, you must identify what sequence of VIs produces the error in LabVIEW. If you are using an instrument driver, try to run each VI interactively and verify that each control is set appropriately.

NI I/O Trace is a tool for monitoring instrument I/O communications while your application runs. You can use NI I/O Trace to capture instrument I/O calls and their results while LabVIEW VIs run. Capturing calls and their results can help you debug problems with instrument communications. Windows - Select Start»National Instruments»NI I/O Trace to launch NI I/O Trace. Mac OS - Select Applications»National Instruments»NI I/O Trace and double-click the NI I/O Trace icon to launch NI I/O Trace. Linux - Type niiotrace in the command line to launch NI I/O Trace.

Back to Top

5. Creating an Instrument Driver

Use the Instrument Driver Project Wizard to create a new instrument driver project. Select Tools»Instrumentation»Create Instrument Driver Project to launch the Instrument Driver Project Wizard. After creating the new instrument driver, follow the Instrument Driver Modification Instructions in LabVIEW Help to complete the driver.

Use the Instrument Driver VI Wizard to create an instrument driver VI and insert the VI into the instrument driver project library. Right-click the project library file in the Project Explorer window and select New»Instrument Driver VI from the shortcut menu to launch the Instrument Driver VI Wizard.

Back to Top

6. Related Links

NI-VISA Programming Reference Manual
Instrument Driver Network
Using IVI Drivers in LabVIEW
Getting Started Using National Instruments IVI with LabVIEW or LabWindows/CVI
Using IVI Drivers to Build Hardware-Independent Test Systems with LabVIEW and LabWindows/CVI
Getting Started with Instrument Control

Back to Top

Bookmark & Share


Rate this document

Answered Your Question?
Yes No