Using NI-DAQmx in LabWindows/CVI



This paper discusses recent innovations in data acquisition implementations within the LabWindows/CVI development environment. LabWindows/CVI is widely used by engineers and scientists who want to take advantage of NI state-of-the-art hardware functionality in an ANSI C environment. Countless engineers and scientists involved in manufacturing test, design validation, lab, research, and service industries have increased their productivity and decreased their development time by adopting LabWindows/CVI as their application development tool.

Data acquisition (DAQ) driver software from NI, known as NI-DAQ, has been a core element in developing a successful DAQ application by today's standards. Determined to provide tools that not only meet today's requirements but also meet tomorrow's requirements, NI introduced the next-generation multithreaded driver software – NI-DAQmx.

By incorporating new multithreaded NI-DAQmx functions and features such as the DAQ Assistant, LabWindows/CVI now can deliver up to 40 times faster execution speed when running a concurrent I/O DAQ application.

NOTE: You can use the NI-DAQmx Library with LabWindows/CVI versions 7.0 and higher. Use Traditional NI-DAQ with earlier versions of LabWindows/CVI.

NI-DAQmx provides intuitive functions you can use to complete the same tasks you completed with Traditional NI-DAQ, which helps you develop optimized test programs quickly. Whether you are an existing LabWindows/CVI user or you have experience building DAQ applications, you will appreciate more intuitive, multithreaded NI-DAQmx functions; the DAQ Assistant; and tasks that help you improve performance and reduce development time. This white paper discusses how you can use NI-DAQmx in LabWindows/CVI to improve performance and reduce development time.


Improving Performance

NI-DAQmx driver software is designed to help you significantly improve performance by exploiting the computer processor power and the memory structure of operating systems. NI-DAQmx driver software uses a multithread application structure to maximize computer processor power and implements memory-mapped registers to produce unprecedented concurrent and single-point I/O performance. As a result, you can experience up to 40 times better performance when you perform a concurrent I/O operation and 20 times faster execution speed when you perform a single-point I/O operation.

NI-DAQmx is an innovative driver software architecture that incorporates multithread technology. With multithreaded DAQ operations, you can perform an I/O operation independently in a separate thread. This guarantees faster execution speeds when you perform concurrent operations. Performing a concurrent operation, such as generating a continuous analog output waveform while acquiring a continuous analog input signal, in a single-threaded environment can be extremely challenging and can yield slow performance unless you employ complicated programming and timing techniques. Because NI-DAQmx driver software is multithreaded, it guarantees the simultaneous operation of analog input acquisition and analog output generation by assigning a separate thread to each operation. This eliminates the need to develop a complicated program to create an optimized concurrent operation. You can implement a multithreaded DAQ operation simply by using the NI-DAQmx Library.

Figure 1 shows a synchronized AI/AO operation example program (Learn how to find and install this NI-DAQmx example for LabWindows/CVI). As the pictured code shows, you can use NI-DAQmx functions to implement multithreaded DAQ operations in LabWindows/CVI simply. You do not have to manually allocate separate threads for each analog input and analog output operation. The NI-DAQmx functions allocate the threads automatically. Therefore, with the NI-DAQmx Library, you can develop a multithreaded DAQ application without spending time implementing the details.

Figure 1. Multithreaded DAQ Program

The time it takes to access the hardware register to initiate each I/O operation determines the execution speed in a continuous single-point I/O operation. NI-DAQmx driver software implements memory-mapped registers to reduce the hardware register access time and improve the overall performance of a single-point I/O operation. With memory-mapped register implementation, NI-DAQmx driver software delivers up to 50 kHz loop rates when performing a single-point I/O operation. This represents 20 times improvement over the Traditional NI-DAQ driver software for a software-timed, single-point I/O operation.


Reducing Development Time

With faster computers and advanced tools readily available to you, more often than not you are expected to complete development projects quickly. The DAQ Assistant and NI-DAQmx Library were developed to help you overcome these time constraints. Using the DAQ Assistant and NI-DAQmx Library, you can shorten development time and deliver an optimized, professional application.

Reduce Development Time with the DAQ Assistant

The DAQ Assistant is an interactive tool you can use to graphically configure a customized DAQ operation, known as a task, to incorporate into a LabWindows/CVI project. As shown in Figure 2 and Figure 3, you can define a complicated task, such as an analog start/stop triggered data acquisition using an externally provided scan clock, with a few mouse clicks in the DAQ Assistant.

Figure 2. DAQ Assistant Displaying Timing Tab

Figure 3. DAQ Assistant Displaying Triggering Tab

Once you create the task, you can import the task into an application by selecting the name of task within a LabWindows/CVI function panel, as shown in Figure 4.

Figure 4. DAQmxLoadTask Function Panel

Prior to NI-DAQmx, DAQ driver software was merely a group of functions you could call in the LabWindows/CVI environment to implement DAQ applications. If you wanted to set a specific sampling rate, configure a digital start trigger, and change the gain setting for a given operation, you had to call separate functions for each task. If requirements changed, such as from a single-buffered acquisition to a double-buffered acquisition, you had to modify the program thoroughly to implement those changes. You might have to replace more than half of the source code to implement such changes. With the DAQ Assistant and NI-DAQmx, you can update any change by reloading the DAQ Assistant and changing the configuration settings. Because the DAQ Assistant generates the necessary code, you do not need to modify the source code at all, which makes development faster and more productive.

LabWindows/CVI also can automatically generate source code based on the customized loaded task, which also saves you development time. Using convenient built-in DAQ tools, you can develop an advanced DAQ application without manually developing mundane tasks.

Reduce Development Time with the NI-DAQmx Library

Figure 5. NI-DAQmx General Programming Flow for Continuous Analog Input Operation

Figure 5 shows the general programming flow you use to acquire an analog input signal using the NI-DAQmx Library. Using the four functions shown, you can acquire analog input signals with or without a triggering condition enabled using either an internal or an external clock. The complexity level of data acquisition does not affect the number of functions you use when you take advantage of the NI-DAQmx Library. As a result, the number of functions you need to complete a complicated task, such as a single-buffered acquisition with digital triggering enabled, has been drastically reduced from 16 lines of code when using Traditional NI-DAQ, as shown in Figure 6, to six lines of code when using NI-DAQmx, as shown in Figure 7. You also will notice that the names of NI-DAQmx functions are much more intuitive than their Traditional NI-DAQ counterparts.

Figure 6. Single-Buffered Acquisition with External Digital Triggering Using Traditional NI-DAQ

Figure 7. Single-Buffered Acquisition with External Digital Triggering Using NI-DAQmx


Other Benefits of Using NI-DAQmx

You can store tasks you create in the DAQ Assistant locally in LabWindows/CVI or globally in the Measurement & Automation Explorer (MAX) utility. You can access globally stored task configurations not only from LabWindows/CVI but also from LabVIEW or Measurement Studio for Visual Studio. You can reuse these global tasks among colleagues and among tests. If you plan to deploy an application to multiple test stations, you also can benefit from this portability.

You can create virtual channels in MAX to integrate into an application program. Any channel-specific settings such as device number, channel number, gain setting, measurement type (voltage, current, temperature, and so on), and scaling information is stored globally in a virtual channel. You can then import these settings into an application program to avoid having to specify each detail in the program.



By using NI-DAQmx with LabWindows/CVI, you can take full advantage of multithread technology and memory-mapped registers to achieve up to 40 times faster execution speed. NI-DAQmx also offers efficient tools, such as the DAQ Assistant, to help you to reduce development time.

Related Links

Was this information helpful?