Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TDMS Timestamp Decoding - Help!!

501 views
Skip to first unread message

bradh

unread,
Apr 17, 2008, 9:40:04 PM4/17/08
to
I am in need of help with decoding the timestamp in TDMS files.  Specifically in the properties section.  The following (very vague documentation) provides limited details:
 
<a href="http://zone.ni.com/devzone/cda/tut/p/id/5696" target="_blank">http://zone.ni.com/devzone/cda/tut/p/id/5696</a>
&nbsp;
Specifically looking for bit definition of the "tdstimestamp" type.&nbsp; As an example I extract the following hex values from a TDMS file:
&nbsp;
44 00 00 00 EA D8 C5 AC 4F 9E 56 BC C2 2F F3 C3 00 00 00 00
&nbsp;
I know that the first four bytes (44 00 00 00) signify the timestamp datatype, but how do I decode the remaining bytes.&nbsp;&nbsp;&nbsp; The approximate time of above is 11:55:41AM on March 4, 2008.
&nbsp;
Thanks for any help!

David_B

unread,
Apr 21, 2008, 2:10:09 PM4/21/08
to
Are you trying to read in values to C?
LabVIEW has a Get and Set Properties VI as well as a TDMS File Viewer VI that may help.
Or are you looking to actually decode manually (via C or some other language) the hex code and be able to interpret the proper time?

bradh

unread,
Apr 21, 2008, 2:40:11 PM4/21/08
to
Matt,&nbsp; Thanks!&nbsp; I verified this works.&nbsp; I'll take a look at the milliseconds.&nbsp;
Dave , I have&nbsp;a .tdms&nbsp;to .mat&nbsp;(MATLAB) file translator written.&nbsp;&nbsp; This by the way was VERY frustrating as the documentation on the page above is very vague/ambious and I hope does not represent internal documentation standards at NI.&nbsp; Why does diadem have a .mat file conversion but LabView does not?
&nbsp;
&nbsp;

David_B

unread,
Apr 22, 2008, 7:10:06 PM4/22/08
to
I don't know if you've checked into using a data plugin (you may be writing your own), but we do have one available for .MAT files on our website:&nbsp; <a href="http://zone.ni.com/devzone/cda/tut/p/id/4065" target="_blank">DataPlugins: Supported Data Formats</a>.
Additional resources that you may find helpful would include <a href="http://digital.ni.com/public.nsf/allkb/A3663DE39D6A2C5A86257204005C11CA?OpenDocument" target="_blank">Reading and Writing TDM/TDMS Files</a>&nbsp;that contains links to a number of guides regarding the TDMS file format as well as interfacing with third-party data files.&nbsp; There are also two examples found here: <a href="http://zone.ni.com/devzone/cda/epd/p/id/4181" target="_blank">Loading Data with a DataPlugin Within LabVIEW</a>&nbsp;that illustrate how to read data into LabVIEW using a data&nbsp;plugin.

bradh

unread,
Apr 22, 2008, 11:40:08 PM4/22/08
to
Matt - Thanks, that works great!!
&nbsp;
Dave,&nbsp; I see that the MATLAB pluggin was just updated to include MATLAB 2008b.&nbsp; We take data in our labratory using the TDMS format.&nbsp; When we distribute this to other researchers, they often use MATLAB (and of course Labview).&nbsp;
&nbsp;
For about a year now, the Matlab pluggin has been out of date and would not work with the last 3 releases of MATLAB.&nbsp; Since it is a compiled C library, we're stuck and can not modify it.&nbsp; As the internal TDMS format is not changing and only low level matlab commands are required to read it, I believe that Matlab users have been looking for a simple Matlab function to just take a tdms file and make a similar .mat file (not a dll).&nbsp; This is what I have done (and thanks to Matt for the timestamp help).
&nbsp;
The&nbsp;Excel TDMS add-in is very nice and is a good reason to use the TDMS format (in addition to its good support in VI libraries), but I often have to fend off requests to write large ASCII or flat binary files (in addition to our TDMS files) so that they can be read in MATLAB.&nbsp; I don't want to have the burden of making/distributing a LV executable that makes this interim file format and then&nbsp;creates a&nbsp;.mat file.&nbsp;&nbsp;&nbsp;

bradh

unread,
Apr 23, 2008, 2:40:05 PM4/23/08
to
A copy of the MATLAB conversion function is attached.&nbsp; On a first glance, it looks overly complicated but was done so to maximize speed (we convert 100MB tdms files in about 2 minutes).&nbsp; I would love to get feedback from other users on it's compatibilty with other TDMS structures.&nbsp;
(Had to change the file extention to .txt as .m was not allowed - needs to be changed back)
Thanks again to Matthew K on decoding the timestamp.


convertTDMS.txt:
http://forums.ni.com/attachments/ni/170/318487/1/convertTDMS.txt

iBiR

unread,
May 6, 2008, 2:10:07 AM5/6/08
to
hello,I run your code,but some error occur:
??? Attempt to reference field of non-structure array.
Error in ==&gt; convertTDMS at 218&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ssamples=ob.(cname).nsamples;
&nbsp;
what is the problem? I run the code under matalab r14
thank you

Josefin

unread,
Jun 30, 2008, 8:40:08 AM6/30/08
to
Hi!
First of all I just want to tank you for the code you attached. I have TDMS files with measurement data and corresponding time stamps for each sample and want to import this data to Matlab. Basically the same thing as you want to do, I suppose? I tried your attached code and got the following message:
??? Error using ==&gt; freadInvalid precision.
Error in ==&gt; convertTDMS at 215&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [data cnt]=fread(fid,nvals,LV2MatlabDataType(index.dataType(r)));
&nbsp;
What does "invalid precision" mean here and how can I correct this? Gratetful for any help! /J

bradh

unread,
Jun 30, 2008, 9:40:06 AM6/30/08
to
Ibir, Josefin,
Would it be possible for you to upload a small tdms data file that you are using?&nbsp;&nbsp;&nbsp;I believe&nbsp;(espically in Josefin's case) that this is just an issue with decoding a datatype.&nbsp;
Regards,
Bradh
&nbsp;

Josefin

unread,
Jun 30, 2008, 12:40:07 PM6/30/08
to
Absolutely! Here is a file with streamed data where the sample timestamps are stored under ther group name "Time" and measurements stored under the "Data Ch: 1"-group. Changed the file extension to txt from tdms just to be able to upload it. Hope that it works when you change it back to tdms.It would be absolutely great if you can help me find what is wrong here! Cos it really would make my life a whole lot easier if this could be solved with a matlab script like that. :-) Thanks for helping me out! /J


TestFile3.txt:
http://forums.ni.com/attachments/ni/170/336267/1/TestFile3.txt

bradh

unread,
Jul 1, 2008, 9:40:07 AM7/1/08
to
Had a chance to look at it, and it seems to be a problem interpreting the time stamp.&nbsp; We figured this out when the timestamp was in the meta data, but when it is written as a channel as you have done, it seems to be causing a compatibilty issue.&nbsp; I have a couple of fires burning right now.&nbsp; Will be looking at it later today/tomorrow.
&nbsp;
NI folks - Can you provide more information than what is in:

Kevin_S

unread,
Jul 1, 2008, 6:10:06 PM7/1/08
to
Hi bradh,
&nbsp;
I can try to provide more information, but you will have to be a little more specific as to what additional information you are looking for.
&nbsp;
This <a href="http://digital.ni.com/public.nsf/allkb/0EEADA99DC7D00A4862572E30037C3A2?OpenDocument" target="_blank">article</a> specifically addresses the issue of " Reading TDM/TDMS Files with The MathWorks, Inc. MATLABŽ Software".&nbsp; There's also an example.
&nbsp;
I hope this helps,
Kevin S.
Applications Engineer
National Instruments

bradh

unread,
Jul 16, 2008, 10:40:07 AM7/16/08
to
Sorry for the delay.&nbsp; I found the problem and believe I have fixed it.&nbsp; See the attached m file (you will need to change the extention back to ".m").&nbsp; Please let me know if you experience any other problems or have any feedback as I would like to perfect this.&nbsp; Kevin S. - As mentioned previously in this thread, the problem with the page you linked is that it is a compiled non-open c dll.&nbsp; Therefore when software versions change, we are all stuck until NI catches up.&nbsp; Honestly, I have never been able to get it to work either.&nbsp; That is why I went to the NI page that I linked to.&nbsp; The information there is incomplete/vague/ambigous (time stamp is not properly defined for decoding, the version number is not properly defined for decoding, it is unclear as to when data objects may or may not show up, etc.).&nbsp; Some of the nice things about the .tdms format is its stability, size, speed, self documenting.&nbsp; It is currently our "standard" collection format in our labratory.&nbsp; As we deciminate this data to non-Labview users we have to provide reliable means for them to utilize the format (or I start getting requests to write data in flat binary or even worse ASCII!).&nbsp; I keep getting back the "use diadem"; it is highly impractical for me to go to our data users that utilize MATLAB and say if you want to use our data, you need to buy this software and go get trained or go buy it just to use it's data plugin to convert files&nbsp;


convertTDMS.txt:
http://forums.ni.com/attachments/ni/170/341410/1/convertTDMS.txt

0 new messages