Using CompactRIO with the NI-DAQmx API

Publish Date: Jun 01, 2018 | 1 Ratings | 5.00 out of 5 | Print | Submit your review

Overview

CompactRIO with NI-DAQmx is the latest addition to the CompactRIO controller family. It brings two software experiences into one by combining the ease-of-use of NI-DAQmx and the low-level functionality of LabVIEW FPGA.

This tutorial introduces the different programming modes available to CompactRIO with NI-DAQmx controllers, and then demonstrates how to set up a simple acquisition using the NI-DAQmx API. This tutorial demonstrates continuous acquisition of analog data from multiple channels using a CompactRIO 9048 controller. The CompactRIO 904x controllers are the first to support NI-DAQmx programming. To see the full list, visit the CompactRIO Store Page and sort by Programming Method.

Table of Contents

  1. Select the Appropriate Programming Model
  2. Starting a New CompactRIO Project in LabVIEW
  3. Acquire Data using the Real-Time DAQmx API
  4. Next Steps

1. Select the Appropriate Programming Model

LabVIEW provides three programming models for CompactRIO systems. To select the appropriate programming model, it is important to understand how the data is transported from the physical input and output ports on the RIO target to the embedded system components. When using a CompactRIO, there are three ways to access I/O. In this tutorial, Real-Time (NI-DAQmx Mode) is used.

Real-Time (NI-DAQmx) Mode – CompactRIO with NI-DAQmx is the latest addition to the CompactRIO controller family. It brings two software experiences into one by combining the ease of use of NI-DAQmx and the low-level functionality of LabVIEW FPGA. It also simplifies system architectures by bringing the latest in synchronization and control technologies to the CompactRIO platform. To program a C Series module in this mode, place it under the Real-Time Resources folder in the LabVIEW project. This tutorial will cover how to set up a simple data acquisition using NI-DAQmx.

Real-Time Scan (I/O Variable) Mode – This option allows you to program the real-time processor of your CompactRIO system, but not the FPGA. In this mode, NI provides a pre-defined personality for the FPGA that periodically scans the I/O and places it in a memory map, making it available to LabVIEW Real-Time. CompactRIO Real-Time Scan Mode is sufficient for applications that require single-point access to I/O at rates of a few hundred hertz. To program a C Series module in this mode, place it under the Real-Time Scan Resources folder in the LabVIEW project. See Performing Basic Control with Real-Time Scan Mode tutorial for more information.

LabVIEW FPGA Interface Mode – This option allows you to unlock the real power of CompactRIO by customizing the FPGA personality in addition to programming the real-time processor, achieving performance that would typically require custom hardware. Using LabVIEW FPGA, you can implement custom timing and triggering, off-load signal processing and analysis, create custom protocols, and access I/O at its maximum rate. To program a C Series module in this mode, place it under the FPGA target in the LabVIEW project. See Offload Signal Processing With LabVIEW FPGA tutorial for more information. 

The figure below shows how each mode sends the I/O data through a unique path. For Real-Time (NI-DAQmx) mode, the data is read through the processor via NI-DAQmx VI’s. For Real-Time Scan (IO Variable) mode, the data is sent through the FPGA, but is ultimately accessed on the processor by dragging and dropping IO Nodes to the Real-Time VI. For LabVIEW FPGA mode, the I/O is read from directly from within the FPGA by dragging and dropping IO Nodes to the FPGA VI.

If you have LabVIEW Real-Time, LabVIEW FPGA, and NI-DAQmx on your development computer, you can select which programming model to use on a per-module basis by placing the module under the appropriate heading in the project. The programming mode is indicated by the text next to the module in the LabVIEW project. You can also select which programming model to use by selecting from the drop-down menu in Measurement and Automation Explorer (MAX). For this tutorial, ensure that the programming mode on your CompactRIO is set to Real-Time (NI-DAQmx)

Back to Top

2. Starting a New CompactRIO Project in LabVIEW

Begin by creating a new project in LabVIEW to manage your code and hardware resources.

1. Create a new project in LabVIEW by selecting File»Create Project. Then select Blank Project. Save the project by selecting File»Save and entering a unique name, such as CompactRIO Using NI-DAQmx. Click OK

2. The default project includes My Computer, which is where you can write code that runs on the Windows machine you’re currently developing on. Remember that a real-time target has a processor running a real-time OS, so it's effectively another computer. To write code that runs on that computer, you need to add another target to your project. Right-click on the Project item at the top of the tree and select New»Targets and Devices… to add a real-time system to the project.

3. With this dialog, you can discover existing systems on your network or add a new system. If you have already configured your CompactRIO system in LabVIEW or in NI MAX, select Existing Target or Device, and Discover an existing target(s) or device(s). Expand the Real-Time CompactRIO folder and select your device, then press OK. If your device is connected to a remote subnet, you may need to connect via IP address. Select Specify a target or device by IP address and enter the IP address of your device. LabVIEW lists available hardware corresponding with the drivers you have installed. Since you installed the NI-RIO driver with your evaluation software, expand the Real-Time CompactRIO folder and then select cRIO-9045. Press OK.

4. Confirm that your C-Series Modules appear under the Real-Time Resources section. In this tutorial, you are using an NI-9215 analog input module.

Back to Top

3. Acquire Data using the Real-Time DAQmx API

1. You should now have a new LabVIEW project that contains your CompactRIO system, including the controller, chassis, and C Series I/O modules. In the LabVIEW project, right click on the CompactRIO real-time controller and select New»VI. Save the VI as DAQmx.vi. This VI is where you will perform your data acquisition and processing using NI-DAQmx.

2. Begin by creating a Virtual DAQmx Channel by right clicking on the Front Panel and navigating to Measurement I/O»DAQmx – Data Acquisition»DAQmx Create Virtual Channel. Drag this VI to the front panel.

3. Right click on the Physical Channels input terminal of the DAQmx Create Virtual Channel VI and select Create » Constant. Click Browse and select all channels by holding down Shift and clicking through the items. This will allow us to read from all four analog input channels in one virtual channel. If you cannot see any channels, confirm that your device is connected, and that your individual modules are configured for Real-Time (NI-DAQmx) programming in NI MAX.

4. Find the DAQmx Timing VI in the DAQmx – Data Acquisition palette and drop it on the front panel. Right click on the rate terminal and select Create»Constant. This is where you can set a custom sample rate for your acquisition. Ensure that this is set to 1000Hz. Repeat this process for the sample mode terminal, and choose Continuous Samples from the drop-down list. This will allow us to continuously take data.

5. Create a While Loop. In the DAQmx – Data Acquisition palette, find the DAQmx Read VI, and place it inside the loop. Because you are reading multiple samples from four channels, click on the drop-down menu on the VI, and select Analog»Multiple Channels»Multiple Samples»1D Waveform (Samples). 

6. Open the Front Panel of your VI and create a Waveform Chart by right-clicking to open the palette, then selecting Silver»Graph»Waveform Chart (Silver). On the Block Diagram, connect the data terminal of the DAQmx Read to your waveform chart. This will display your waveform data. Add a Wait (ms) function and a stop button to your loop. Your final VI should look like the one below. Note: This screenshot is a VI Snippet that you can copy into LabVIEW by clicking and dragging to your block diagram.

7. Run your VI. LabVIEW will connect to the CompactRIO, deploy the code, and then run the code on the real-time target. You can view the data on the waveform chart you have created.

Back to Top

4. Next Steps

You have completed a simple data acquisition loop using NI-DAQmx on CompactRIO. There is far more that can be done with NI-DAQmx, including custom triggering, synchronization between devices, advanced timing and more. See the Additional Resources section to continue learning about CompactRIO and NI-DAQmx. 

 

Back to Top

Bookmark & Share


Ratings

Rate this document

Answered Your Question?
Yes No

Submit