Monitor and Log Data With LabVIEW Real-Time

Publish Date: Jun 08, 2017 | 3 Ratings | 5.00 out of 5 | Print | Submit your review

Overview

Build on the tutorial Acquire and Analyze Signals With LabVIEW Real-Time, to learn how to locally log data to disk on real-time targets, a necessary task for many stand-alone applications. Review the first tutorial before working through this one because the first tutorial covers many of the fundamental tasks for creating your project.

Download LabVIEW Evaluation Download the Sample Code

Adding Data Logging to a LabVIEW Real-Time Project

1. Open your completed solution from the first tutorial, Acquire and Analyze Signals With LabVIEW Real-Time, or download the .zip file from this page. Double-click to open Real-Time Evaluation.lvproj.

2. The default project tree 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. RT.vi is the code that runs on your real-time target. Since you installed the NI-RIO driver with your evaluation software, the target saved in this project is a real-time CompactRIO target, shown as the cRIO-9068 chassis. Note that you communicate with your target by entering its valid IP address once you have properly configured it on the same network as your development computer.

3. Double-click to open RT.vi and press <Ctrl-E> to open the block diagram. A VI is composed of two windows, the gray front panel, which serves as the user interface, and the white block diagram, where code is developed. The code completed thus far acquires data in a high-priority Timed Loop, stores it in a buffer, and deterministically transfers it to a lower priority loop to display to the user interface. In addition to displaying to the user interface, this tutorial covers logging data locally to the real-time target. Error handling and comments are added in the screenshot below to the first tutorial solution. Propagating errors is especially important in embedded processors to ensure safe shutdown.

It’s a best practice to separate high-priority DAQ from presenting or logging the data. This minimizes jitter and allows your Timed Loop to run with “real-time” performance, meaning that it always finishes on time. By running tasks in separate loops at distinct rates, you maximize CPU efficiency by executing each task only as often as necessary. In the low-priority loop, you pull data from the shared variable buffer to not only display on the user interface but also log to disk.

4. Place a TDMS Open VI in the initialization sequence structure (search the Functions palette or right-click in the blank space to bring up the Functions palette and then navigate to Programming»File I/O»TDM Streaming»TDMS Open). With the NI TDMS file format, you can organize data into groups and channels.

5. Right-click the file path input terminal and Create»Constant. Type in the file path as /c/test1.txt, which is proper syntax for the cRIO-9068 running the NI Linux RTOS. For targets running another RTOS, like VxWorks or Phar Lap ETS, you can type in c:\test1.txt. LabVIEW should coerce it to the correct syntax. Create another constant for the operation input and select replace or create for the value.


Note:
You can also write to connected USB or SD Card storage entering the file path as the U: drive.

6. Wire the Error Out from the Data Buffer variable to the Error In terminal of the TDMS Open VI. Then wire the Error Out and the tdms file out outputs through the sequence structure to the border of the While Loop as shown below.

7. Create a branch from the Error wire up to the Error input node on the Timed Loop to propagate errors to both loops.

8. To write to the file just created, place down an instance of the TDMS Write VI (Programming»File I/O»TDM Streaming»TDMS Write) inside the While Loop and wire the error and file reference inputs appropriately.

9. To write data from the first channel to file, place down an Array Subset VI (Programming»Array»Array Subset). Branch a wire from the Data Buffer shared variable into the array input. Right-click on the index and length inputs and Create»Constant. The index for the first channel is 0 and the length 1. Then wire the subarray output into the data input of the TDMS Write VI.

10. Place down an Or (Programming»Boolean»Or) on the block diagram next to the Stop Control. Then wire a branch from the Error Out terminal of the TDMS Write VI into one input and delete and rewire the Stop Button value into the other input, as shown below. This ensures that the program stops either from the button or if an error is encountered.

11. Outside the While Loop to the right, place down a TDMS Close VI (Programming»File I/O»TDM Streaming»TDMS Close) to ensure the reference and file on disk are properly closed. Wire the error and file reference inputs accordingly.

12. Finally, right-click on each of the error and file reference tunnels on the left border of the While Loop and select Replace with Shift Register from the drop-down menu. A shift register enables the passing of data from one loop iteration to the next. LabVIEW replaces the tunnel you right-clicked with a shift register terminal, and the cursor becomes a shift register icon (). Hover over the tunnel on the opposite side of the loop until it flashes and then click the tunnel to replace it with a shift register.

13. When completed, your While Loop should look like this:

14.  Finally complete wiring the diagram by adding meaningful group and channel names for your data. Right-click on the group name in and channel name in inputs of the TDMS Write VI and Create»Constant. An example is shown below.

Your basic acquisition, analysis, and logging application is now complete. Once you connect to CompactRIO hardware, you can run the code on the target.

 

Continue your Evaluation of LabVIEW with the LabVIEW RIO Evaluation Kit


Using the evaluation kit, develop an embedded system with the LabVIEW reconfigurable I/O (RIO) architecture. Use LabVIEW software and C/C++ to program NI RIO hardware, which includes a real-time processor, FPGA, and I/O. CompactRIO uses this same architecture for prototyping through deployment with a flexible array of configuration, expansion, and C Series module I/O options.

 

Back to Top

Bookmark & Share


Ratings

Rate this document

Answered Your Question?
Yes No

Submit