Creating Custom Properties Using the TDMS .NET Library

Measurement Studio 2019 Help

Edition Date: May 2019

Part Number: 375857B-01

»View Product Info
Download Help (Windows Only)

The TDMS data model automatically implements certain properties when you create files, channel groups, and channels or when you write certain data types. However, in many cases, you may want to create a property specific to your particular needs.

Note Note   This topic applies to the following editions: Enterprise, Professional.

The TDMS data model automatically implements certain properties when you create files, channel groups, and channels or when you write certain data types. However, in many cases, you may want to create a property specific to your particular needs. You can create a custom property by adding TdmsProperty objects to the TdmsPropertyCollection associated with TdmsFile objects, TdmsChannelGroup objects, and TdmsChannel objects.

You can define TdmsProperty for each level in the hierarchy: TdmsFile, TdmsChannelGroup, and TdmsChannel. With TdmsProperty, you define a Name, a TdmsPropertyDataType, and a value.

The following example demonstrates how to read and write custom properties on a TdmsFile. The syntax is similar for a TdmsChannelGroup and a TdmsChannel.
VB.NET

Private Sub CreateCustomTdmsProperty(ByVal propertyName As String, ByVal propertyValue As String)

    ' Create the TDMS file 
    Dim file As TdmsFile = New TdmsFile("C:\properties.tdms", New TdmsFileOptions())

    ' Get the TdmsProperty collection 
    Dim properties As TdmsPropertyCollection = file.GetProperties()

    ' Create a new TdmsProperty and add it 
    Dim myProperty As TdmsProperty = New TdmsProperty(propertyName, TdmsPropertyDataType.String, propertyValue)
    properties.Add(myProperty)

    ' Get the TdmsProperty collection and read the property
    properties = file.GetProperties()
    Dim myPropertyValue As String = properties(propertyName).GetValue(Of String)()

    ' Close the file
    file.Close()
End Function
C#
private void CreateCustomTdmsProperty(string propertyName, string propertyValue)
{

    // Create the TDMS file
    TdmsFile file = new TdmsFile(@"C:\properties.tdms", new TdmsFileOptions());

    // Get the TdmsProperty collection
    TdmsPropertyCollection properties = file.GetProperties();

    // Create a new TdmsProperty and add it
    TdmsProperty myProperty = new TdmsProperty(propertyName, TdmsPropertyDataType.String, propertyValue);
    properties.Add(myProperty);

    // Get the TdmsProperty collection and read the property
    properties = file.GetProperties();
    string myPropertyValue = properties[propertyName].GetValue<string>();

    // Close the file
    file.Close();
}

WAS THIS ARTICLE HELPFUL?

Not Helpful