LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to programmatically tell if an 'optional' input is wired?

Here is what i want to do:

 

I have an optional input terminal whose type is cluster. I would like to do some operation on it if it is wired, otherwise I use an alternative solution. How can i do it programmatically?

 

Unlike array input we can check if it is empty, i guess there is no empty cluster. Any ideas?

0 Kudos
Message 1 of 10
(5,402 Views)

IDK if you can tell if it's wired or not, but you could do the next best thing and check to see if it is at its default values.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 10
(5,391 Views)

Use the reference of the control you like to check. If the reference is empty, you could detect it with "Not A Number/Path/Refnum? Function ". The value can be extracted with a property node. 

0 Kudos
Message 3 of 10
(5,388 Views)

@aptivo wrote:

Use the reference of the control you like to check. If the reference is empty, you could detect it with "Not A Number/Path/Refnum? Function ". The value can be extracted with a property node. 


What control? It would be painful to have to create a control if you simply want to wire a constant.

 

Either use the (BS) defaults, or add a Boolean input to tell the VI if the input should be used..

 

Or make two VIs, one with the input and one without. Let the internals handle the difference on a lower level... Not very growable (e.g. if you have 8 inputs, you'd need 2^8 VIs), but it might just work in simple situations...

 

In a class, you could add VIs to set each individual peace of data, and not setting the data could signal the object that the peace of data should not be used. It's exactly the same problem!  You'd need to 1) check for default values, or 2) use a Boolean to see if it's been set or 3) make two children. But the details are hidden (encapsulated) in the class, relieving the user of this burden.

0 Kudos
Message 4 of 10
(5,348 Views)

@aptivo wrote:

Use the reference of the control you like to check. If the reference is empty, you could detect it with "Not A Number/Path/Refnum? Function ". The value can be extracted with a property node. 


That is a horrible solution. A property node forces the thread to run in the UI thread and reads from a control (and thus also needs a control to feed it). If you can't set the VI input to 'required', then set the default to something obvious, as NaN (if it's a number) and it should be clear if it's wired.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 10
(5,342 Views)

I either don't like this solution. If you don't have a performance critical application it can be a workaround. As mentioned the best solution is the use of two VIs and the usage of required or optional terminals.  

0 Kudos
Message 6 of 10
(5,338 Views)

Hello Chuan,

Hope you have got too many suggestion, If i also want to be a part of it then i would suggest you to go with default values.

Decide whether the value is default/Wired value( make sure your wired value should not be same as default).

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 10
(5,330 Views)

Here are 3 possibilities:

  • The easiest way is to set the default value to something it would never have if real data were wired in (e.g. "NaN" for a double), then check the value.
  • Another way is to use a variant control as an input, and check for a void (or check for an error when converting to your cluster).
  • Make a malleable VI.
"If you weren't supposed to push it, it wouldn't be a button."
Message 8 of 10
(5,291 Views)

@paul_cardinale wrote:

Here are 3 possibilities:

  • The easiest way is to set the default value to something it would never have if real data were wired in (e.g. "NaN" for a double), then check the value.

Exactly. For a cluster, you have an even higher chance to pick a "impossible" combination, because each element can be defined as a unlikely value (e.g. all DBLs at -Inf, etc. all I32 at -2147483648, all string empty, etc.). Be careful with NaNs, because all equal comparisons will result in FALSE. NaN != NaN. 😄

0 Kudos
Message 9 of 10
(5,283 Views)

Just out of curiosity, can you explain what your VI does and when it will not be wired? There may be a simpler way to address your use case. For instance, if it is only unwired the first time you run the VI, you could use a "First Call?" to see if it is the first run or not.

0 Kudos
Message 10 of 10
(5,277 Views)