LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to test if a connection is wired in a subvi

If a VI calls a subvi, some connections may be not be required. Is it possible to find out (within the subVI) whether the optional connections are connected or not?
0 Kudos
Message 1 of 5
(3,398 Views)
I usually do this by checking to see if the data is at its default value. For example, imagine that you have a string input. You could set its default to "". Then you can test for this value and assume that it is unwired if it equals this value.

Other examples are to use -1 as a default for integer values that are expected to be greater than zero, or NaN for floats (you may need to Format to String and compare against the string "NaN" because of how LabVIEW compares floats), etc.

Good luck,

-Jim
0 Kudos
Message 2 of 5
(3,398 Views)
Hi,

The only way to do this, is to set the default values to something special
(NaN, -1, etc.).

In the VI you have to test the input, if it is default, the control is not
wired. If a connection is not used, LV uses the default value (but only if
the control is wired as a connector).

Regards,

Wiebe.

"Joolz" wrote in message
news:506500000008000000C7590000-1027480788000@exchange.ni.com...
> If a VI calls a subvi, some connections may be not be required. Is it
> possible to find out (within the subVI) whether the optional
> connections are connected or not?
0 Kudos
Message 3 of 5
(3,398 Views)
Hi all,
one method of checking the default value is to take a copy of the control value as it has come in, and then perform a re-initialise to default method on the original control. You can then compare - if they're the same then it's a default (though it might be a coincidence that you wired a value into the sub.vi that matched - maybe it's something NI could add in a future release - a property of a control to say it got it's data elsewhere). This method makes sure that you're not going to run into a block diagram / front panel mismatch if you ever update the program (i.e. you set a control's default value, then you have to remember to change the constant on the block diagram too.
It's a little more cumbersome - I use a sub.vi to do the che
cking. Because the data isn't important, you can do the comparison based on the variant data.
The attached files are in LabVIEW 6.1.

Just my 2 cents worth.

S.
// it takes almost no time to rate an answer Smiley Wink
Download All
0 Kudos
Message 4 of 5
(3,398 Views)
OK thanks to everyone who replied - it does seem like an omission on Ni's behalf, but I have written a workaround as you suggested.

Cheers

Joolz
0 Kudos
Message 5 of 5
(3,398 Views)