Connect to Measurement Hardware Using LabVIEW

Updated Oct 21, 2020



  • LabVIEW


  • NI-DAQmx

Use LabVIEW to connect to your measurement hardware, both NI DAQ devices and third-party instruments, to acquire or generate a variety of signal types. Learn how to acquire an analog signal using NI DAQ hardware and the NI-DAQmx driver with the provided sample code.

Connect to Your Measurement Hardware

To begin taking measurements using the sample code provided, download and install the NI-DAQmx driver to interface and configure your NI data acquisition devices. Use the code in the Connect to NI DAQ Hardware for this guide.

To connect to your hardware:

  1. Connect your NI DAQ device to your computer.
  2. Open Measurement & Automation Explorer (MAX) and expand the Devices and Interfaces drop-down. You can see your device listed as connected to your system.

Figure 1: Discovering hardware in MAX.
MAX is device management software installed with all NI hardware drivers for the configuration of NI hardware and software, replication of configuration data, performing system diagnostics, and updating NI software.

Create a Simulated Device

If you don’t have NI data acquisition hardware yet, you can use this guide by creating a simulated device that replicates hardware behavior to run functions or programs. To create a simulated device, open Create Simulated from the attached sample code. Run the code by clicking on the run arrow. This VI creates a simulated device called SimuDAQ on your computer, which is discussed later in this guide.

Figure 2: If you don't have hardware, follow along with a simulated device.


Acquire a Signal Using the DAQ Assistant

  1. Open Acquire Analog Inputs Using the DAQ from the Connect to NI DAQ Hardware.lvproj. This VI includes a prebuilt UI and analysis code. For this exercise, you need to add the code required to acquire a signal.

    Figure 3: Starting Point.


    2. The DAQ Assistant provides a step-by-step guide for configuring, testing, and programming measurement tasks. Start by adding a DAQ Assistant Express VI to your diagram. To do this, right-click on your block diagram and navigate to Measurement I/O»NI-DAQmx»DAQ Assistant, and then click and place the DAQ Assistant icon onto your block diagram. Alternatively, you can press <Ctrl-Space> to open Quick Drop, type DAQ Assistant, and select the entry from the list.

    Figure 4: Navigating to the DAQ Assistant.


3. When you place the DAQ Assistant on your block diagram, the measurement configuration dialog box opens to help you set up your task. The first step is to select your type of measurement and channel. You have several options for an analog input acquisition. This exercise steps through a simple voltage measurement, but if you’re using your own device and sensor, you can select the appropriate measurement type and channel for your system. Configure your measurement by selecting Acquire Signals»Analog Input»Voltage.

Figure 5: Selecting Signal Type.
4. The next step is to select your channels. If you are using your own NI data acquisition hardware, it is listed by device name. Dev1 is the default for a system with only one DAQ device plugged in. If you’re using the simulated device from Part 1 of this guide, it is listed under the name SimuDAQ. Select the appropriate analog input channel from your physical device (if available) or select ai0 if you’re using the simulated device.
Figure 6: Selecting Channel(s).
5. Once you have selected your channel(s), click the Finish button. This launches the analog input task configuration page. Here you can select your acquisition type, sampling rate, number of samples, and voltage range. Under Timing Settings, use the default Acquisition Mode of N samples, change the number of samples to red to be 1k, and use the default sampling rate of 1 kHz. You can preview your data by clicking the Run button at the top of the window.

Figure 7: Configuring and Testing Acquisition Parameters.
6. When you’ve finished configuring your acquisition parameters, click OK. The DAQ Assistant automatically generates the code required to implement your acquisition. To complete the system, wire the data output of your DAQ Assistant to the inputs of the analysis VIs as shown below.

Figure 8: Completed Block Diagram.
7. Switch to the front panel and run the program to see your raw signal data and filtered data as well as the minima, maxima, and mean of the acquired signal.

Figure 9: Visualize raw data, filtered data, and points of interest. 

You can find the finished VI in the Solutions folder in the Connect to NI DAQ Hardware.lvproj.

Acquiring a Signal Using NI-DAQmx

Though the DAQ Assistant provides a quick and easy way to acquire or generate data without programming, more advanced users may need added flexibility and lower-level control than what the DAQ Assistant offers. The NI-DAQmx driver features a comprehensive API of basic and advanced functions for control over such parameters as timing, synchronization, data manipulation, and execution control.

Figure 10: The DAQmx API provides added programming flexibility.

Open Acquire Analog Inputs using the DAQmx for an example of a more advanced application. Here you can configure channels, recording options, triggering options, and advanced timing settings.