The attached step types are for handling .NET events directly from within a TestStand sequence. They require TestStand 2010 or higher.
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.
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:
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:
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:
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.
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.
dotNET Event Handler Step Types.zip
TestStand 2016 or compatible
Visual Studio 2013 or compatible (To rebuild .NET code)
To install the step types provided in this example, install the custom step type files:
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.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.