Add New Data Into The Same Group On an Existing TDMS File in LabWindows™/CVI

Updated Oct 7, 2022

Environment

Software

  • LabWindows/CVI

I would like to add data programmatically into an existing group on my TDMS file in LabWindows™/CVI.
Which functions should I use and how?

Here are the steps to follow in order to update an existing TDMS file:
  1. Call the function TDMS_OpenFileEx to open the existing file. This function will return the tdms file handle that it will be pass to the other functions.
  2. The next function is the TDMS_GetChannelGroupByName, which it will give you group handle based on the group name you want to add your data. You must know before what is the group name of your existing TDMS file.
  3. In order to add data, you need to associate a channel with it. Call the function TDMS_AddChannel to add a new channel into the same group. You will need to use the group handle from the previous step. This function ill give you the channel handle.
  4. Use he function TDMS_AppendDataValues to append your data into the created channel from the previous step.  New data values will be added after existing data values.
  5. At the end, you must close the TDMS file handle with the function TDMS_CloseFile .
An example will look like this: 
#include <cvitdms.h>
#include <ansi_c.h>
#include <cvirte.h>	
#define MAX_CHARACTERS_PATH 1024  

static	TDMSFileHandle			tdmsFileHandle = 0;
static	TDMSChannelGroupHandle	tdmsChannelGroupHandle;
static	TDMSChannelHandle *		tdmsChannelHandle = 0;  
static char     fileName[MAX_CHARACTERS_PATH]; 
static const char *	GROUP_NAME = "Data Signals";   
double  Data[]={value};     

tdmsChannelHandle = malloc(sizeof(TDMSChannelHandle));

TDMS_OpenFileEx(fileName,0,0,&tdmsFileHandle);
TDMS_GetChannelGroupByName(tdmsFileHandle,GROUP_NAME,&tdmsChannelGroupHandle);
TDMS_AddChannel(tdmsChannelGroupHandle,TDMS_Double,"NumberOfChannels","Number Of Channels",0,&tdmsChannelHandle);
TDMS_AppendDataValues(tdmsChannelHandle,Data,NumberOfSamples,1);
TDMS_CloseFile(tdmsFileHandle);