Transition from Traditional NI-DAQ to NI-DAQmx in LabVIEW

Publish Date: May 11, 2011 | 39 Ratings | 2.08 out of 5 |  PDF

Table of Contents

  1. Overview
  2. Analog Input
  3. Analog Output
  4. Digital Output
  5. Counter Pulse Train Generation
  6. Shared Clocks over RTSI (Interoperability of Traditional NI-DAQ and NI-DAQmx)
  7. Tips and Tricks for NI-DAQmx in LabVIEW 7.0

The National Instruments Getting Started with NI-DAQmx Series is aimed at helping you learn NI-DAQmx programming fundamentals. Through video and text tutorials, this series will take you from verifying your device's operation in Measurement & Automation Explorer (MAX) to programming data acquisition applications using LabVIEW. It is intended for both the beginner who wants to learn how to use the DAQ Assistant, as well as the experienced user who wishes to take advantage of advanced NI-DAQmx functionality.

1. Overview

This reference guide demonstrates how to migrate applications written in Traditional NI-DAQ to NI-DAQmx. The purpose of this document is to show the key differences between the two data acquisition (DAQ) drivers, as well as discuss some common tips to use while programming in NI-DAQmx.

NI recommends starting with a new VI and using the old VIs written in Traditional NI-DAQ as a guide. Although many of the programming techniques are similar, there are some slight differences that will be pointed out in this document. Please note that this article is intended to be a supplement to the other help documents available, not a substitution. After you understand what is described in this article, you should have a clear idea of the main differences to keep in mind when programming in NI-DAQmx.

Since it is recommended to start code from scratch, here are a few guidelines and suggestions to make that transition as easy as possible. A helpful new tool available in LabVIEW 7.0 is the DAQ Assistant. With this assistant, you can designate what you want your code to do in Measurement & Automation Explorer (MAX), and then generate code based on that task.  After generating the code, you can then edit it by adding property nodes or changing the configuration to meet the needs of your specific application. If you would like more information on how the DAQ Assistant works, refer to Taking an NI-DAQmx Measurement in LabVIEW, located in LabVIEW Help at LabVIEW Help::Getting Started::Getting Started With DAQ::Taking an NI-DAQmx Measurement...

One major difference between the two drivers is in the palettes. In Traditional NI-DAQ, there is a different palette for each type of operation, such as a digital palette for digital operations, an analog input palette for all analog input operations, and so on. In NI-DAQmx, just one set of VIs is used for all operations, and you can configure each VI for a specific type of acquisition. For example, in Traditional NI-DAQ, you use the AI Config VI to configure a channel or set of channels for analog input. In NI-DAQmx, you use the DAQmx Create Channel VI, and configure this VI for Analog Input::Voltage. This distinction makes it easier to become familiar with the specific VIs needed to perform various operations. 

 

Back to Top

2. Analog Input


(Click to Enlarge)

Figure 1. Traditional NI-DAQ: Cont Acq&Graph (buffered).vi


(Click to Enlarge)

Figure 2. NI-DAQmx: Cont. Acq&Graph Voltage-Int Clk.vi


This example shows the difference between performing continuous analog input with an internal clock in Traditional NI-DAQ and NI-DAQmx. To translate a program written with Traditional NI-DAQ into NI-DAQmx, follow these steps:

 

  1. First, replace the AI Config VI with the DAQmx Create Channel VI.
  2. Configure the DAQmx Create Channel VI to be an Analog Input>>Voltage VI by clicking on the purple outlined box below the VI. This information needs to be set because the DAQmx Create Channel VI is a polymorphic VI used for all types of acquisition. This is unlike Traditional NI-DAQ where different VIs are used for the different types of acquisitions.
  3. Create the controls on the front panel so that the data types correlate. Notice that there are no longer device number and channel name controls because they are combined into one control denoted by the Physical Channel. Another configurable input on this VI is the Input Terminal Configuration. The board automatically defaults to Differential mode. The referencing mode is no longer set in MAX, to measure in NRSE or RSE, you must specify it here.
  4. Now insert the DAQmx Timing VI after the DAQmx Create Channel VI. The DAQmx Timing VI sets the sample rate and creates the buffer for continuous acquisition. Since continuous acquisition is specified, LabVIEW automatically creates a buffer to make use of buffered acquisition.
  5. Replace the AI Start VI with the DAQmx Start Task VI, which is similar in functionality. The most significant difference between the two is that the sample rate is no longer set when you start the acquisition, but instead set with the DAQmx Timing VI.
  6. Replace the AI Read VI with the DAQmx Read VI.
  7. Configure the DAQmx Read VI for Analog>>Multiple Channels>>Multiple Samples>>1D Waveform.
  8. Create the constants, controls, and indicators so they are connected to the correct terminals.
  9. Replace the AI Clear VI with the DAQmx Clear Task VI. The inputs to this VI are the same and it performs the same function.

Back to Top

3. Analog Output


(Click to Enlarge)

Figure 3. Traditional NI-DAQ: Continuous Generation IntClk.vi


(Click to Enlarge)

Figure 4. NI-DAQmx: Cont Gen Voltage Wfm-Int Clk.vi

This example shows the difference between Continuous Analog Output in Traditional NI-DAQ and NI-DAQmx. To convert a program written in Traditional NI-DAQ to NI-DAQmx, follow these steps:

 

  1. First, replace the AO Config VI with the DAQmx Create Channel VI.
  2. Create all the controls so that the data types match. In NI-DAQmx, the Physical Channel input specifies the device number as well as the channel number, instead of the two separate controls required in Traditional NI-DAQ.
  3. Replace the Compute Waveform VI with a very similar VI called Waveform Buffer Generation VI. This new VI passes the task through the waveform generation VI, as opposed to having to wire around it as in Traditional NI-DAQ.
  4. Replace the AO Write VI with both the DAQmx Timing VI and the DAQmx Write VI.
  5. Configure the DAQmx Timing VI for the Sample Clock. The DAQmx Timing VI, when configured for the Sample Clock, specifies the sample mode as well as the clock source to use.
  6. Set the DAQmx Write VI to use Analog>>Single Channel>>Multiple Sample>>Waveform.
  7. Create the necessary inputs and make sure the data types are equivalent.
  8. Replace the AO Start VI with the DAQmx Start Task VI. Both of these VIs have similar inputs and outputs and generally perform the same functions.
  9. Inside the while loop, substitute the AO Write VI with the DAQmx Is Task Done VI. Because this example uses continuous generation, you do not necessarily need to use the DAQmx Is Task Done VI because the task will not be complete until you press the stop button on the front panel. However, if you are performing a finite generation, this VI is essential to signify the end of the operation.
  10. Replace the AO Clear VI with the DAQmx Clear Task VI. Both of these VIs achieve the same function.

Back to Top

4. Digital Output


(Click to Enlarge)

Figure 5. Traditional NI-DAQ: Write to 1 Dig Port.vi



(Click to Enlarge)

Figure 6. NI-DAQmx: Write Dig Port.vi


The example above illustrates the difference between doing Digital Port Writes in Traditional NI-DAQ and in NI-DAQmx. To move a Traditional NI-DAQ program to NI-DAQmx, follow these steps:

  1. First, replace the DIO Port Config VI with both the DAQmx Create Channel VI and the DAQmx Start Task VI.
  2. Configure the DAQmx Create Channel VI for Digital Output.
  3. Create controls and make sure the data types of the controls match up correctly.
  4. When creating the port control, specify the entire port and not just a specific line number.
  5. Now substitute everything inside the while loop except the Wait function and the stop button with the DAQmx Write VI.
  6. Configure the DAQmx Write VI for Digital>>Single Channel>>Single Sample>>U8 (Port Format). This VI takes care of writing all the data.
  7. Add a DAQmx Clear Task VI outside the while loop to clear the task created for the program.

Back to Top

5. Counter Pulse Train Generation


(Click to Enlarge)

Figure 7. Traditional NI-DAQ: Generate Pulse Train (DAQ-STC).vi



(Click to Enlarge)

Figure 8. NI-DAQmx: Gen Dig Pulse Train-Continuous-Pause Trigger.vi


This example demonstrates the difference between doing Continuous Pulse Train Generation in Traditional NI-DAQ and NI-DAQmx. Follow these steps to transition a program written in Traditional NI-DAQ to NI-DAQmx.

  1. First, replace the Counter Group Config VI with the DAQmx Create Channel VI.
  2. Configure the DAQmx Create Channel VI for Counter Output>>Pulse Generation>>Frequency.
  3. Create separate controls for the Duty Cycle, Frequency, Counter, and Idle State. The Counter control specifies which device as well as which counter to use. The Idle State input informs the counter in which state to start and to which state to return after the pulse train has completed. The Set Pulse Specs VI is no longer needed because those values are set on the DAQmx Create Channel VI instead.
  4. Replace the Counter Gate (STC) VI with a DAQmx Trigger property node. Set the Trigger Type to Digital Level in the property node, and then create a control on the front panel to select the source of the gate.
  5. Insert the DAQmx Timing VI after the DAQmx Trigger property node. The DAQmx Timing VI is configured to Implicit (Counter). This VI indicates the duration of the pulse generation.
  6. Add a DAQmx Timing property node after the DAQmx Timing VI. In this case, the timing property node specifies the onboard clock and configures an external clock, if desired. This is used in lieu of the case structure in the Traditional NI-DAQ example.
  7. Replace the Counter Control VI with a DAQmx Is Task Done VI inside the while loop. The purpose of this VI is to check when finite generation is finished. For this example, the DAQmx Is Task Done VI can be omitted since it is continuous, but if performing finite generation, you need to include this VI.
  8. Replace the Counter Control VI with the DAQmx Clear Task VI. The inputs to this new VI are very similar, except that the task automatically resets without specifying to do so.

Back to Top

6. Shared Clocks over RTSI (Interoperability of Traditional NI-DAQ and NI-DAQmx)


(Click to Enlarge)

Figure 9. Traditional NI-DAQ: Share 653x REQ Clock with E Series AI Sample Clock.vi



(Click to Enlarge)

Figure 10. NI-DAQmx: Share 653x REQ Clock with E Series AI Sample Clock.vi


This example illustrates how to synchronize a 653X board with an E Series board. The REQ clock of the 653X is used as the sample clock for an analog input acquisition on the E Series board. This is shown above using Traditional NI-DAQ as well as NI-DAQmx. The example demonstrates the flexibility and the interoperability of the two drivers, and how much clearer RTSI use is in NI-DAQmx. The digital board portion on both examples uses the Traditional NI-DAQ driver, so this explanation describes only how to convert the segment of code running on the E Series board.

  1. First, replace the AI Config VI with the DAQmx Create Channel VI.
  2. Configure the DAQmx Create Channel VI to be an Analog Input>>Voltage VI.
  3. Create the controls on the front panel and the necessary constants.
  4. Replace the AI Clock Config VI with the DAQmx Timing VI. The DAQmx Timing VI sets the sample rate and creates the buffer, because continuous acquisition is desired. The buffer is acquired automatically since it is set up for continuous acquisition. One important input to this VI is the Source. Leave the input blank if you want to use the default onboard clock. For this example, however, create a constant and set it to use the RTSI pin that is routed from the digital board (which in this case is /Dev4/RTSI0). Notice that this name permits you specify a different device number. This is important because NI-DAQmx accomplishes all the internal routing for you.
  5. Replace the AI Control VI with the DAQmx Start Task VI, which is similar in functionality.
  6. Replace the AI Read VI with the DAQmx Read VI.
  7. Configured the DAQmx Read VI for Analog>>Single Channel>>Multiple Samples>>1D Waveform. You must provide this information because the DAQmx Read VI is a polymorphic VI used for all types of data acquisition (as opposed to Traditional NI-DAQ, where there are many unique VIs for different types of acquisition).
  8. Replace the AI Clear VI with the DAQmx Clear Task VI. The inputs to this VI are the same and they perform the same functionality.

Back to Top

7. Tips and Tricks for NI-DAQmx in LabVIEW 7.0

  • Basic DAQ programming (analog input/output, digital input/output) is simpler and more streamlined in NI-DAQmx. There is one basic structure for all DAQ programs that uses the same collection of VIs, instead of having a separate set of VIs for each type of input/output as in Traditional NI-DAQ.
  • The more advanced concepts such as counters, triggering, timing and synchronization require a shift in programming mindset from Traditional NI-DAQ. In NI-DAQmx, you must use property nodes for certain advanced functionality. The property names are descriptive, such as the Clock Source property, which specifies the terminal of the signal to use as the sample clock). For more help, see KnowledgeBase 2X87BR7Y linked below: Where to Find NI-DAQmx Property Nodes Listings and Help.
  • Start by looking at examples already written in NI-DAQmx.
  • Don’t try to convert the Traditional NI-DAQ code you already have. Instead, start from scratch, using the DAQ Assistant to configure your own measurement tasks and generate code for them. Code generation is helpful to see how to set up basic functions. The only issue may be that the configuration code is in a subVI, so you must copy and paste it to the main VI if you want the controls on the front panel of the main VI. Then you can add more functionality and other VIs to the generated code.
  • With NI-DAQmx, many of the terminal and signal names have been changed so they are easier to understand and more consistent across NI hardware and software products. This change in terminology is explained in KnowledgeBase 2X7MTTN1 linked below: What are the Terminology Changes in NI-DAQmx?
  • At the most basic level, programming in NI-DAQmx involves creating a task, and then reading or writing. A task is just a virtual channel with added features, including custom configuration such as timing, triggering, and scales. Virtual channels are integral to NI-DAQmx, not just an added feature as in Traditional NI-DAQ. For more information on tasks and virtual channels please see the NI-DAQmx help, which is installed with NI-DAQmx.

Related Links:
KB 2X87BR7Y: Where to Find NI-DAQmx Property Nodes Listings and Help
KB 2X7MTTN1: What are the Terminology Changes in NI-DAQmx?
KB 1Z5D23PH: Manuals for NI-DAQ
Developer Zone Tutorial: NI-DAQmx Installed Documentation

 

Back to Top

Bookmark & Share


Ratings

Rate this document

Answered Your Question?
Yes No

Submit