03-14-2019 01:27 AM - edited 03-14-2019 01:29 AM
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?
03-14-2019 01:38 AM
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.
03-14-2019 01:42 AM - edited 03-14-2019 01:44 AM
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.
03-14-2019 05:55 AM
@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.
03-14-2019 06:38 AM
@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
03-14-2019 06:48 AM
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.
03-14-2019 06:59 AM
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).
03-14-2019 11:41 AM
Here are 3 possibilities:
03-14-2019 12:07 PM
@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. 😄
03-14-2019 12:32 PM
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.