The NI Technical Data Management Streaming (TDMS) file format is the fastest and most flexible way to store measurement data to disk. Developers have long used the LabWindows/CVI TDMS API to attach timing information and custom-defined attributes to measurement data as it streams to disk. Storing data in TDMS files eliminates the need to design and maintain custom data file formats while creating well documented data sets that can be easily searched and ported to any platform.
» Read an Introduction to the LabWindows/CVI TDM Streaming Library
Fig 4. Write measurement data to a TDMS file using the built-in libraries to better organize data sets by group and add descriptive meta-data about each data set.
The TDMS Advanced API adds new functionality to the existing TDMS library, such as:
Compared to the standard TDMS functions, the Advanced TDMS functions have the following advantages:
Note When you write data to a .tdms file, the data includes meta data and raw data. Refer to TDMS File Format Internal Structure for more information about meta data and raw data in a .tdms file. |
Use the following guidelines when you read or write data with the Advanced TDMS functions.
The following guideline describes how to read data from a .tdms file asynchronously.
The following guideline describes how to write data to a .tdms file asynchronously.
Advanced Synchronous and Asynchronous I/O | |
Advanced Close File | TDMS_AdvancedCloseFile |
Advanced Create File | TDMS_AdvancedCreateFile |
Advanced Open File | TDMS_AdvancedOpenFile |
Reserve File Size | TDMS_ReserveFileSize |
Set Channel Info | TDMS_SetChannelInfo |
Set Next Read Position | TDMS_SetNextReadPosition |
Set Next Write Position | TDMS_SetNextWritePosition |
Advanced Asynchronous I/O | |
Advanced Async Read | TDMS_AdvancedAsyncRead |
Advanced Async Write | TDMS_AdvancedAsyncWrite |
Configure Async Reads | TDMS_ConfigureAsyncReads |
Configure Async Writes | TDMS_ConfigureAsyncWrites |
Get Async Read Status | TDMS_GetAsyncReadStatus |
Get Async Write Status | TDMS_GetAsyncWriteStatus |
Advanced Synchronous I/O | |
Advanced Sync Read | TDMS_AdvancedSyncRead |
Advanced Sync Write | TDMS_AdvancedSyncWrite |
Advanced Data Scaling | |
Create Linear Scaling Info | TDMS_CreateLinearScalingInfo |
Create Polynomial Scaling Info | TDMS_CreatePolynomialScalingInfo |
Create Thermocouple Scaling Info | TDMS_CreateThermocoupleScalingInfo |
Create RTD Scaling Info | TDMS_CreateRTDScalingInfo |
Create Table Scaling Info | TDMS_CreateTableScalingInfo |
Create Strain Scaling Info | TDMS_CreateStrainGageScalingInfo |
Create Thermistor Scaling Info | TDMS_CreateThermistorScalingInfo |
Create Reciprocal Scaling Info | TDMS_CreateReciprocalScalingInfo |
![]() |
Note Use the standard TDMS functions when the advanced features are not necessary. Incorrect use of the advanced TDMS functions can result in a corrupt .tdms file. If you disable buffering when using the advanced TDMS functions, you must read and write data in multiples of the sector size of the hard disk. |
Did you find this tip useful? Rate this document or add a comment below.
If you give this a try, share your experience! Add a comment below.
Can I read data out of the file in one thread as another thread is writing data into the file?
I have a graph control in stripchart mode that is scrolling the data on the graph and to file. If the user scrolls back on the graph I want to be able to read data outof the file to put on the stripchart but at the same time incoming data from the instrument needs to be written to the file.
Hi Cymrieg,
The scenario you proposed is supported and I have attached an example to the document above. In the code we have a thread that is writing some data to a tdms file using TDMS_AdvancedSyncWrite. In another thread we read a random chunk from previously written tdms data and do some basic verification to validate that read data. Be careful to change read position using TDMS_SetNextReadPosition before actually reading desired data.
Let me know if this is helpful!
Thanks
Anna
Anna,
Thanks for the response and this is good news so I will go ahead and play with the example.
What lead me to ask was that I saw in the API there was a function to "defrag" the file so I assumed you needed to do this between writing to the file and then reading from it, which of course would have prevented writing and reading at the same time to the file.
So what is the "defrag" of the file all about? When would I need to do this?
Hi Cymrieg,
Take a look at this document: KB: Why are my TDMS Files so Large? CVI uses the same defragment function as LabVIEW so the same use case applies. You might want to defragment your TDMS file if you are frequently writing small amounts of data for several channels.
Let me know if you have further questions.
Thanks, Anna