08-16-2018 06:44 AM
So I get my data as AnalogWaveformy<double>[] with a regular sample intervall. In this case there shouldnt be any need for timing information for each sample. But the problem ist when I start a measurement and stream the data into a TDMS file, the field "wf_start_time" (in Excel) doesnt show the actual start time. It shows the timestamp from the last samples when I stop the measurement.
If I load the TDMS file into my Programm and get the DateTime[] info from it, the start time is also incorrect. The sampling data is right but every timestamp ist rightTimeStamp+measurementDuraction. There is a offset. If i measure till 6 AM the DateTime[] info starts at 6 AM.
The shown time is exact and I could reprocess it to get the real start time. But this doesnt seem like the way to go.
Right now I am setting up my file like this:
public void _setUpTdmsFile(string _path, string[] _channelNames) { int _numberOfChannels = _channelNames.Length; ///< Anzahl der Kanäle welche in die Datei geschrieben werden sollen. // Öffne eventuell vorhandene Datai. if (File.Exists(_path)) { TdmsFile.Delete(_path); } // Erstelle eine neue Datei. //_file = new TdmsFile(_path, new TdmsFileOptions(TdmsFileFormat.Version20)); _file = new TdmsFile(_path, new TdmsFileOptions()); _file.AutoSave = true; // Erstelle ChannelGroup. TdmsChannelGroupCollection _channelGroups = _file.GetChannelGroups(); _channelGroup = new TdmsChannelGroup("Main Group"); _channelGroups.Add(_channelGroup); // Setze Datei Layout. TdmsChannelCollection _tdmsChannels = _channelGroup.GetChannels(); _waveformChannels = new TdmsChannel[_numberOfChannels]; _channelGroup.WaveformLayout = TdmsWaveformLayout.NoTimeChannel; // Setze Kanäle welche für das Schreiben von Daten benötigt werden. for (int i = 0; i < _numberOfChannels; i++) { string _channelName = _channelNames[i]; _waveformChannels[i] = new TdmsChannel(_channelName, TdmsDataType.Double); _tdmsChannels.Add(_waveformChannels[i]); } }
and append data to it like this:
Snippet
public void _appendTdmsFile(AnalogWaveform<double>[] _waveform) { _channelGroup.AppendAnalogWaveforms<double>(_waveformChannels, _waveform); }
Snippet
public void _stopStreaming() { _file.Close();
}
Currently my theory is, that the start time field gets overwritten every time I append to the file. Is my code wrong or could this be a bug? I checked the documentian and the forum and cant find anything about this. If needed I would be happy to provide more information.
It would also be an option to write just a single time collum but in my understanding this isnt supported right now.
Solved! Go to Solution.
08-17-2018 03:53 AM
I found a workaround and will post it here in case anyone else encounters this problem. The first time I get an Analogwaveform I get the start time and save it for later use.
Snippet
if (first) { _handler._setStartTime(data[0].Samples[0].TimeStamp); first = false; }
At the end I overwrite the start time property in the TDMS file manually.
Snippet
public void _stopStreaming() { for (int i = 0; i < _waveformChannels.Length; i++) { _waveformChannels[i].GetProperty("wf_start_time").SetValue<DateTime>(realStartTime); } _file.Close(); }
This is probably not the best solution but it works.