Example Code

Recording Variants to TDMS from TestStand

Code and Documents

Attachment

 

 

Overview

This example demonstrates how to recording variants to TDMS files from TestStand via LabVIEW VIs.

 

Description

The TDMS Write function does not accept variants so the data type must be defined prior to using the VI.  Rolling this requirement back to the source of the data is trivial in LabVIEW.  Even converting the data type in LabVIEW is done often without thought. 

If the data source is TestStand, however, data type management between LabVIEW and TestStand can become burdensome and prone to error. This example should help relieve some of the headaches that come with writing data to TDMS from TestStand.

Test data (obviously) never has a consistent data type so having a single TDMS-record VI that can handle data types makes sense.  Polymorphic VIs or variant control inputs are the only solutions that suite this problem.  Variants are more efficient and elegant so they are a natural choice.  Using the "Get Type Information" VI in the variant palette will allow the necessary conversion to be made...and you're done.  Unfortunately, data types are not consistent across NI's product suite.

Specifically, LabVIEW has many more data types than TestStand.  There is an automatic mapping that happens when VIs are called in TestStand so NI has been gracious enough to provide a decoder ring for this mapping.  It can be found here.  For most situations, this mapping works.  The problems come when variants are used, which is exactly what we want when recording data to a TDMS file.

In this example, the TDMS_Record VI has a variant control for the data.  TestStand maps this to the "Anything" data type, which strips out any useful type information that may be present.  To demonstrate this to yourself, use the built-in "Get Type Information" VI on a variant that comes from TestStand.  The result is empty.

An easy fix would be to have TestStand provide the data type of the variant using the TypeOf() function.  The TDMS_Record VI would have to be modified to accept this input and act on it accordingly.  This works; however, it is not very efficient and prone to errors.  Every time you enter data into the variant input, you also have to enter TypeOf(data) into a separate input.  I challenge anyone to use this implementation and never have a run time error because you forgot to update the object passed to TypeOf().

The best solution would be to use the TS API to extract the data type automagically (typo intended) from the variant input parameter value.  The attached VIs do exactly that.  I've also included a TS sequence to demonstrate the VIs.  It is best to look at the comments in the code to understand what I am doing versus explaining it here.

Quick disclaimer: These VIs are for demonstration purposes only.  Use your discretion if you choose to integrate them into your own code.

 

Hardware and Software Requirements

  • TestStand 2016 or compatible
  • LabVIEW 2016 or compatible

 

Steps to Implement or Execute Code

  1. Download the VIs and demonstration sequence.
  2. Load the sequence in TestStand.
  3. The TDMS file path in the sequence is empty. Be sure to enter a valid path.
  4. Run the sequence (Ctrl + F5).
  5. After it completes, browse to the TDMS file.
  6. Open the file in your favorite TDMS viewer to see the results.

 

Additional Information or References

get data type.png

write to tdms.png

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