The following sections explore how the simple user interface example is built, discussing Each of the following phases:
Note: this interface is located at (<TestStand>\UserInterfaces\Simple\LabVIEW\Build Script.lvproj)
If you have never seen this interface, take a minute to run it and explore the functionality. Having the User Interface VI open while reading this guide will help in understanding.
The manager controls also handle the updating of the visible controls on the user interface, but the manager controls must be linked (connected) to the visible controls so they know what to update. This is the first phase of the user interface execution:
Configuring the visible controls
You can see that the visible controls are split into 3 categories based on which manager control is in charge of updating it. the control references are then passed into subVIs to make the connection. The diagram below shows the subVI where we configure the ExecutionView Manager.
Configuring execution related controls (Simple OI - Configure ExecutionViev Manager.vi)
To make the connection, we call Connect methods of the manager control. For example, in the first invoke node, we tell the ExecutionView manager to display the execution list on our Executions Combo box by calling the ConnectExecutionList() method, and wiring in the control reference of the combo box.
Rather than having a specific connect method for each button, the manager control implements the ConnectCommand method, which takes in both a control reference and a command. In the above code, we are configuring the Close executions button to execute the Close command when clicked. Each manager has particular set of Connect methods. Refer to the help topic on each manager (linked above) for a comprehensive list of connect methods.
For more information on how to connect each Visible control to a manager control, refer to the TestStand User Interface Controls topic in the TestStand Help.
This connection is all we need to do to make the controls functional.
The manager controls keep track a number of TestStand events, such as when an execution starts, or when you close the interface window. You can specify an action to take when an event occurs by specifying a VI to run when the event occurs. A VI that is executed in response to an event is known as an event callback (or usually simply callback). In the simple User Interface example, these callbacks are configured in the section below:
(NOTE: The simple UI uses a LabVIEW user event to exit the application. Refer to the User Events LabVIEW help topic for more if you aren't familiar with using these)
Configuring Event Callbacks
The Configure Event Callbacks subVI takes in a Manager Reference (each manager handles its own set of events) as well as a few additional items, which you will see are eventually used in the callback VIs. The code for the configure events VI is shown below:
Configuring the event handling callbacks is accomplished using the Register Event Callback Node. This node allows you to select events of an activeX or .NET object (in our case the Application Manager control), and specify callback VIs to execute when the selected event occurs. The node has three terminals for each event:
- Reference to the event source - the object defining the event. In this case, the Application Manager control.
- Reference of the callback VI - a static reference to a VI to call when the selected event occurs. The VI must be configured correctly. NOTE: callback VIs can be created easily by right clicking the terminal, then selecting create callback VI.
- User parameter - Pass in any data you want to access in the callback VI that is not specified by the event data (you can see what is available in the event data by inspecting the callback VI). Since LabVIEW is not calling the VI directly, you cannot pass data through the connecter pane.
In the simple user interface, we configure callback VIs for 5 events, such as exiting the application and handling TestStand errors.
Note: the events we can track in TestStand are documented in the help topic for each manager in the Events section. The LabVIEW context help also provides a description of the events.
Shown below is one of the callback VIs, the Display Sequence File Callback, which is executed when we open a sequence file:
Display Sequence File callback subVI
In this callback, we get a reference to the opened sequence file from the event data (a parameter containing information about how the event was triggered), and assign it as the active sequence with the SequenceFileView manager (we passed this reference through the User Parameter, since it is not included in the event data). This assignment causes the sequence view control to update and display the sequence file (we connected the sequence view control to the sequenceFileView manager as discussed previously).
Note that the exit application event callback is passed a reference to the "quit application" LabVIEW user event. this event is fired within the callback, and is later handled by an event structure, as we will see in the next section.
Now that we have configured the connections and events, the interface uses an event structure to wait for user interaction. Almost all user interaction is handled by a connection (clicking buttons, selecting items in combo boxes, etc.) or by a application manager event (loading a sequence, showing executions, etc). However, the manager controls cannot handle the panel close event, so we use a LabVIEW event structure for this purpose:
main event loop
The event structure also handles the LabVIEW user event mentioned earlier. Both events have the same result: ending the main event loop so that the application proceeds to the shutdown phase.
The final portion of the interface ensures that all references used are closed properly before exiting the application:
Closing necessary references.
Shutdown consists of unregistering all LabVIEW events, closing the engine reference, and finally, exiting LabVIEW (in the case that we are running an EXE).