04-20-2016 11:53 AM
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
Solved! Go to Solution.
04-21-2016 04:17 AM
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
04-21-2016 04:19 AM
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
04-21-2016 04:36 AM
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
05-02-2016 03:05 AM
Can you attach runnable code?
Please comment on what happens when in the code.
Best,
Anna
05-02-2016 03:41 AM
Hi Anna,
I attached a commented console application. Thanks!
05-04-2016 02:00 AM
Hi Jonas,
which Versions do you use? I cannot get it to run.
Best,
Anna
05-04-2016 03:39 AM
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
05-11-2016 03:23 AM
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