Example Code

VI-Based API for Writing TDMS Files

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


Download All


This document contains information and VIs to provide you with TDMS writing capability for the following:


  • VxWorks, Mac OS, and Linux in LabVIEW, 7.1 and later
  • Windows in LabVIEW 7.1-8.0.

How to Use

1. TDMS File Format

The TDMS file format is designed to write and read measured data at a very high speed, while maintaining a hierarchical system of descriptive information. Although the binary layout itself is simple, the optimizations TDMS enables by writing meta data incrementally lead to very sophisticated file configurations. The installed TDM Streaming application programming interface (API) in LabVIEW hides this complexity. However, the installed TDM Streaming API is available only for Windows and Phar Lap for the LabVIEW Real-Time Module, and requires LabVIEW 8.2 or later.



Use the G TDMS VIs to complete the following actions:

  • Write TDMS files on the VxWorks and Phar Lap real-time platforms
  • Write TDMS files on every desktop operating system LabVIEW supports
  • Write TDMS files in LabVIEW 7.1 or later 
  • Learn the internal structure of TDMS files

Note Equivalent functions for reading TDMS files on VxWorks, Mac OS, and Linux are not available at this time. You can read TDMS files on Windows using LabVIEW 8.2 or later, NI DIAdem 10.0 or later, or Microsoft Excel 2003 or later. You can download the TDMS Add-In for Microsoft Excel from the National Instruments Web site at ni.com (linked below).

The TDMS VIs available for download are G TDMS Open, G TDMS Write, G TDMS Close, and G TDMS Set Properties. G TDMS Write and G TDMS Set Properties are polymorphic VIs that allow you to write a large variety of data types to the file.



Function Description
G TDMS Open Opens a .tdms file for writing. You also can use this function to create a new file or replace an existing file. Use the TDMS Close function to close the reference to the file.
G TDMS Write Streams data to the specified .tdms file. The data subset to write is determined by the values you identify in the group name and channel name(s) in inputs.
G TDMS Close Closes the .tdms file you opened with the TDMS Open function.
G TDMS Set Properties Sets the properties of the specified .tdms file, channel group, or channel. The properties are written to a channel group or channel if you wire the group name or channel name inputs with values. If the group name or channel name inputs contain no values, the properties values become file-specific.

The VI icon has a blue background, as seen in the following figure, and the VI name begins with G TDMS.

Refer to the Downloads section of this document to download the G TDMS VIs.

After you download the VIs, you can access the VIs from the labview\user.lib directory. Refer to the Adding VIs and Controls to the User and Instrument Drivers Subpalettes topic (linked below) in the LabVIEW Help for information about adding the VIs to the User Libraries palette.


3. Caveats and Recommendations

The following list describes some of the caveats and recommendations to consider when you download and utilize the G TDMS VIs.

  • The built-in TDM Streaming API in LabVIEW prevents a variety of problems that can occur if TDMS files are not properly structured. The G TDMS VIs in this document provide less protection. Refer to the TDMS File Format Internal Structure document (linked below) for more information about the composition of the TDMS file format and to learn how to optimize TDM Streaming writing and reading performance.
  • The G TDMS VIs do not create a .TDMS_INDEX file. The index file contains redundant information from the .tdms file that LabVIEW, NI DIAdem, and MS Excel use for high performance random access to data in .tdms files. LabVIEW 8.2 and other NI applications that natively support TDMS automatically generate the .TDMS_INDEX file when reading a file written by the G TDMS API.
  • Every time you write properties or data to disk, you create a new segment in the TDMS file. Every segment consists of a header section and a data section. The more segments you write, the more header information LabVIEW interprets when you load the file. An important recommendation is to keep the number of segments in the file as low as possible. For single-point data acquisition, accumulate multiple scans in an array before writing the array to disk. Avoid writing redundant properties or indexes. Write code so that header sections stay small and number as few as possible.
  • The G TDMS API technically allows you to write an arbitrary number of groups and channels to the file. The installed TDMS API in NI applications accepts up to 10,000 groups/channels. If you use 10,000 groups or channels, make sure the software and the machine you use for reading the file can process that number of objects.
  • The G TDMS VIs cannot share access to the same file with the installed TDM Streaming API in LabVIEW


4. Accessing the Help

There are no additional help files available in this document for download. Refer to the following topics in the LabVIEW Help for more information about TDM Streaming VIs and how to add the G TDMS VIs to the User Libraries palette.

File I/O with Binary Measurement Files

TDM Streaming VI and Functions

Adding VIs and Controls to the User and Instrument Drivers Subpalettes

Related Links

Developer Zone: Introduction to LabVIEW TDM Streaming VIs

Developer Zone: TDMS Add-In for MS Excel

Developer Zone: TDMS File Format Internal Structure

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