LabVIEW

cancel
Showing results for
Did you mean:

Highlighted

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.

Message 1 of 13
(1,331 Views)

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

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.
Message 2 of 13
(1,301 Views)

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

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

Message 3 of 13
(1,297 Views)

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

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
Philips Respironics
Certified LabVIEW Developer
Message 4 of 13
(1,273 Views)

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

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.

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

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

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

"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Message 6 of 13
(1,202 Views)

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

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
(1,200 Views)

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

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.

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.
--------------------------------------------------------------------------------------------------------------------------
Message 8 of 13
(1,197 Views)

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

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)

Message 9 of 13
(1,170 Views)

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

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."
Message 10 of 13
(1,029 Views)