Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

TDMS: Add property, DateTime vs. PrecisionDateTime

Solved!
Go to solution

I'm back with another issue concerning the .NET TDMS API.

What would you expect when you you add a property with a DateTime value to a TDMS file and than add another property with the same value converted to a PrecisionDateTime value? Both should be stored as i64 + u64 bits according to the TDMS File Format Internal Structure.

 

 

var someDate = new DateTime(635757120000000000L, DateTimeKind.Local);

using (var file = new TdmsFile(@"C:\Temp\ts.tdms", new TdmsFileOptions()))
{
    file.AddProperty("_ts0", TdmsPropertyDataType.DateTime, someDate);
    file.AddProperty("_ts1", TdmsPropertyDataType.DateTime, PrecisionDateTime.FromDateTime(someDate));
}

In binary, the total i64 seconds are equal, but the u64 fraction part of the first property is 0x0000800000000000.

 

So when I read the first property I get a difference of 76 DateTime ticks which equals 7.6 µs.

That is the "precision" I get for the price of 128 bits?

 

Beste Regards,

Jonas

0 Kudos
Message 1 of 9
(4,992 Views)

HI Jonas,

 

I am  not sure I understand your question.

Can you rephrase it? Irony is hard to get in written context and I am not sure if you used it

 

Best,

 

Anna

Anna Vogl
Certified LabVIEW Developer
0 Kudos
Message 2 of 9
(4,963 Views)

DateTime object is only accurate to the nearest 100-nanosecond tick, while a PrecisionDateTime object is accurate to the nearest 2^(-64) second

 

I don't know if that helps you

Anna Vogl
Certified LabVIEW Developer
0 Kudos
Message 3 of 9
(4,961 Views)

Thanks for your reply. The required precision in this example is very low. Briefly, I write a value, I read this value, both values are not equal. Minimum example:

 

 

DateTime writeDate = new DateTime(635757120000000000L, DateTimeKind.Local);

file.AddProperty("_ts0", TdmsPropertyDataType.DateTime, writeDate);
DateTime readDate = file.GetProperty("_ts0").GetValue<DateTime>();

Console.WriteLine(readDate.Ticks - writeDate.Ticks);

 

 

The difference between them is 76 DateTime ticks. In my opinion, the calculation from 64 bit DateTime to 128 bit PrecisionDateTime in the TDMS API is incorrect. I checked the binary values in file. The funny thing is that when I do the conversion by hand using PrecisionDateTime.FromDateTime(...) everything works fine.

 

Regards,

Jonas

 

 

0 Kudos
Message 4 of 9
(4,958 Views)

Can you attach runnable code?

 

Please comment on what happens when in the code.

 

Best,

 

Anna

Anna Vogl
Certified LabVIEW Developer
0 Kudos
Message 5 of 9
(4,843 Views)

Hi Anna,

 

I attached a commented console application. Thanks!

0 Kudos
Message 6 of 9
(4,840 Views)

Hi Jonas,

 

which Versions do you use? I cannot get it to run.

 

Best,

 

Anna

Anna Vogl
Certified LabVIEW Developer
0 Kudos
Message 7 of 9
(4,803 Views)

Hi Anna,

 

as you can see in the *.csproj file I'm using NationalInstruments.Tdms, Version=15.0.40.49153 in Visual Studio 2010 SP1. But it should build with earlier versions too. Maybe you can copy paste the code in one of your projects with a reference to the TDMS API.

 

Best Regards,

Jonas

0 Kudos
Message 8 of 9
(4,797 Views)
Solution
Accepted by topic author jonas.d

HI jonas,

 

sorry that it took a while. We got it to run and could reproduce the behaviour. I forwarded it.

Thank you for reporting that.

 

Best,

 

anna

Anna Vogl
Certified LabVIEW Developer
0 Kudos
Message 9 of 9
(4,696 Views)