Example Programs

Showing results for 
Search instead for 
Did you mean: 

Using the TestStand API in LabVIEW to create .NET steps for the NI VeriStand API



This example briefly details the scripting of .NET steps in NI TestStand. It is a multipurpose example, in that on top of building .NET steps, it specifically builds steps that call into NI VeriStand using the NIVS Client API .NET Assembly. As such, it can be used in two ways:

  1. The simple addition of .NET steps using the NI TestStand API for LabVIEW.
  2. Scripting NI VeriStand API calls in TestStand.

The TestStand scripting actions are accomplished using a new component of the NI TestStand API for LabVIEW in TestStand 2010 and later, which replaces obsolete components from TestStand 4.2.1. This new method replaces several older methods, and is called "LoadPrototypeFromSignature".





TestStand .NET Steps 

The main functionality of the example program focuses on creating .NET steps in TestStand. The top-level VI is a very simple interface for adding these steps. It wraps the low-level functionality in an easy to use "Add Step" subVI.  This subVI is detailed below.


Initialize VI

The Init VI opens references to TestStand, opens a new sequence file, and creates the variables that are used later in the example.  


Add Step VI

The bulk of the functionality of this example is contained in the Add Step VI. There are three main operations:

  1. Create the new step in TestStand using the dotNet Adapter.
  2. Load the appropriate dotNet assembly, class, and function calls.
  3. Add the new step to the current TestStand sequence.


New .NET Step VI

This step simply creates a new TestStand step from the .NET Adapter, then obtains the module reference for the new step. Since the DotNetModule class is required, we typecast the reference to the appropriate class, and then destroy the original Module class reference.



Load .NET Call VI

Next, the DotNetModule class is populated with the requested .NET Assembly, class, and class reference. The class reference serves one of two purposes, depending on the CreateObject value. If the CreateObject flag is true, a new class object will be created.  In this case, the class reference is a location to store a reference to the newly created object. However, if the CreateObject flag is false, the class reference is the location to look for a reference to an existing object, for which to execute the call.

The two steps in this code are an example of how this works. The first step generates a reference to an IProject object.  The reference is stored in the "Locals.ProjectRef" local variable, because this is the input to ClassReference. The second step executes a method of the IProject class on the existing IProject object. In this case, the Locals.ProjectRef variable is provided to the ClassReference input in order to retrieve the appropriate reference.


In the next section of this code, the function call and parameters are set. If the .Net step only calls the constructor for the class, the function call should not be set. Therefore, these operations are contained inside of a case structure, which is controlled by the Constructor? boolean control. The DotNetCalls class constitute the complete call chain of the step. In this case, we are calling a function of the class object, so the call chain looks like this:




The index parameter of the New and Item methods of the DotNetCalls class refers to the location in the call chain. In the example above, ClassObject() resides at index 0, and FunctionCAll(Parameter1,Parameter2) resides at index 1. Since we already specified the class name earlier, the function call needs to be at index 1.



Next, the LoadPrototypeFromSignature method is called to load the appropriate class method. The prototype can be loaded either from its full signature, including parameter data types or from its function or member name. If the latter is used, the allowMemberNameMatching flag must be set to true. More information about this function and how to specify its inputs can be found in the Help document for the function.


Config .NET Call VI

After the function prototype is set, it is necessary to set each parameter for the function. The code below simply iterates through an array of parameters, placing each one sequentially in the parameters array for the step. It should be noted that the first parameter will be the return value from the function. Any following parameters will be the inputs to the function.


Add Step to Sequence VI

This VI simply adds the step that was just created to the existing sequence.


Save and Close

The final step in the code is to save the sequence that was created, then close all remaining references.



Software Requirements

Create .NET Steps Using TestStand API - TS2012.zip

TestStand 2012 or Compatible

LabVIEW 2012 or Compatible



Steps to Implement or Execute Code


NI VeriStand API

The VeriStand portion of this example is purely based on the inputs to the code.  The front panel has been set to load the NI VeriStand Client API.  The assembly itself resides in the Global Assembly Cache. 


NI VeriStand 2011 Assembly Path:

NationalInstruments.VeriStand.ClientAPI, Version=2011.0.0.0, Culture=neutral, PublicKeyToken=a6d690c380daa308, processorArchitecture=MSIL

NI VeriStand 2010 Assembly Path:

NationalInstruments.VeriStand.ClientAPI, Version=2010.0.0.0, Culture=neutral, PublicKeyToken=a6d690c380daa308, processorArchitecture=MSIL


The first step is creating a Factory class object, so the "Create New Class Object?" boolean is true. This reference will be returned and stored in the Locals.FactoryRef variable, as per the Object Reference Input. Since a function is being called on the new object, the "Constructor?" boolean is set to false. The full signature is used to describe the "GetIProject" method, so the "Member Name?" boolean is also false. Finally, the "GetIProject" method accepts 4 input parameters and returns a reference to the project. Therefore, we provide a variable for the returned reference, and then the four inputs in the Parameters array.


The second step is very similar to the first. However, we are using the existing project reference from the first step, so the "Create New Class Object?" boolean is false. The Object Reference field now contains the local variable in which we stored the project reference in the previous step. Finally, the "Deploy" method is being called, but using the simple name, so the "Member Name?" boolean is true. This method accepts no inputs, and we do not need to store the output reference, so the Parameters array is empty. 




Al B.
Staff Software Engineer - TestStand