Example Code

Create New TDMS File Based on Time

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.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example shows how to create a new TDMS file based on time using the Elapsed Time function. It also writes to the TDMS file based on the time specified in a second Elapsed Time function. 

Description

As noted on the Block Diagram of this example, the code takes the following steps: 

 

1. Get the Date/Time when the VI starts and build that into a path in the C:/temp directory.

2. Create a new TDMS file with TDMS Open, using the newly built path.

3. The "File Elapsed Time" function will wait for the "Period of Time Between New Files (s)" to pass to output a True. Otherwise, it will output a False. This is a non-blocking function, so it will be polled as often as the While Loop iterates, which the Wait (ms) defines as 1000 ms.

4. If the "File Elapsed Time" function outputs a True, the current TDMS file closes and a new TDMS file is created with an updated Date/Time. If the "File Elapsed Time" function outputs a False, the current TDMS file reference is kept open and passed along.

5. The "Write Elapsed Time" function will wait for the "Period of Time Between Writes (s)" to pass to output a True. Otherwise, it will output a False.

6. If the "Write Elapsed Time" function outputs a True, data is written to the TDMS file. If the "Write Elapsed Time" function outputs a False, the current TDMS file reference is passed along. Note that the double array here is a placeholder for real data.

7. When the Stop button is pressed, the While Loop exits, TDMS file closes, and errors are checked.

Hardware and Software Requirements

LabVIEW Base Development System 2013 or compatible.

Steps to Implement or Execute Code

1. Set the "Period of Time Between New Files (s)" and "Period of Time Between Writes (s)" values.

2. Run the VI.

Additional Information or References

Note: To save the TDMS files in a different location, the file path constant on the Block Diagram must be changed. Additional coding is required to write real data to file; see step 6 on the Block Diagram.

Thanks,

Rita Prather
Software Product Manager
rita.prather@ni.com
National Instruments

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