Example Code

TestStand .NET Event Handler Step Types

Code and Documents

Attachment

Overview

The attached step types are for handling .NET events directly from within a TestStand sequence. They require TestStand 2010 or higher.

  

Description

There are two step types provided with this code: Register .NET Event Handler and Wait for .NET Event. After installing the files with the above instructions and launching TestStand, the step types will show up under the .NET Events folder in the step insertion palettes of the sequence editor.

 

Register .NET Event Handler Step Type

Use this step type, along with an instance of a class for which you want to handle an event, to register a TestStand .NET event handler. Once you have registered a .NET event handler for your event, you can then wait on it using the Wait for .NET Event step type.
Here’s what the configuration dialog for this step type looks like:

 

2018-03-27_152750.png

 

Wait for .NET Event Step Type

Use this step type when you want to check to see if or wait until an event for which you’ve previously registered a TestStand .NET event handler has occurred. You can optionally get the arguments for the event in a TestStand array of containers, and you can optionally set a timeout.

Here’s what the configuration dialog for this step type looks like:

 2018-03-27_152812.png

Getting the Arguments to the Event

If you specify a TestStand array of containers for the event arguments setting of the step type, the step type will fill in the array with the arguments converted to their TestStand equivalent types resizing and re-dimensioning the array as needed. For example, for the event delegate:

 

public delegate void MyEventDelegate(ClassWithEvents.MyEnum enumparam, ClassWithEvents classref1, ClassWithEvents nullclassref, ref ClassWithEvents classrefbyref, string nullstringparam, string arg1, Int64 arg2, Int32 arg3, double arg4, string[] arg5, Int32[] arg6, ref string myargName, ref Int32 arg8, out string arg9, out Int32 arg10, ref string[] arg11, ref Int32[] arg12);

 

you might get something like the following back in your arguments array:

 

2018-03-27_152854.png

 

You can then access these arguments from a TestStand expression by using either the argument name or index to access the corresponding array element. For example, Locals.eventArgs["myargName"] is equal to bbb and Locals.eventArgs[0] is equal to myenumval3. Arrays are not currently converted to native TestStand arrays but are instead stored as a reference to the .NET array itself. These references can be used with the .NET adapter. Also, enums values are stored as strings with the names of the enum value as the value. These also can be used with the .NET adapter, or just used directly to check for an expected value.

 

Adding a Timeout

By default, the timeout is set to -1 which means that there is no timeout. You can set the timeout to any floating point value or a number variable which contains such a value to indicate the maximum number of seconds to wait for the event. If the timeout occurs, then the step’s TimeoutOccurred property is set to True so you can check that property if you want to know whether or not an event occurred.

 

Hardware and Software Requirements

dotNET Event Handler Step Types.zip

TestStand 2016 or compatible

Visual Studio 2013 or compatible (To rebuild .NET code)

 

 

Steps to Implement or Execute

To install the step types provided in this example, install the custom step type files:

 

  1. Exit TestStand if it is currently running.
  2. Copy the file NI_DotNetEventTypes.ini to <TestStandPublic>\Components\TypePalettes directory
  3. Copy the folder TSDotNETEventHandler to <TestStandPublic>\Components\StepTypes directory.  This folder contains both the compiled binaries and source code for the step types.
  4. Restart TestStand

 An example sequence file TSDotNetEventHandlerExample.seq and code which it depends on (located in the ExampleAssemblyWithEvents folder) are provided to help illustrate the use of these step types. 

Al B.
Staff Software Engineer - TestStand
CTA/CLD

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

Comments
j_dodek
Active Participant
Active Participant
on

Hi BlueOnes

Works perfect, thanks for sharing the step-types code

I have used it for monitoring files with FileSystemWatcher Class.

Regards

juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
Contributors