08-09-2010 04:46 AM
When writing signal data to a TDMS file I always end up with a different number of (Y) double values compared to the number of (X) DateTime timestamps.
What is strange is that DataCount for the channel yields a correct result. However, when opening the file for reading there is always a mismatch between the number of X and Y values, per channel.
I have previously reported a bug concerning the AutoSave property and corrupt data when using TdmsWaveformLayout.PairedTimeAndSampleChannels and WaveformTiming.CreateWithIrregularInterval(). The workaround was to explicitly call Save() whenever modifying the TDMS file, e.g. creating groups/channels or writing sample data. This seemed to work well enough, and I haven't seen corrupt data since. However, I am now experiencing a data loss instead.
Just to be sure I am logging the value reported by DataCount before and after each write operation. In this example 80 samples are written each time. It looks OK:
2010-08-09 11:07:02.254 [9] DEBUG SE.Epiq.Acqis.Storage.TdmsStorage - P0 [mmHg] # before (double/DateTime): 23920/23920 2010-08-09 11:07:02.262 [9] DEBUG SE.Epiq.Acqis.Storage.TdmsStorage - P0 [mmHg] # after (double/DateTime) : 24000/24000 2010-08-09 11:07:02.269 [9] DEBUG SE.Epiq.Acqis.Storage.TdmsStorage - P5 [mmHg] # before (double/DateTime): 4400/4400 2010-08-09 11:07:02.269 [9] DEBUG SE.Epiq.Acqis.Storage.TdmsStorage - P5 [mmHg] # after (double/DateTime) : 4480/4480
But when I open the file and try to read the data I get an error saying "the number of time stamps on the timing channel associated with ... is not equal to the number of data samples.". DataCount confirms this and there is always a multiple of the number of samples written simultaneously that is missing, e.g. 80/160/240/... samples.
If I use the TDMS Reader demo application and click on a timing channel I sometimes (!) get a different error: "Specified argument was out of range of valid values. Parameter name: wholeSeconds.". I don't know if this error is related. The time stamps I am writing are what DateTime.UtcNow returns. Nothing strange at all.
I create/open the TDMS file like this:
... = new TdmsFile(filename, new TdmsFileOptions(TdmsFileFormat.Version20, TdmsFileAccess.ReadWrite, true, TdmsByteOrder.Native));
When I am done writing data, I call Save(), Close(), Dispose() (in that order).
Sample data are written to the file using AppenAnalogWaveform().
channel.Parent.AppendAnalogWaveform(channel, TdmsUtilities.CreateAnalogWaveform(e.Data, e.Signal));
The CreateAnalogWaveform method returns an AnalogWaveform<double>:
AnalogWaveform<double> result = AnalogWaveform<double>.FromArray1D(data.Samples); result.Timing = WaveformTiming.CreateWithIrregularInterval(data.Timing); result.ChannelName = signal.Alias; result.UnitDescription = signal.UnitOfMeasurement;
The TDMS file is saved after each call to AppenAnalogWaveform.
What is really funny is that the docs for TdmsFile.Dispose() says:
Call Dispose when you are finished using the TdmsFile. The Dispose method closes the TDMS file, and leaves it in an unusable state. This method does not save the file. Call Open to re-open the TDMS file.
If dispose really leaves the file unusable (sic!) it is great that you have documented it. 😉
Solved! Go to Solution.
08-09-2010 04:49 AM
As this is the third bug I've found affecting TDMS files in Measurement Studio, I will now seriously consider a different option for storing my sample data. TDMS seems a bit too unstable for my requirements on a production environment. I'm sorry, but that's the way I feel.
08-10-2010 12:44 AM
Is a car going to be filed?
08-10-2010 04:24 AM
No, not by me at least. I don't have the time to investigate further and have (as of today) dropped TDMS from my project.
08-10-2010 01:18 PM
Hello Mif -
I'm sorry that the TDMS API has been giving you such a hard time. We take the usability and reliability of our APIs very seriously, and would really like to get to the bottom of this issue with you. I've spent time today trying to reproduce what you've reported, but I've been unable to so far.
I've attached the code I used to try to reproduce the issue - could you modify it or attach your own code that reproduces what you're seeing?
Thanks and sorry for the inconvenience -
NickB
National Instruments
08-11-2010 03:06 AM
Hello Nick!
I've actually managed to reproduce the error. See attached code and TDMS file. It might be a threading/timing issue and not a bug in the TDMS library, but I am not sure. Look for "SetProperty" and the comment "this is what triggers the bug".
To be fair there are other reasons I'm dropping TDMS as well. We need a more OO way of storing data and have decided on using DB4O instead.
Thank you for taking the time!
08-11-2010 03:26 PM
Thanks for the code MiF -
With your code, I was able to reproduce the bug you were seeing. It looks to be closely aligned internally with the previous bug you reported concerning autosave corrupting your data under specific circumstances. The fix for both of these issues will be in the next version of Measurement Studio, but can also be obtained now by installing the LabVIEW 2010 run-time engine.
Once again, I'm sorry for the inconvenience these bugs have caused you -
NickB
National Instruments
08-12-2010 01:48 AM
Thank you Nick for confirming my suspicion. Then, at least, it is not my coding that is off. Upgrading to MS 2010 and corresponding run-time is not an option for us right now. I'll be using DB4O to store my data instead, and it seems to be working just fine. (At least for now ... *crossing fingers*)
Does finding three TDMS bugs in a short time qualify for a t-shirt?
Best Regards,
Mikael
08-12-2010 08:47 AM
One quick update -
As a result of the bugs you've found, a push has been made to make the standalone TDMS installer containing fixes to these bugs available for download. You can get this installer (20MB) here, and once installed, you should no longer see the issues you have been running into.
I understand you are likely still going to move to DB4O api, but I wanted to make sure anyone else who runs into this issue knows where to get the fix until Measurement Studio 2010 is released.
NickB
National Instruments