LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a VI that requires any (x-1) of x outputs.

Is there a way to create a VI with a set of three input terminals of which two are required and the third has a default value if not wired? The complication is that it may be any two of the three terminals which are wired.

0 Kudos
Message 1 of 13
(4,068 Views)

only in a kind of hackish or very complicated and unsupported way.

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019L20SAE


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 2 of 13
(4,038 Views)

Is this a calculation where you want the vi to recognize which inputs are wired and then branch to use the correct formula based on that?  (An example might be an ideal gas law calculation PV=nRT.  A subvi might require the caller to wire exactly 2 of P,V,T and then it solves for the the other one).

 

For something like this to be feasible, you'd typically need the default value of each input to have a special "sentinel" value.  This should be a value that'd be illegal if wired.  Then you're able to recognize whether or not that particular input was wired by comparing to the sentinel value.

 

I've often done this using "NaN" as my default value for floating point inputs.  (If someone actually wires a "NaN" value, well, the calculation's gonna be in trouble anyway.)  Sometimes -1 can work for integer inputs that are only valid/sensible when positive.  

 

The mechanics of it aren't too bad, it's more a question of whether your problem allows for it.  You need a problem where there's a known range of legal possible values for your inputs so you can choose an illegal value as a default sentinel.   However, some problems don't lend themselves to such assumptions.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 3 of 13
(4,034 Views)

To follow up along the same lines as Kevin's excellent reply:

 

Another real world math problem I once implemented as a single VI is the pressure-altitude computation... given any two of {barometric pressure, station altitude, ambient pressure}, compute the third as an output.

 

I found it easier to just create one three-input, three-output VI, and each output is independently the result of the other two entities as input  (although there are some common elements of the internal math).  In this case, rather than using NaN as a sentinel, I just used zero altitude and standard pressure as default values.  The resultant single VI can be used regardless of "what you know" vs. "what you need to compute", and documents more easily.

 

Would an approach like that work in your case?

 

Best regards,

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 4 of 13
(4,011 Views)

Another technique is to use variants on the inputs, then convert the variant values to the desired type.  Unconnected inputs will yield an error on the conversions.

NW.png

"If you weren't supposed to push it, it wouldn't be a button."
Message 5 of 13
(3,969 Views)

R-click the input on the connector pane, select "This input is -> Required". For the recommended ones (the standard) the default value in the VI is what you'll get if unconnected.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 13
(3,940 Views)

A couple other thoughts.

 

1.  Polymorphic VI's.

2.  A VI that that has an enum input where the enum would be "Given ABC",  "Given ABD",  Given "ACD"  (Or "Solve for A",  "Solve for B", "Solve for C")   Since you need to drive a case structure depending on what is given and what you are solving for because the formula to solve for an unknown variable will be different based on which variable is the unknown.

 

#2 is what I used when I wanted a subVI to solve the geometry of a somewhat defined quadrilateral and  in some cases I knew the angles and in others I knew the lengths of the sides.

Message 7 of 13
(3,938 Views)

Similar in concept to Paul's reply, you could use arrays as inputs to your vi.

Then convert your scalar values to arrays when used.

Unused Inputs.png

 

 

 

 

 

 

 

 

 

 

 

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
0 Kudos
Message 8 of 13
(3,935 Views)

I haven't played with malleable VIs as much as I'd like to, but the little I've done makes me think that they would be an ideal solution (assuming you're running 2017)

0 Kudos
Message 9 of 13
(3,908 Views)

I thought this would work; but I don't understand why the 3rd instance is broken.

"If you weren't supposed to push it, it wouldn't be a button."
Download All
0 Kudos
Message 10 of 13
(3,767 Views)