Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Acquiring Data and Communicating with an Instrument

2 ratings | 2.50 out of 5
Print | PDF

Overview

This tutorial introduces you to the Express VIs you use to acquire data and communicate with instruments on Windows. These exercises require data acquisition hardware.

Refer to the Taking Measurements book on the Contents tab in the LabVIEW Help for information about acquiring data and communicating with instruments on all platforms.

Acquiring a Signal

In the following exercises, you will use the DAQ Assistant Express VI to create a task in NI-DAQmx. NI-DAQmx is a programming interface you can use to communicate with data acquisition devices. Refer to the Getting Started»Getting Started with DAQ»Taking an NI-DAQmx Measurement in LabVIEW book on the Contents tab in the LabVIEW Help for information about additional methods you can use to create NI-DAQmx tasks.

The following exercises require that you have NI-DAQmx and an NI-DAQmx-supported device. Refer to the NI-DAQ Readme for the list of NI-DAQmx-supported devices. If you have a device that is supported only with Traditional NI-DAQ, refer to the Taking Measurements book on the Contents tab in the LabVIEW Help for information about using Traditional NI-DAQ (Legacy) for data acquisition. In the following exercises, you will create an NI-DAQmx task that continuously takes a voltage reading and plots the data on a waveform graph. 

Note: With NI-DAQmx 7.4 or later you can create NI-DAQmx simulated devices in MAX. An NI-DAQmx simulated device is a software replica of a DAQ device. Refer to the Measurement & Automation Explorer Help for NI-DAQmx for detailed instructions on creating an NI-DAQmx simulated device that you can use to complete the following exercises.

Creating an NI-DAQmx Task

In NI-DAQmx, a task is a collection of one or more channels, timing, triggering, and other properties. Conceptually, a task represents a measurement or generation you want to perform. For example, you can create a task to measure temperature from one or more channels on a DAQ device. Complete the following steps to create and configure a task that reads a voltage level from a DAQ device. 

1. Open a new VI. 

2. On the block diagram, display the Functions palette and select Express>>Input to display the Input palette. 

3. Select the DAQ Assistant Express VI, shown at left, on the Input palette and place it on the block diagram. The DAQ Assistant launches and the Create New dialog box appears. 

4. Click Analog Input to display the Analog Input options. 

5. Select Voltage to create a new voltage analog input task. The dialog box displays a list of channels on each installed DAQ device. The number of channels listed depends on the number of channels you have on the DAQ device. 

6. In the Supported Physical Channels list, select the physical channel to which the instrument connects the signal, such as ai0, and then click the Finish button. The DAQ Assistant opens a new dialog box, shown in Figure 1, which displays options for configuring the channel you selected to complete a task.


[+] Enlarge Image


[+] Enlarge Image

Figure 1. Configuring a Task Using the DAQ Assistant

7. In the Input Range section of the Settings page, enter 10 for the Max
value and enter -10 for the Min value.

8. On the Task Timing page, select the N Samples option.

9. Enter a value of 1000 in the Samples To Read text box.

Testing the Task

You can test the task to verify that you correctly configured the channel. Complete the following steps to confirm that you are acquiring data. 

1. Click the Test button, shown at left. The DAQ Assistant dialog box appears. 

2. Click the Start button once or twice to confirm that you are acquiring data, and then click the Close button to return to the DAQ Assistant. 

3. Click the OK button to save the current configuration and close the DAQ Assistant. LabVIEW builds the VI. 

4. Save the VI as Read Voltage.vi in an easily accessible location.

Graphing Data from a DAQ Device

You can use the task you created in the previous exercise to graph the data acquired from a DAQ device. Complete the following steps to plot the data from the channel on a waveform graph and change the name of the signal. 

1. On the block diagram, right-click the data output and select Create>>Graph Indicator from the shortcut menu. 

2. Display the front panel and run the VI three or four times. Observe the waveform graph. 

Voltage appears in the plot legend at the top of the waveform graph. 

3. On the block diagram, right-click the DAQ Assistant Express VI and select Properties from the shortcut menu to open the DAQ Assistant. 

4. Right-click Voltage in the list of channels and select Rename from the shortcut menu to display the Rename a channel or channels dialog box.

5. In the New Name text box, enter First Voltage Reading, and click the OK button. 

6. In the DAQ Assistant dialog box, click the OK button to save the current configuration and close the DAQ Assistant. 

7. Display the front panel and run the VI. First Voltage Reading appears in the waveform graph plot legend. 

8. Save the VI.

Editing an NI-DAQmx Task

You can add a channel to the task so you can compare two separate voltage readings. You also can customize the task to acquire the voltage readings continuously. Complete the following steps to add a new channel to the task and acquire data continuously. 

1. On the block diagram, double-click the DAQ Assistant Express VI to open the DAQ Assistant. 

2. Click the Add Channels button, shown at left, and select the Voltage channel from the Add Channel menu to display the Add Channels To Task dialog box. 

3. Select any unused physical channel in the Supported Physical Channels list, and click the OK button to return to the DAQ Assistant. 

4. Rename the channel Second Voltage Reading. 

5. On the Task Timing page, select the Continuous option. 

When you set timing and triggering options in the DAQ Assistant, these options apply to all the channels in the list of channels. 

6. Click the OK button to save the current configuration and close the DAQ Assistant. The Confirm Auto Loop Creation dialog box appears. 

7. Click the Yes button. LabVIEW places a While Loop around the DAQ Assistant Express VI and the graph indicator. A stop button appears on the block diagram wired to the stop input of the DAQ Assistant Express VI. The stopped output of the Express VI is wired to the conditional terminal of the While Loop. The block diagram should appear similar to Figure 2.

Figure 2. Block Diagram of the Read Voltage VI

If an error occurs or you click the stop button while the VI is running, the DAQ Assistant Express VI stops reading data and the stopped output returns a TRUE value and stops the While Loop.

Visually Comparing Two Voltage Readings

Because you have two voltage readings displayed on a graph, you can customize the plots to distinguish between the two. Complete the following steps to customize the plot color on the waveform graph. 

1. On the front panel, expand the plot legend to display two plots. 

2. Run the VI. Two plots appear on the graph, and the plot legend displays both plot names. 

3. Right-click First Voltage Reading in the plot legend and select Color from the shortcut menu. Using the color picker, select a color such as yellow so the plot is easy to read. Change the plot color of Second Voltage Reading

4. Save the VI.

Communicating with an Instrument

Instrument drivers simplify instrument control and reduce test program development time by eliminating the need to learn the programming protocol for each instrument. 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. Use an instrument driver for instrument control when possible. National Instruments provides thousands of instrument drivers for a wide variety of instruments. 

In the following exercises, you will communicate with an instrument.

Finding and Installing Instrument Drivers (Windows and Linux)

Use the NI Instrument Driver Finder to search for and install LabVIEW Plug and Play instrument drivers without leaving the LabVIEW development environment. 

Note: The Instrument Driver Finder is available only on Windows and Linux. You must have Internet access to use the Instrument Driver Finder.

You also can visit the NI Instrument Driver Network at ni.com/idnet to find a driver for an instrument.

Complete the following steps to search for and install an instrument driver using the Instrument Driver Finder. 

1. Select Tools>>Instrumentation»Find Instrument Drivers or Help>>Find Instrument Drivers to launch the Instrument Driver Finder. 

2. Select National Instruments from the Manufacturer pull-down menu. 

3. Click the Search button. The folders on the Search Results page represent instrument drivers, and the contents of the folders represent the files that the Instrument Driver Finder can download and install. The Instrument Driver Finder opens the first driver folder in the list and selects a driver file. You can click different files and use the detailed information to the right to choose the correct driver for the instrument. 

4. Select the first instrument driver file from the Driver list and click the Install button. 

5. If you do not have an NI.com profile, select No, I need to create a profile and click the Create Profile button to open a browser window in which you can create an NI.com profile. If you do have an NI.com profile, skip to step 7. 

6. Create a profile and return to the Instrument Driver Finder. 

7. Select Yes, fill in your email address and ni.com password, and click the Login button. 

8. Click the Close button after the Instrument Driver Finder downloads and installs the instrument driver into the labview\instr.lib directory and displays the path to the newly installed driver. 

9. Click the Close button to close the Instrument Driver Finder. 

You also can create your own instrument drivers. Refer to the Controlling Instruments»Using Instrument Drivers book on the Contents tab in the LabVIEW Help for more information about creating instrument drivers.

Selecting an Instrument Using the Instrument I/O Assistant

If a driver is not available for an instrument, you can use the Instrument I/O Assistant Express VI to communicate with the instrument. 

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. 

Complete the following steps to use the Instrument I/O Assistant Express VI to select an instrument. 

1. Turn on the instrument you want to use. The instrument must be powered on to use the Instrument I/O Assistant Express VI. 

2. Select the Instrument I/O Assistant Express VI on the Input palette and place it on the block diagram. The Instrument I/O Assistant dialog box appears. 

3. Click the Show Help button, shown at left, in the upper right corner of the Instrument I/O Assistant dialog box. 

The help appears to the right of the dialog box. The top help window contains how-to information about using the Instrument I/O Assistant. The bottom help window provides context-sensitive help about components in the dialog box. 

4. Click the Select Instrument link in the top help window and follow the instructions in the help window to select the instrument with which you want to communicate. 

5. If necessary, configure the properties of the instrument. 

6. If you want to minimize the help window, click the Hide Help button, shown at left, in the upper right corner of the Instrument I/O Assistant dialog box.

Acquiring and Parsing Information for an Instrument

After you select the instrument, you can send commands to the instrument to retrieve data. In this exercise, you will learn to use the Instrument I/O Assistant Express VI to acquire and parse identification information for an instrument. Complete the following steps to communicate with the instrument. 

1. In the Instrument I/O Assistant dialog box, click the Add Step button and click the Query and Parse step. 

2. Enter *IDN? in the Enter a command text box. 

*IDN? is a query that most instruments recognize. The response is an identification number string that describes the instrument. If the instrument does not accept this command, refer to the reference manual for the instrument for a list of commands the instrument does accept. 

3. Click the Run button, shown at left. The Instrument I/O Assistant sends the command to the instrument, and the instrument returns its identification information. 

4. Select ASCII only from the pull-down menu below the Byte index column of the response window to parse the instrument name as an ASCII string. You also can use the Instrument I/O Assistant to parse ASCII numbers and binary data. 

5. Click the Parsing help button, shown at left, in the Instrument I/O Assistant dialog box to display information about parsing data. 

6. In the ASCII representation column of the response window, click the value you want to parse. 

7. Enter a name for the token, or parsed data selection, in the Token name text box. The name that you entered in the Token name text box is the output of the Instrument I/O Assistant Express VI, shown at left.

Wiring a Command to an Instrument

After you acquire data from the instrument, you can add an input parameter to an instrument command. The parameter becomes an input to the VI or function. Complete the following steps to add a parameter to a command. 

1. Click the Add Step button and click the Write step. 

2. Enter *IDN? in the Enter a command text box. 

3. Select the command in the Enter a command text box and click the Add parameter button to add a parameter to the command. 

4. Enter a default value for the parameter in the Test value text box. 

5. Enter a name for the parameter in the Parameter name text box. You use this name to reference the parameter in the application. 

6. Click the OK button to save the current configuration and close the Instrument I/O Assistant dialog box.

Summary

The following topics are a summary of the main concepts you learned in this chapter.

DAQ Assistant Express VI

You can use the DAQ Assistant Express VI to interactively build measurement channels or tasks. 

Place the DAQ Assistant Express VI on the block diagram to configure channels and tasks for use with NI-DAQmx for data acquisition. NI-DAQmx is a programming interface you can use to communicate with data acquisition devices. You can use the DAQ Assistant Express VI to control devices supported by NI-DAQmx. 

Refer to the Getting Started»Getting Started with DAQ»Taking an NI-DAQmx Measurement in LabVIEW book on the Contents tab in the LabVIEW Help for information about the DAQ Assistant. 

Refer to the NI-DAQ Readme for information about devices supported by NI-DAQmx. If NI-DAQmx does not support the device you want to use, refer to the Taking Measurements book on the Contents tab in the LabVIEW Help for information about using Traditional NI-DAQ (Legacy) for data acquisition.

Tasks

In NI-DAQmx, a task is a collection of one or more channels, timing, triggering, and other properties. Conceptually, a task represents a measurement or generation you want to perform. F

or example, you can configure a collection of channels for analog input operations. After you create a task, you can access the single task instead of configuring the channels individually to perform analog input operations. After you create a task, you can add or remove channels from that task. 

Refer to the Taking Measurements book on the Contents tab in the LabVIEW Help for more information about channels and tasks.

Instrument Drivers

Use the NI Instrument Driver Finder to search for and install LabVIEW Plug and Play instrument drivers without leaving the LabVIEW development environment. 

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. Use an instrument driver for instrument control when possible. National Instruments provides thousands of instrument drivers for a wide variety of instruments. 

Refer to the Controlling Instruments>>Using Instrument Drivers book on the Contents tab in the LabVIEW Help for more information about the Instrument Driver Finder. 

You also can visit the NI Instrument Driver Network at ni.com/idnet to find a driver for an instrument, or you can create your own instrument drivers. Refer to the Controlling Instruments>>Using Instrument Drivers book on the Contents tab in the LabVIEW Help for more information about creating instrument drivers.

Instrument I/O Assistant Express VI

If a driver is not available for an instrument, you can use the Instrument I/O Assistant Express VI to communicate with the instrument. You can use the Instrument I/O Assistant to communicate with message-based instruments and graphically parse the response. Start the Instrument I/O Assistant by placing the Instrument I/O Assistant Express VI on the block diagram or by double-clicking the Instrument I/O Assistant Express VI icon on the block diagram. 

Refer to the Instrument I/O Assistant Help for information about communicating with an external device. Display the Instrument I/O Assistant Help by clicking the Show Help button in the Instrument I/O Assistant dialog box.

Downloads

acquiring_data1.pdf

2 ratings | 2.50 out of 5
Print | PDF

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).