Giter VIP home page Giter VIP logo

tdmsreader's Introduction

TDMS Reader

Nuget Travis CI Build Status TeamCity Build Status

A managed library for reading TDMS files.

Install

TDMSReader can be found on nuget:

PM> Install-Package TDMSReader

Usage

The folowing demonstrates how to read data from a TDMS file.

using (var output = new System.IO.StreamWriter(System.IO.File.Create(@"D:\export.txt")))
using (var tdms = new NationalInstruments.Tdms.File("Sample.tdms"))
{
    tdms.Open();

    foreach (var value in tdms.Groups["Noise data"].Channels["Noise_1"].GetData<double>())
        output.WriteLine(value);
}

The folowing demonstrates enumeration of properties, groups and channels.

using (var output = new System.IO.StreamWriter(System.IO.File.Create(@"D:\tdms.overvw.txt")))
using (var tdms = new NationalInstruments.Tdms.File("Sample.tdms"))
{
    tdms.Open();

    output.WriteLine("Properties:");
    foreach (var property in tdms.Properties)
        output.WriteLine("  {0}: {1}", property.Key, property.Value);
    output.WriteLine();
    foreach (var group in tdms)
    {
        output.WriteLine("    Group: {0}", group.Name);
        foreach (var property in group.Properties)
            output.WriteLine("    {0}: {1}", property.Key, property.Value);
        output.WriteLine();
        foreach (var channel in group)
        {
            output.WriteLine("        Channel: {0}", channel.Name);
            foreach (var property in channel.Properties)
                output.WriteLine("        {0}: {1}", property.Key, property.Value);
            output.WriteLine();
        }
    }

    output.WriteLine("Data:");
    foreach (var group in tdms)
    {
        output.WriteLine("    Group: {0}", group.Name);
        foreach (var channel in group)
        {
            output.WriteLine("    Channel: {0} ({1} data points of type {2})", channel.Name,
                                channel.DataCount, channel.DataType);
            foreach (var value in channel.GetData<object>().Take(20))
                output.WriteLine("          {0}", value);
            if (channel.DataCount > 20) output.WriteLine("        ...");
            output.WriteLine();
        }
    }
}

Contributors

Huge thanks to Tommy Jakobsen for adding interleaved data support!

Tommy Jakobsen
Tommy Jakobsen

Props

Thanks to JetBrains for providing OSS licenses!

License

MIT License

tdmsreader's People

Contributors

illishar avatar mettekou avatar mikeobrien avatar tommyja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tdmsreader's Issues

Reading .TDMS files that possess a time interval/duration

This component works fine except for those files which use a set duration or time interval. I only get the wf_sample values, not the whole length values.

This is the code I'm using to create an excel file with the values of the TDMS file:

foreach (var group in tdms)
{
int column = 0;
string sheetName = group.Name;
ExcelWorksheet ws = pck.Workbook.Worksheets.Add(sheetName);
foreach (var channel in group)
{
int row = 1;
column++;
ws.Cells[row, column].Value = channel.Name;
ws.Cells[row, column].Style.Font.Bold = true;

	foreach (var valueData in channel.GetData<object>())
	{
		row++;
		ws.Cells[row, column].Value = valueData;
	}
}

}

Could you please help me? I have attached a sample file.

Thaqnk you so much.
Asier

RUN_UP14_06_2018_20_37.zip

Issue reading strings

I have a large file that I'm trying to read. Sample is attached. All of the numeric values appear to read fine, but some of the strings are corrupted.

Here is the code I used to read the data:

using (var output = new System.IO.StreamWriter(System.IO.File.Create(@"C:\Carl\tdms_example.txt")) )
using (var tdms = new NationalInstruments.Tdms.File(openFileDialog1.FileName) )
{
    tdms.Open();

    output.WriteLine("Properties:");

    foreach ( var property in tdms.Properties )
    {
        output.WriteLine("  {0}: {1}", property.Key, property.Value);
    }

    output.WriteLine();

    foreach ( var group in tdms )
    {
        output.WriteLine("    Group: {0}", group.Name);

        foreach ( var property in group.Properties )
        {
            output.WriteLine("    {0}: {1}", property.Key, property.Value);
        }

        output.WriteLine();

        foreach ( var channel in group )
        {
            output.WriteLine("        Channel: {0}", channel.Name);

            foreach ( var property in channel.Properties )
            {
                output.WriteLine("        {0}: {1}", property.Key, property.Value);
            }

            output.WriteLine();
        }
    }
}

Attached is the output data. See "Channel: 1850-5 Lower Element" for an example of the data corruption.

The Excel importer add-in reads the TDMS file fine so I don't believe it is corrupted.

tdms_example.txt

String Issue Sample.zip

Timestamp precision

Now that Timestamp is working, I noticed that some precision seems to be missing:

TDMSReader:

09/11/2014 08:11:33.000 AM
09/11/2014 08:11:43.000 AM
09/11/2014 08:11:53.000 AM
09/11/2014 08:12:02.000 AM
09/11/2014 08:12:12.000 AM

Excel Converter:

09/11/2014 08:11:33.007 AM
09/11/2014 08:11:43.057 AM
09/11/2014 08:11:53.107 AM
09/11/2014 08:12:02.897 AM
09/11/2014 08:12:12.947 AM

Problem with Groups and Channels

Hello,

I'm trying to use the TDMS reader in C# to read NI files, but I've got problems with the channels of a Group.

For Example, if I go to group "Mount1" channel "1X Freq", the DLL tells me that the length is 2400. But the thing is that it should have 400 elements. The rest of the elements corresponds to the groups "Mount2", "Mount3" .... I don't know why they appear as elements of group "Mount1"

Could you please tell me if I'm doing something wrong? If you'd like to, I'd have no problem in sending you the TDMS file I've used.

Thank you so much,

Asier Otamendi
[email protected]

image

Unknown data type 285212672

Hi Team,
I got "Unknown data type 285212672" this error after this cmd
tdms.open()

        Dim output = New System.IO.StreamWriter(System.IO.File.Create(("D:\tdmsfiles\DC355 NL Match and Barcode\tdms.overvw.txt")))
        Dim td = New NationalInstruments.Tdms.File("D:\tdmsfiles\DC355 NL Match and Barcode\test.tdms")
        td.Open()
        output.WriteLine("Properties:")

DateTime data is off by 4 hours

GetData<DateTime>()

If you open a TDMS file by using the Excel plugin (or if you use the Measurement Studio TDMS code), you get the correct output. TDMSReader's datetime (timestamp) is off by 4 hours. Looking at the source everything looks correct (even the 1904 offset).

Timestamps in TDMS files are stored as a structure of two components:

  • (i64) seconds: since the epoch 01/01/1904 00:00:00.00 UTC (using the Gregorian calendar and ignoring leap seconds)
  • (u64) positive fractions: (2^-64) of a second

http://www.ni.com/white-paper/5696/en/

Support DAQmx data channels

[Apologies in advance, this post is not a real issue]
Hi,

Thank you for the TDMS reader, I'm looking for a solution to read the TDMS file that is being generated from the C# API package. I need to post process the data from it.
I'm logging the data using the built in function ConfigureLogging() but I cannot find a simple way to read it back. I know it is being saved correctly because when I am looking into it I can see the binary data according to the formal file structure:
http://www.ni.com/white-paper/5696/en/
I used HxD (https://mh-nexus.de/en/hxd/) to look into it.

This project is the only solution that I found that implement C# TDMS reader, but, it doesn't support TDMS2.0.

How can read DAQmx raw data TDMS2.0 files using C# without rolling my own TDMS reader?

Cheers
Maayan

Channel Metadata is read but most entries are not exposed in Channel properties.

Channel Metadata is read by reader but not exposed in Channel properties.
They are possibly filtered in File.LoadChannels. I have run out of time and have not determined why all read attributes do not get exposed to Channel Properties. The sporadic channel properties issue was not found in initial testing. This issue occurs on every file and is not hard to reproduce.

Reader Line 83:
metadata.Properties = new Dictionary<string, object>();
for (var y = 0; y < propertyCount; y++)
{
var key = _reader.ReadLengthPrefixedString();
var value = _reader.Read(_reader.ReadInt32());
metadata.Properties[key] = value;

TRACEPOINT {key}={value} {metadata.Path[0]} {metadata.Path[1]} >>>
}
metadatas.Add(metadata);

loads many Waveform" "BOP5-CWP1-MOH" metadata entries:

"unit_string"="" "Waveform" "BOP5-CWP1-MOH"
"NI_CM_AssetNodeId"="57d6c4febaa884470461047f" "Waveform" "BOP5-CWP1-MOH"
"NI_CM_AssetName"="Duke Energy|Smith|Power Block 5|PB5|Circ Water Pump 5A|Motor|BOP5-CWP1-MOH" "Waveform" "BOP5-CWP1-MOH"
"unit_string"="g" "Waveform" "BOP5-CWP1-MOH"
"NI_CM_Dt"="9.7656250000E-5" "Waveform" "BOP5-CWP1-MOH"
"NI_CM_Speed"="505" "Waveform" "BOP5-CWP1-MOH"
"wf_xvalues"="none" "Waveform" Out of bounds array index
"wf_start_time"={2017-03-30 14:59:24} "Waveform" "BOP5-CWP1-MOH"
"wf_start_offset"=0.0 "Waveform" "BOP5-CWP1-MOH"
"wf_increment"=0.00009769999999999999 "Waveform" "BOP5-CWP1-MOH"
"wf_samples"=81920 "Waveform" "BOP5-CWP1-MOH"
"RMS_g"=0.0040556330819473546 "Waveform" "BOP5-CWP1-MOH"
"PeakPeak_g"=0.023956298828125 "Waveform" "BOP5-CWP1-MOH"
"CrestFactor_g
g"=3.6197414292238372 "Waveform" "BOP5-CWP1-MOH"
"HighFrequency_grms"=0.0011031509254603251 "Waveform" "BOP5-CWP1-MOH"
"TruePeak_g"=0.014680343088455594 "Waveform" "BOP5-CWP1-MOH"
"DerivedPeak_g"=0.0057355313084989428 "Waveform" "BOP5-CWP1-MOH"
"TruePeak_ips"=0.022817510920429478 "Waveform" "BOP5-CWP1-MOH"
"DerivedPeak_ips"=0.010223429951643482 "Waveform" "BOP5-CWP1-MOH"
"~1xMagnitude_ipspeak"=0.0030968335398627546 "Waveform" "BOP5-CWP1-MOH"
"2xMagnitude_ipspeak"=0.00042457538246915184 "Waveform" "BOP5-CWP1-MOH"
"Subsynchronous_ipspeak"=0.0086347027651816777 "Waveform" "BOP5-CWP1-MOH"
"Peak
Peak_mil"=0.23272358626127243 "Waveform" "BOP5-CWP1-MOH"

Reduced metadata exposed in channel properties:

Group Properties: Waveform
Waveform.description:
Channel: Waveform.BOP5-CWP1-MOH
Waveform.BOP5-CWP1-MOH.wf_start_time: 2017-03-30 14:59:24
Waveform.BOP5-CWP1-MOH.wf_start_offset: 0
Waveform.BOP5-CWP1-MOH.wf_increment: 9.77E-05
Waveform.BOP5-CWP1-MOH.wf_samples: 81920
THAT IS ALL OF THEM!

"System.ArgumentException" (An item with the same key has already been added)

Hi,
When trying to open a tdms files, the reader throws an exception of type "System.ArgumentException" occurred in mscorlib.dll.

Additional information: An item with the same key has already been added.

Error occurs in the Open() operation:

var tdms = new NationalInstruments.Tdms.File(filePath);
tdms.Open();

I'm not sure how "Open()" could be some sort of duplicate. Any ideas on fixing this error?

NI Insight 2.0 TDMS file not accepted by TDMSReader

When using the TDMSReader example to open TDMS file created by NI Insight 2.0 the program report:

File ADVANCED_20160919_063535.0.tdms cannot be opened as TDMS.

The file can be opened by other TDMS readers from NI, such as the Excel Add-On or TDMS reader built using NI's C++ api.

I attach a small TDMS file from Insight 2.0 as well as a screen shot from Excel.

Excel Screen Shot

ADVANCED_20160919_063535.0.zip

Exceptions when ToC is empty

When opening a TDMS file where the last segment has no content I got a KeyNotFoundException in File.cs#36. I fixed it by checking the presence of the keys before using them:

// apply previous metadata if available
if (prevMetaDataLookup.ContainsKey(m.Path[0]) && prevMetaDataLookup[m.Path[0]].ContainsKey(m.Path[1]))
{
    var prevMetaData = prevMetaDataLookup[m.Path[0]][m.Path[1]];

Then I got a OutOfMemoryException in ReadMetadata(Segment). Regex.Matches(..) got a huge value when reading the string length (_reader.ReadInt32()). I fixed it by skipping segments which have no content flags set in LoadMetadata(Reader):

foreach (var segment in segments)
{
    if (!(segment.TableOfContents.ContainsNewObjects || segment.TableOfContents.HasDaqMxData || segment.TableOfContents.HasMetaData || segment.TableOfContents.HasRawData)) {
        continue;
    }

Find the changed File.cs in this ZIP archive:

File.cs.zip

Thanks for your excellent work!

Cheers,
Franz

Unknown data type -1

Hello,

When I try to open tdms files, the reader throws an exception "Unknown data type -1".
That occurs in the Open() operation:

var tdms = new NationalInstruments.Tdms.File(filePath);
tdms.Open();

This exceptions only occurs sometimes, but I would like to know why. Maybe a problem in the files or maybe a problem with the reader with newest versions of the files.

Thanks in advance!

Exception is throwed when I run all tests

Exception is throwed when I run all tests

at
public static object Read(this BinaryReader reader, int dataType)

message is,
System.ArgumentException: 'Unknown data type 9999

Double-precision floating point values read as single-precision

Hello,

Thank you for this great library!

Data-type of the value marked in the image is double / decimal however it is being extracted as float by the library and this issue leads me to lose precision. I have looked through source code and see that data-type is also stored as byte-data in the file so i am not sure if there might be something done to fix this losing decimal precision issue.

I wanted to ask that it if is possible to extract decimal value?
Another question is that, if the data is really stored as float, how DIADEM shows more digit on the fraction?

1

I tried to tweak library a bit with the following approach. I tried to call BinaryReader.ReadDouble() whenever i see data-type as float however this returned a totally different values since it read wider byte-range and it corrupted the last read position of the BinaryReader.

Data missing when reading from channels

Hi,
I have a group (mw_sensor) of close to 900 channels with each channel containing 396 data points, I am able to read from the first channel ("Untitled") fine, but when trying to read the others I'm only getting the first 12 data points.

The file is the same one I posted in a other Issue from "System.ArgumentException" (An item with the same key has already been added) ..(Recordings.zip), I'm getting an error when trying to upload it.

Group: mw_sensor
Channel: Untitled (396 data points of type System.Double)
Channel: Untitled 1 (12 data points of type System.Double)
Channel: Untitled 2 (12 data points of type System.Double)
Channel: Untitled 3 (12 data points of type System.Double)

Any ideas on why it only reads 12 data points for all the other channels?

DataCount for every channel is always 1

Dear team,

When I read the tdms files, regardless of the files I always get only 1 element per a channel. I can open the files in excel and see that there is more than 1 entry.

Any advices?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.