LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Time channel generation in TDMS for multi channel measurements

Solved!
Go to solution

Hi Everyone,

 

I have to write an application having five measurements going simultaneously.. then it should be saved in TDMS with every measurement channel having it's own time channel just after it ... i.e sequence of channel as below

 

Channel Group

     Measurement1

     Time1

     Measurement2

     Time2

     Measurement3

     Time3

     Measurement4

     Time4

     Measurement5

     Time5

 

Every time channel should have "dt" corresponding to its measurement number...

 

So far i m succesfull in recording only all measurement channel.. But i have no clue how to design Time channel for every measurement ..

 

I tried to fetch time as i receive the data using functions as below

 

GetSystemDate (&month, &day, &year);
           GetSystemTime (&hours, &minutes, &seconds);
           sprintf (timeStr, "%d/%d/%d %02d:%02d:%02d", month, day, year,
                 hours, minutes, seconds);

 

This will generate channel of time string ... but my requirement is of data type "Date/Time" used in scaling of axis in DIAdem..

 

Any help

 

Thanks

HS

 

 

0 Kudos
Message 1 of 6
(6,245 Views)

 

Hi,

 

Any suggestion from anyone... i m totally out on above requirement.. and in urgent need to find solution.. I used  pointer to write the timestamp as string but don't know about writing "Date/Time" data structure in TDMS channel..

 

usually we get it in LabVIEW through waveform...

 

please suggest something or some path to work on...

 

for example consider i have sine curve and i want to store it in TDMS format with all index data in Sine[] "array" having corresponding timestamp of generation.. i.e for sine[50] i should have time[50] for every index data repectively.. 

 

any guideline will be great help

 

thanks

HS

0 Kudos
Message 2 of 6
(6,201 Views)
Solution
Accepted by topic author H_SH

HS,

 

There are two methods of storing timing information for a channel in a TDMS file.

 

You can only use the first method if the timing information is regular (evenly spaced), meaning that it can be described with only t0 and dt values.  This method results in a single channel in DIAdem that contains the data values and stores the timing information as properties on the channel.  Note that in this case DIAdem will treat the time values as relative values with no absolute timebase. Here are the properties you need to set on the channel:

 

1) wf_start_offset (Required), type is TDMS_Double, contains the t0 time value of the first data point in whatever units you are using and can just be set to 0 if your t0 value has no meaning other than as a reference point for all other time values in this channel

2) wf_increment (Required), type is TDMS_Double, contains dt in whatever units you are using

3) wf_samples (Required), type is TDMS_Int32, contains the number of samples in the waveform

4) wf_xname(Optional), type is TDMS_String, contains the name associated with the time x-axis and will be used by DIAdem to label the x-axis when plotting this waveform

5) wf_xunit_string (Optional), type is TDMS_String, contains a string describing the units of the time x-axis and will be used by DIAdem to label the x-axis when plotting this waveform

 

You can set the above properties using the TDMS_SetChannelProperty function.

 

You can use the second method for regular or irregular (not evenly spaced) timing information.  This method results in one channel with your data values and a second separate channel that contains absolute timestamp values. Based on your original post, this sounds more like what you want.  In addition to your data channel, you need to create a timestamp channel.  Call TDMS_AddChannel with a datatype of TDMS_Timestamp to create your timestamp channel.  Call TDMS_AppendDataValues with values of type CVIAbsoluteTime to write the Timestamp values to this channel.  You can create individual timestamp values of type CVIAbsoluteTime by calling the absolute time functions in the CVI Utility Library, such as GetCurrentCVIAbsoluteTime and CVIAbsoluteTimeFromLocalCalendar.

 

I hope that helps.

 

-Jeff

NI

Message 3 of 6
(6,159 Views)

Hey Jeff,

 

Certainly your suggestions are helpfull and understood by me.. But I think the some of your suggested function is not defined in CVI 8.5.. When i m Calling TDMS_AddChannel with a datatype of TDMS_Timestamp.. i get an error as "Undeclared Identifier"..

 

Is there any suggestion for CVI 8.5 ?

 

Thanks for your support

 

HS

0 Kudos
Message 4 of 6
(6,145 Views)

HS,

You are correct.  Support for the TDMS_Timestamp data type was added in CVI 9.0.

There is one other solution that seems like it would work for you.  DIAdem also has another representation for time channels.  Instead of using the TDMS_Timestamp type for your time channel, you can use the TDMS_Double type for your time channel.  Each double value represents time as the number of seconds since 1/1/0000 00:00.  The fractional part of the double value represents fractions of a second.  As long as you are only recording relative time values, then it doesn't really matter what your first time value is.  You can use any values as long as they have units of seconds (such as the values returned by the Timer function in the CVI Utility Library).  Starting with a time value of zero might make the x-axis of your plots in DIAdem look cleaner.  This method gets tricky if you want to use absolute time values, as there are no library functions available to help you convert the current time or a specific time to/from this double value representation.  DIAdem contains functions to do this, but CVI does not.

To create one of these time channels, call TDMS_AddChannel with a datatype of TDMS_Double.  Call TDMS_AppendDataValues with values of type double to write the values to this channel.  Finally, you need to set the following property on the channel so that DIAdem knows to interpret this channel as a time channel instead of a regular double channel:
displaytype, type is TDMS_String, value should be "time"

 

You can call TDMS_SetChannelProperty to set this property.


Finally, note that you don't really need to have a special time channel at all for relative time values.  You can just create an integer or double channel that contains your time values in whatever representation you prefer (eg, an integer number of milli- or micro- seconds or a double number of seconds).  DIAdem can plot any channel on the y-axis vs any channel on the x-axis, so you would just plot your data channel on the y-axis vs your own time representation channel on the x-axis.  The special time representations in DIAdem just allow DIAdem to use fancy time format strings in terms of hours/minutes/seconds on the x-axis instead of just using your raw time representation values.  The special time channels in DIAdem are also necessary if you want to use absolute time values instead of relative time values.

-Jeff
NI

Message 5 of 6
(6,125 Views)
Well it's better to upgrade CVI version Smiley Wink ... It will save more time in developing work around process.. Any way thanks to Jeff for support..
0 Kudos
Message 6 of 6
(6,090 Views)