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

Edit Variable Control and Popup for TestStand

Code and Documents

Attachment

Overview

Sometimes in TestStand solutions and often when developing TestStand plugins there is a need to be able to view or edit TestStand variables at runtime.  For example when implementing the configuration sequence of a plugin this module can be used to display a dialog to allow the use to change the options of a plugin without having to create a custom dialog each time.

Description

 

I tend to use C# for executive code module implementation so snippets will be from the full example Visual Studio C# project. 

The module accepts a reference to the TestStand sequence context as well as a variable path to the TestStand variable to edit.

public EditTSVariableForm(SequenceContext seqContext, string LookupString)

{

                InitializeComponent();

 

                m_SeqContext = seqContext;

                m_LookupString = LookupString;

 

                // Make the window modal

                bool ShouldAbort = false;

                m_ModelID = m_SeqContext.Engine.RegisterModalWindow(m_SeqContext, (int)this.Handle, out ShouldAbort);

 

                // Localize the edit control and build type menu names

                this.ctrlTSVariableEdit.AttachEngine(m_SeqContext.Engine);

 

                m_PropertyToEdit = seqContext.AsPropertyObject().Clone(LookupString, 0);

 

                this.ctrlTSVariableEdit.TestStandProperty = m_PropertyToEdit;

}

The popup window is implemented as a modal dialog and this is registered to the TestStand engine that called the utility.

For maximum flexibility the utility was mainly designed as a control to allow the viewing and editing of data.  The popup dialog utility uses the custom control as the main component of a form. This allows for the future use of the control integrated into other interfaces.

The AttachEngine method within the custom control makes use of the TestStand language resource strings to allow the localizing of the items within the control as well as the menus for editing the data. 

The popup dialog creates a clone of the variable specified by the sequence context to allow the user to make changes to the data and still have the option to cancel.  If the OK button is pressed the cloned data is used to replace the original data.

The text on the popup form itself can also be tailored to suit different applications and locations using the LocalizeForm method.

public void LocalizeForm(string LanguageSection)

{

                if (null != m_SeqContext)

                {

                                object Found;

 

                                this.Text = m_SeqContext.Engine.GetResourceString(LanguageSection, "EDIT_VARIABLE_TITLE", this.Text, out Found);

                                this.buttonDone.Text = m_SeqContext.Engine.GetResourceString(LanguageSection, "OK", this.buttonDone.Text, out Found);

                                this.buttonCancel.Text = m_SeqContext.Engine.GetResourceString(LanguageSection, "CANCEL", this.buttonCancel.Text, out Found);

                }

}

The dialog is initially localized using the VARIABLES_VIEW_CONTROL and OBJECT TYPES sections from the standard National Instruments language files.  If the Language section is supplied then the form title (EDIT_VARIABLE_TITLE) and the OK (OK) and Cancel (CANCEL) button text shall be customized from the TestStand language file with the matching section name.

The CanEdit property will set if the custom control should support the editing of the variable data and also if there is a cancel button visible (as you cannot cancel if there is no option to edit).

The CanEditUnstructered  property sets the setting within the custom control to allow the editing of unstructured containers.  TestStand supports containers that are no constrained by type, setting the option to true lets the user add, edit and delete properties within a container that has the Unstructured flag set.

Hardware and Software Requirements

TestStand 2012 or later.

Steps to Implement or Execute Code

Add the attached DLL (or build yourself from the support code) to your PC (suggest in the  <TestStand>\Components\Tools folder).

In your TestStand sequence add a .Net step and call the Show method within the EditVariableDialog class within the TestStandEditVariable.dll.  

For starters use the default constructor providing RunState.ThisContext as the seqContext and "Locals" as the LookupString. So the .Net Invocation : in the step settings should read:

EditVariableDialog(NationalInstruments.TestStand.Interop.API.SequenceContext, System.String).Show()

Additional Information or References

 None

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

Contributors