There are reasons to avoid file input and output (IO) on the real-time (RT) target in a LabVIEW RT application. This document presents decisions and methods that can be used to eliminate and reduce file IO in an RT application. The document is divided into four focuses: Evaluate, Offload, Reduce and Optimize.
There are reasons to avoid file input and output (IO) on the real-time (RT) target in a LabVIEW RT application.
This document presents decisions and methods that can be used to eliminate and reduce file IO in an RT application. The document is divided into four focuses: Evaluate, Offload, Reduce and Optimize.
It may be possible to reduce file IO by thoroughly evaluating the need for the data. Eliminate disk operations that aren’t truly necessary. The following questions may help ascertain the need for archived data.
Scrutinize each disk operation to identify unnecessary file IO that can be removed.
Determine which system is best-suited to perform the file IO.
If writing data to disk is necessary, the host system may be better suited to perform the read/write operation.
There are seven network communication methods outlined by LabVIEW 2009 Real-Time Module Help: Exploring Remote Communication Methods (RT). These methods may be used to transfer data from the real-time target to the host computer where it can be logged. Refer to the help file for more information each method.
There are also APIs based on the above methods that may simplify the transfer overhead. An example is the Simple Messaging Reference Library (STM).
There are, however, caveats to offloading data from the target to the host.
Consider the following points when data must be archived on the real-time target.
Consider techniques to reduce the amount of data that must be archived. The amount of reduction possible depends on the system requirements.
Code that runs faster than necessary reduces the resources available for future expansion and may generate superfluous data.
When a small amount of data is used to represent a data point, less data must be written to disk to archive the point.
You can choose to write to several types of files from LabVIEW.
Items marked with an asterisk write data in binary format. This data is not human readable but often consumes less space on disk. The other formats are human readable, but often require more space on disk.
For example, a DBL uses 64 bits in a Binary file. The same DBL uses 8 bits per digit in a Text file (up to 120 bits depending on the number). See LabVIEW 2009 Help: Numeric Data Types Table for more information.
Use a binary file format to reduce read/write time on the real-time system.
Reduce the number of data points archived to disk. There are built-in LabVIEW functions to decimate data.
You can also build your own decimation algorithms. The decimation factors in the following examples are arbitrary. The following considerations are made.
Log every N’th sample (Figure 1). A simple rollover counter can be used to log every N’th sample. None of the samples between N, 2N, 3N… are logged to file.
Figure 1
Log the average of the last N points to file (Figure 2). An additional Shift Register or Feedback Node is used to store the running sum, and the average is calculated and written to disk.
Figure 2
Log one point of data every M units of time (Figure 3). When configured to reset, the Elapsed Time Express VI is suited for this task. None of the samples between t = M, 2M, 3M… are logged to file.
Figure 3
Average samples over time (Figure 4). One Shift Register/Feedback Node is used to store the running sum and another is used to store the number of iterations since the last file write. The average is calculated and written to disk.
Figure 4
A strict delta filter logs data only if the value changes (Figure 5).
Figure 5
Extend delta filtering to absolute deadbanding. An offset from the current data point must be exceeded to qualify for a disk write (Figure 6). The In Range and Coerce function is suited for the comparison.
Figure 6
Absolute deadbanding can be modified to implement alarming and bandpass filtering. The min and max values are provided to the In Range and Coerce function to identify the window.
Rather than use an offset to define the deadband, it may be more meaningful to define the deadband as a percent change (Figure 7). For example, if the new value is within 5% of the last value written, do not write the value to disk.
Figure 7
The nature of the data and system requirements will determine what statistical parameters are of interest. There are built-in LabVIEW functions to calculate statistics.
A simple data set may include the following.
Combination Algorithms
Using these simple building blocks, a robust algorithm may be implemented. Consider the following combination.
Reduce the size of the data archived to disk.
Write an initial value and delta (either as a scalar value or percentage) to disk. A smaller data type may be used to represent the delta than the data point itself. This technique is mostly applicable to continuous phenomena (temperature in an incubator for example).
There are a variety of compression algorithms that have been written for specific data sets (audio, video, image, etc.). These algorithms may be used to reduce the amount of data that gets written to disk. A decompression algorithm is used to extract the data when it’s needed. These algorithms are beyond the scope of this document, but an Internet search for “Compression Algorithms” will get you started.
There is also a 3rd party API called OpenG Zip Tools that can be used to compress files on LabVIEW RT targets. This API is not supported by National Instruments.
Optimization techniques are aimed at making file IO more efficient on the embedded system.
Store data in RAM to buffer disk operations rather than writing each data point (Figure 8).
Figure 8
Buffering data in RAM can also be used to store data on the RT system for post-processing without ever writing to disk. Add more RAM to the system to increase the RAM buffer.
The diagram in Figure 8 can be used to optimize the disk operation to the sector size of the disk. See DeveloperZone Tutorial: Optimizing File I/O in LabVIEW and LabVIEW RT for more information.
If file IO is necessary in a real-time application, a robust process can be derived from the following chart.
Benchmark Project.lvproj. (2009). LabVIEW 2009 > Help > Find Examples > Browse by Task > Toolkits and Modules > Real-Time > Benchmarking.
Attribution 3.0. (2009, September 5). Oglib lvzip. Retrieved October 21, 2009, from OpenG > Viewing Oglib lvzip: https://www.vipm.io/package/oglib_lvzip/
Datalight Incorporated. (2009). High-Integrity Transactional File System with Dynamic Transaction Point™ Technology. Retrieved October 21, 2009, from Datalight Home > Products > File Systems > Reliance Family > Reliance: https://www.tuxera.com/products/
National Instruments. (2009, June 1). Decimate (single shot) VI . Retrieved October 21, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW 2009 Help: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/vi-lib/analysis/2dsp-llb/decimate-single-shot-vi.html
National Instruments. (2009, June 1). Decimate 1D Array Function . Retrieved October 21, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW 2009 Help: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/decimate-1d-array.html
National Instruments. (2009, June 1). Exploring Remote Communication Methods (RT Module). Retrieved October 21, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW 2009 Real-Time Module Help: https://www.ni.com/docs/en-US/bundle/370622r/page/download.html
National Instruments. (2009, June 1). File IO VIs and Functions. Retrieved October 21, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW 2009 Help: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/menus/categories/programming/file-mnu.html
National Instruments. (2005, December 21). Is DAQmx Raw Data Calibrated and/or Scaled? Retrieved October 21, 2009, from NI Home > Support > KnowledgeBase: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019YLoSAM&l=en-US
National Instruments. (2007, August 1). LabVIEW Execution Trace Toolkit 2.0 Help. Retrieved October 22, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW Execution Trace Toolkit 2.0 Help :
https://www.ni.com/docs/en-US/bundle/370622r/page/download.html
National Instruments. (2009, June 1). Max & Min Function . Retrieved October 21, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW 2009 Help: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/max-min.html
National Instruments. (2009, June 1). Numeric Data Types Table. Retrieved October 21, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW 2009 Help: https://www.ni.com/docs/en-US/bundle/labview/page/numeric-data-types-table.html
National Instruments. (2006, September 6). Optimizing File I/O in LabVIEW and LabVIEW RT. Retrieved October 21, 2009, from NI DeveloperZone > Tutorial. https://www.ni.com/en/support/documentation/supplemental/09/best-practices-for-target-file-io-with-labview-real-time.html
National Instruments. (2009, June 1). Sample Compression Express VI. Retrieved October 21, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW 2009 Help: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/vi-lib/express/express-signal-manip/samplecompressionblock-llb/ex-inst-sample-compression-vi.html
National Instruments. (2009, April 22). Simple Messaging Reference Library (STM). Retrieved October 21, 2009, from NI Developer Zone > Example Program: https://www.ni.com/en/support/documentation/supplemental/21/simple-messaging-stm-communication-library-for-labview.html
National Instruments. (2009, June 1). Statistics Express VI. Retrieved October 21, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW 2009 Help: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/vi-lib/express/express-analysis/statisticsblock-llb/ex-inst-statistics-vi.html
National Instruments. (2009, June 1). Timing Deterministic Applications (RT Module). Retrieved October 21, 2009, from NI Home > Support > Product Reference > Manuals > LabVIEW 2009 Real-Time Module Help: https://www.ni.com/docs/en-US/bundle/370622r/page/download.html