You are on page 1of 6

Monitor and Log Data

Building off of the tutorial, Acquire and Analyze Signals , now learn how to locally log data to disk on real-time
targets, a necessary task for many standalone applications. It’s highly recommended to walk through the first
tutorial before this one as many of the fundamental tasks for creating your project are covered.

This codes requires LabVIEW and the LabVIEW Real-Time Module.

Adding Datalogging to a LabVIEW Real-Time Project

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

2. In the default project tree you have My Computer, which is where you can write code that will run on
the Windows machine you’re currently developing on. Remember that a Real-Time target has a
processor running a real-time operating system, so effectively, it’s another computer. RT.vi is the code
that will run 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, shown as the cRIO-9068 chassis.
Note that you would communicate to your target by entering its valid IP Address once it’s properly
configured 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 will cover 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 data acquisition from presenting or logging the data. This
minimizes jitter and allows your timed loop to run with “real-time” performance, meaning that it will
always finish on time. By running tasks in separate loops at distinct rates, you also maximize CPU
efficiency by executing each task only as often as necessary. In the low priority loop, now you will 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 blank space to bring up the Functions palette, then navigate to Programming » File I/O » TDM
Streaming » TDMS Open). The NI TDMS file format allows you to 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,
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 will stop
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, then click the tunnel to replace it with a shift register.

13. When completed, your While Loop should look as follows:

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 CompactRIO
hardware you can run the code on the target.

Additional Resources
Using WebDAV to Transfer Files to Your Real-Time Target

Building and Deploying a Stand-Alone Real-Time Application

You might also like