LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

TDMS file update in CVI

Solved!
Go to solution

 

Hi Everyone,

 

I am new in CVI development.. My current work is on TDMS inside CVI 8.5 , I been through CVI help on TDMS and one white paper on NI website..

 

My current requirement is that user is running application and see the data on graph of user interface.. if user accepts the data and press control buttoon accept the data will get saved in TDMS file.. otherwise user will redo the data acqusition process to see another iteration result to accept or deny..

 

I am able to write data first time but as i accept another set of data it throws an error

 

-6604TDMS_FileCouldNotBeOpenedThe file could not be opened.

 

Inside TDMS_CreateFile function, i understand it may be as file is already created in first iteration..

 

Is there any way to update the same channel data by appending every iteration with time stamping ?

 

Thanks for your time and support

 

Regards

HS

0 Kudos
Message 1 of 8
(4,705 Views)

Hi HS,

 

because you didn't tell us which function you are using we can only guess... are you aware of the function TDMS_AppendDataValues which appends data values?

0 Kudos
Message 2 of 8
(4,698 Views)

Hi,

 

my syntax for control button "Accept" press is as below

 

-------------------------------------------------------------------------

 

int CVICALLBACK DataSave (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 TDMSChannelHandle mainChannel;
    TDMSChannelGroupHandle mainChanGroup;
    TDMSFileHandle tdmsFileHandle;
 
 switch (event)
 {
  case EVENT_COMMIT:
    
   
    TDMS_CreateFile ("d:\\CVI\\signal.tdms", TDMS_Streaming, "signal", "", "", "",&tdmsFileHandle );
    TDMS_AddChannelGroup (tdmsFileHandle, "Main Group", "Dev1",&mainChanGroup);
    TDMS_AddChannel (mainChanGroup, TDMS_Double, "Main Channel", "ai0", "", &mainChannel);
    TDMS_AppendDataValues (mainChannel, sine, 100, 1);
    TDMS_CloseFile(tdmsFileHandle); 

   break;
  case EVENT_RIGHT_CLICK:

   break;
 }
 return 0;

 

--------------------------------------------------------------------------------------------------

 

This works fine as i press Accept first time, this create signal.tdms and save data in mainChannel... But as i press it to save second time it throws error code "-6604" in TDMS_CreateFile syntax...

 

I want to append the data in mainchannel with time stamp over and over with acceped iteration results.. number of iteration is not predefined sothat ian initialize any array for mainchannel...

 

Anyway around to get it solved ?

 

Thanks HS

0 Kudos
Message 3 of 8
(4,695 Views)

to begin with your first line:

 

the function TDMS_CreateFile is obsolete. You should use the TDMS_CreateFileEx function instead.

0 Kudos
Message 4 of 8
(4,692 Views)
I think there is no such command in CVI 8.5... if i try TDMS_CreateFileEx the bug comes out as "missing prototype"..
0 Kudos
Message 5 of 8
(4,688 Views)
Solution
Accepted by topic author H_SH

sorry (I am using CVI2009).

 

My guess is that you should not close the file every time but only once and instead call TDMS_SaveFile () to write data to disk, and only if you are done call TDMS_CloseFile.

 

Hence, you should rearrange your code: somewhere in the beginning of the program, call TDMS_CreateFile , TDMS_AddChannelGroup , and TDMS_AddChannel , and in your button callback only keep the append / save function. Before closing your application, call TDMS_CloseFile

Message 6 of 8
(4,672 Views)

 

Thanks alot ! it solves my current work partially, as you know problem will come if i stop the program and restart it the again, this TDMS_CreateFile will throw same error "-6604" .. as file will be already created and closed in first run of program..

 

Is there any way to handle such error like as i start program it should check the TDMS file in specified location, if file exist then only data should append on click button other wise it should create file and then append on click..

 

Kind regards and thanks to you Mr/Ms Wolfgang for your continuous support

 

 

0 Kudos
Message 7 of 8
(4,667 Views)
I get it done using FileExists function Smiley Happy
0 Kudos
Message 8 of 8
(4,645 Views)