Programmatically Check If a SubVI Input Terminal Is Wired

Updated Aug 24, 2023

Reported In

Software

  • LabVIEW

Issue Details

I have a subVI and its behavior depends on which inputs are wired to it. How can I programmatically check if one of its input terminals is wired or not?

Solution

You can programmatically check if an input terminal is wired to the subVI by comparing the current value of the input to its default value. You should set the default value of the input to an improbable value. The boolean statement 'Is the input value equal to its default value?' can be used to control the behavior of the subVI.


For example, below is a simple subVI that outputs a string stating whether or not its input is wired. In this example, the subVI Input control is assigned a default value of 999999 because it assumed that the subVI Input will never hold that value. The subVI then compares value of the input with a numeric constant to see if the value of subVI Input is equal to its default value. If the result of this comparison is True, the Output indicator displays a statement saying the input is not wired. If the result of the comparison is False, the Output indicator displays a statement saying the input is wired.


True Case: Print "Input is not wired" if subVI Input is not wired (i.e. subVI Input is set to the default value of 999999)


False Case: Print "Input is wired" if subVI Input is wired (i.e. subVI Input is not equal to the default value of 999999)

Note: To assign the default value to a control, enter the desired value into the control on the front panel then right-click the control and select Data Operations » Make Current Value Default.

Additional Information

Another way to programmatically check if a terminal has a wire connected is VI Scripting. VI Scripting enables you to create, edit, run, and inspect VIs programmatically. Using VI Scripting one can check if there is an actual wire on the Block Diagram connected to the subVI's terminal. Please note that VI Scripting does only work inside the LabVIEW Development Environment, not within e.g. compiled exe files that rely on the LabVIEW Runtime Engine.
For more information about VI Scripting refer to the Related Links section below.