Example Code

Timestamping Queued Data and Storing in TDMS Files using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.


  • LabVIEW

Code and Documents



This example show how to use Producer-Consumer design pattern for simulated data acquisition.



TDMS files are a great way to store measurement data quickly and simply in LabVIEW. They are a type of binary file that consists of two separate files, a binary file and a binary index file. Being stored in a simple binary format allows very fast streaming to disk, and the binary index file contains information on all attributes and pointers in the binary file, allowing rapid read access. On top of this, TDMS files allow you to segment your data into specific 'groups' and 'channels' allowing the data to be organised in a logical fashion. Overall, this makes TDMS a very good candidate for applications need:

  • to store measurement data
  • to create structured grouping for data
  • to store information about data
  • to read and write data at high speeds

In this example, the data we acquiring is simulated with the use of a random number generator. You'll see that I have split the data into two channels; one for the simulated signal and one for a timestamp. By using queues, we can ensure that no data is lost, even if the data acquisition rate is greater than the rate at which we can process the data and save it to file.



LabVIEW Full Development System 2012 or compatible


Steps to Implement or Execute Code

  1. Run the VI
  2. Select a path to save the TDMS File
  3. The VI will write a simulated signal to the TDMS file.
  4. Control the processing time in the producer and consumer loops using their delays respectively
  5. Notice how the number of elements increase in the consumer is slower than producer
  6. Stop the VI to view the TDMS data file


Additional Information or References

VI Block Diagram


**This document has been updated to meet the current required format for the NI Code Exchange. **


Jeremy T
Technical Marketing

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.