Here are the steps to follow in order to update an existing TDMS file:
- 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.
- 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.
- 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.
- 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.
- 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);