From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Append 2D array to TDMS file with VB.NET

Code and Documents

Attachment

Overview

This example demonstrates how to add a 2D array into a TDMS file, where each row of the array belongs to its own channel. 

 

 

Description

This code uses array manipulation to create each row of a 2D array, and then adds each row to the TDMS file using AppendData.  The data from the first row of the array will be added into the first channel, the second row to the second channel, and so on.  The section of code that deals explicitly with manipulating and writing out the 2D array to file is included below.  It is written in VB.NET using the TDMS libraries that come with Measurement Studio.

 

Requirements

  • Visual Basic with Measurement Studio

 

Steps to Implement or Execute Code

  1. Download the attached TDMS write array.zip
  2. Extract the files
  3. Open the solution
  4. Run the program
  5. Click Create TDMS File
  6. The TDMS file will be created in the executable directory, which is <TDMS write array>TDMS write array\bin\Debug by default
  7. View the TDMS file with your favorite viewer.  The Measurement Studio example TDMS reader is one option
  8. Note that each row of the array is in its own column

 Additional Information or References

Picture of Code

'write the 2d array to file

Dim i, j As Integer

Dim d1array(2) As Double

 

For i = 0 To 2      'index through rows

    For j = 0 To 'index through each element in the row

        d1array(j) = dataArray(i, j)    'add the element to a 1d array

    Next

    myChannel(i).AppendData(Of Double)(d1array) 'add the row as stored in the 1d array into that row's channel

Next

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 


 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.