DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

NI TDMS C DLL - Timestamp Issues

I'm having a lot of trouble with the TDMS C DLL. It often misreports channels and channel properties of type DT_DATE as DT_DOUBLE. I am then unable to read them using DDC_GetChannelPropertyTimestampComponents(). 

 

It seems any files I have written to using DiAdem 2014 will show channel data type as DDC_Double even though it's reported correctly in the TDMS File Viewer (LV2014SP1). Additionally, the DDC_CHANNEL_MINIMUM/DDC_CHANNEL_MAXIMUM properties are data type of DDC_Double even on channels that do correctly show a type of DDC_Timestamp.

 

Attempting to read a channel or channel property that is incorrectly reporting its datatype results in a -6227 error code (type mismatch).

 

What can I do to fix this issue?

 

Thanks!

0 Kudos
Message 1 of 3
(4,912 Views)

Hi Thomas,

 

Could you clarify what you mean by “misreports” the type? What environment are you using to write this TDMS and what environment are you using to read it? Also, if you could create a small snippet of code to reproduce this issue that would be helpful in trying to figure out what is going on.


-Kevin

0 Kudos
Message 2 of 3
(4,570 Views)

MINIMUM and MAXIMUM are always double properties. Their datatype will not change according to the channel type.

 

DIAdem time channels are stored as double that contains seconds since 1/1/0000 00:00:00.

To help to convert times to different types the following constants might be helpful.

 

  const __int64 SECONDS_1_JANUARY_1904 = 60084288000; ///<! Seconds form 01.01.0000 - 01.01.1904
  const __int64 SECONDS_1_JANUARY_1970 = 62167132800; ///<! Seconds form 01.01.0000 - 01.01.1970
  const __int64 SECONDS_1_JANUARY_1601 = 50522659200; ///<! Seconds form 01.01.0000 - 01.01.1601

 

How can a DOUBLE time channel be determined.

The channel will have a custom property named displaytype.

 

 

 

   int doubleTimeChannel = 0;

doubleTimeChannel = 0; if(0 == DDC_GetChannelPropertyString(channels[i], "displaytype", channelDisplayType, 125)) { if(0 == stricmp("Time", channelDisplayType)) { doubleTimeChannel = 1; } }

 

If a double channel has this set to 1 it can be extracted as a time channel like the given code

 

 

#include <math.h>
#include <time.h>

void PrintTimeValues(unsigned __int64 numDataValues, double *data) { unsigned __int64 i; time_t lt; struct tm * ltTm; double number, fractionOfSecond, seconds; const __int64 SECONDS_1_JANUARY_1904 = 60084288000; ///<! Seconds form 01.01.0000 - 01.01.1904 const __int64 SECONDS_1_JANUARY_1970 = 62167132800; ///<! Seconds form 01.01.0000 - 01.01.1970 const __int64 SECONDS_1_JANUARY_1601 = 50522659200; ///<! Seconds form 01.01.0000 - 01.01.1601 for (i = 0; i < numDataValues; i++) { if(data[i] > SECONDS_1_JANUARY_1970) { number = data[i] - (double)SECONDS_1_JANUARY_1970; fractionOfSecond = modf(number, &seconds); lt = seconds; ltTm = gmtime(&lt); printf (" Date: %s Fraction : %lf", asctime(ltTm), fractionOfSecond); } else { // relative time seconds are interpreted as seconds } } }

 

The ltTm structure will contain the time parts. The same mechanism can also be used to extract time values from MINIMUM and MAXIMUM values.

 

 

0 Kudos
Message 3 of 3
(4,512 Views)