Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Long (two minute) delay before being able to simultaneously read data written to a TDMS file.

I am writing data to a TDMS file, 10 signals consisting of paired DateTime/double values. Each signal is sampled at 1 kHz and data is being written every 100 ms, for each channel. A different process (EXE) is (simultaneously) reading data from the TDMS file.

 

The trouble is that it takes a very long time before the reading process sees the data recently written to the file.

 

To be fair, I wouldn't expect to be able to read the most recent record immediately, but I am now experiencing a two minute delay. Is this what to expect when simultaneously writing/reading the same TDMS file? If so, I have to find a different means of storing/accessing my data.

 

In addition, I sometimes get an weird exception when opening the file. I know my test code is terribly inefficient, but I thought creating a new TdmsFile object might solve the problem with the two minute delay. It didn't.

 

AutoSave is off and I am calling Save() every time I write data to the file.

 

This is using MS 8.9.0.246 in Visual Studio 2008 SP1 using .NET framework 3.5 SP1 on Windows 7.

This is my tiny test program:

static void Main(string[] args) { while (true) { DirectoryInfo info = new DirectoryInfo(@"c:\tmp"); FileInfo file = info.GetFiles("*.tdms").OrderByDescending(f => f.LastWriteTimeUtc).First(); Console.WriteLine(string.Format("File: {0}", file.Name)); Console.WriteLine(string.Format("Size: {0} Mb", file.Length / 1024 / 1024)); using (TdmsFile tdms = new TdmsFile(file.FullName, new TdmsFileOptions(TdmsFileFormat.Version20, TdmsFileAccess.Read, true, TdmsByteOrder.Native))) { TdmsChannelGroup group = (TdmsChannelGroup)tdms.GetChannelGroups().First(); TdmsChannel channel = (TdmsChannel)group.GetChannels().First(); if (channel.DataCount > 0) { DateTime[] data = channel.GetData<DateTime>(channel.DataCount - 1, 1); Console.WriteLine(string.Format("- Now: {0} Last: {1} Count: {2}", DateTime.Now, data.Last(), channel.DataCount)); Console.WriteLine(string.Format("- Diff: {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - data.Last().Ticks))); } else { Console.WriteLine(string.Format("- Now: {0} Empty!?", DateTime.Now)); } tdms.Close(); } System.Threading.Thread.Sleep(10000); } }

 

... and this is the output:

 

File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 26 Mb - Now: 2010-05-12 09:57:26 Empty!? File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 28 Mb - Now: 2010-05-12 09:57:36 Empty!? File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 30 Mb - Now: 2010-05-12 09:57:46 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:07.7338669File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 34 Mb - Now: 2010-05-12 09:57:56 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:17.9714929 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 36 Mb - Now: 2010-05-12 09:58:07 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:28.1759179 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 38 Mb - Now: 2010-05-12 09:58:17 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:38.3803429 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 41 Mb - Now: 2010-05-12 09:58:27 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:48.5740264 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 43 Mb - Now: 2010-05-12 09:58:37 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:58.7667334 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 45 Mb - Now: 2010-05-12 09:58:47 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:09.0053359 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 49 Mb - Now: 2010-05-12 09:58:58 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:19.2654214 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 51 Mb - Now: 2010-05-12 09:59:08 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:29.4473869 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 53 Mb - Now: 2010-05-12 09:59:18 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:39.6752479 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 55 Mb - Now: 2010-05-12 09:59:28 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:49.8904144 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 59 Mb - Now: 2010-05-12 09:59:39 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:02:00.1065574File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 61 Mb - Now: 2010-05-12 09:59:49 Last: 2010-05-12 09:59:44 Count: 250200 - Diff: 00:00:04.8688200 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 62 Mb - Now: 2010-05-12 09:59:59 Last: 2010-05-12 09:59:44 Count: 250200 - Diff: 00:00:15.4394325

 

The exception that pops up when opening the TDMS file:

 

Unhandled Exception: NationalInstruments.Tdms.TdmsException: An unexpected error occurred. at NationalInstruments.Tdms.Internal.k.a(String A_0, Boolean A_1, Boolean A_2 ) at NationalInstruments.Tdms.TdmsFile.a(TdmsFileOptions A_0) at NationalInstruments.Tdms.TdmsFile..ctor(String path, TdmsFileOptions fileO ptions) at ...Program.Main(String[] args) in C:\...\Program.cs:line 22

 

0 Kudos
Message 1 of 2
(3,666 Views)

Code looks like cr*p. Sorry about this.

 

static void Main(string[] args) { while (true) { DirectoryInfo info = new DirectoryInfo(@"c:\tmp"); FileInfo file = info.GetFiles("*.tdms").OrderByDescending(f => f.LastWriteTimeUtc).First(); Console.WriteLine(string.Format("File: {0}", file.Name)); Console.WriteLine(string.Format("Size: {0} Mb", file.Length / 1024 / 1024)); using (TdmsFile tdms = new TdmsFile(file.FullName, new TdmsFileOptions(TdmsFileFormat.Version20, TdmsFileAccess.Read, true, TdmsByteOrder.Native))) { TdmsChannelGroup group = (TdmsChannelGroup)tdms.GetChannelGroups().First(); TdmsChannel channel = (TdmsChannel)group.GetChannels().First(); if (channel.DataCount > 0) { DateTime[] data = channel.GetData<DateTime>(channel.DataCount - 1, 1); Console.WriteLine(string.Format("- Now: {0} Last: {1} Count: {2}", DateTime.Now, data.Last(), channel.DataCount)); Console.WriteLine(string.Format("- Diff: {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - data.Last().Ticks))); } else { Console.WriteLine(string.Format("- Now: {0} Empty!?", DateTime.Now)); } tdms.Close(); } System.Threading.Thread.Sleep(10000); } }

 

 

The output:

 

 

File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 26 Mb - Now: 2010-05-12 09:57:26 Empty!? File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 28 Mb - Now: 2010-05-12 09:57:36 Empty!? File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 30 Mb - Now: 2010-05-12 09:57:46 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:07.7338669 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 34 Mb - Now: 2010-05-12 09:57:56 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:17.9714929 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 36 Mb - Now: 2010-05-12 09:58:07 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:28.1759179 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 38 Mb - Now: 2010-05-12 09:58:17 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:38.3803429 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 41 Mb - Now: 2010-05-12 09:58:27 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:48.5740264 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 43 Mb - Now: 2010-05-12 09:58:37 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:00:58.7667334 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 45 Mb - Now: 2010-05-12 09:58:47 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:09.0053359 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 49 Mb - Now: 2010-05-12 09:58:58 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:19.2654214 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 51 Mb - Now: 2010-05-12 09:59:08 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:29.4473869 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 53 Mb - Now: 2010-05-12 09:59:18 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:39.6752479 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 55 Mb - Now: 2010-05-12 09:59:28 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:01:49.8904144 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 59 Mb - Now: 2010-05-12 09:59:39 Last: 2010-05-12 09:57:38 Count: 124800 - Diff: 00:02:00.1065574 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 61 Mb - Now: 2010-05-12 09:59:49 Last: 2010-05-12 09:59:44 Count: 250200 - Diff: 00:00:04.8688200 File: 1.3.6.1.4.1.30354.129778336515.4432.20100512075531.10.tdms Size: 62 Mb - Now: 2010-05-12 09:59:59 Last: 2010-05-12 09:59:44 Count: 250200 - Diff: 00:00:15.4394325

 

 

The exception:

 

 

Unhandled Exception: NationalInstruments.Tdms.TdmsException: An unexpected error occurred. at NationalInstruments.Tdms.Internal.k.a(String A_0, Boolean A_1, Boolean A_2 ) at NationalInstruments.Tdms.TdmsFile.a(TdmsFileOptions A_0) at NationalInstruments.Tdms.TdmsFile..ctor(String path, TdmsFileOptions fileO ptions) at ...Program.Main(String[] args) in C:\...\Program.cs:line 22

 

0 Kudos
Message 2 of 2
(3,662 Views)