LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Index through cluster to change value

Solved!
Go to solution

I've tried looking for an answer for this problem through the forum but have yet to find any that could solve what I'm trying to do.

 

I have over 20 boolean controls that need to be reset back to default state (off). I've put all them into a cluster and then set to an array and change each one through a for loop, but I'm unsure if this will actually switch the original boolean control back to the default state. 

 

Is there a more efficient way to do this? Can someone give me an example using clusters or arrays? I wish to keep the label of the Boolean the same from input to output as I noticed them changing when I put them into an Array from a cluster or vice versa. For example, my original Boolean control is named "Switch 1", but after putting it through and array and outputting it as an indicator, the Boolean label is now named "Boolean 1".

 

Thank you!

0 Kudos
Message 1 of 13
(50,964 Views)

To start at the end. Just change the name in the cluster, or even better, make it a Type def. What you call the signals is irrelevant for the program, it just cares for the data types. For you as a programmer and user, however, it can be quite important. 🙂

Your VI doesn't quite show what you describe, but you have an array of clusters and want to reset some item in all rows, right?

Reset Cluster item.png

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 13
(50,956 Views)

hi,

other options

bp
0 Kudos
Message 3 of 13
(50,927 Views)

I saved snippet like thisscreen sketch.png

but when I open it looks like

using clusters.png

bp
0 Kudos
Message 4 of 13
(50,916 Views)

If you want to change the states of the individual boolean controls, then you'll need to act directly on those controls or on references to them; bundling them (actually, their values) into a cluster indicator like you did just creates a new indicator separate from the original controls, it doesn't give you access to the original controls' references. If you want to reset them all back to false, you can create an array of references to all of the controls, then use those references to change the values of the controls, like this:

snippet.png

0 Kudos
Message 5 of 13
(50,900 Views)

@bharathp10 wrote:

I saved snippet like thisscreen sketch.png

but when I open it looks like

using clusters.png


That is a flaw of using the VI snippet maker that is built-into LabVIEW.

 

If you use the Code Capture Tool found on the VI Tools network, it doesn't mess up local variables and references like this.

Message 6 of 13
(50,895 Views)

Hopping into the wayback machine for a moment...

 

Ah yes, here it is.  I stumbled into a neat solution to this just over a decade ago.  I remain uncertain if it's 100% robust now and into the future, but it sure *seems* to still work.

 

The essential idea starts with converting the cluster of same-datatype-elements into an array.  Once you've got an array, many things can be done with greater block diagram efficiency (at least in terms of pixel real estate).  The key is that you can typecast from array back to the original cluster without having to hardcode the # of cluster elements like you'd need to do with the array-to-cluster primitive.

 

See below:

 

 assign bool cluster.png

 

 

 

-Kevin P

 

P.S.  I'd advise making a typedef out of that cluster to be even more sure about element labels and cluster order.

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 7 of 13
(50,872 Views)

Hi Kevin

 We can perform Boolean operation and typecast  on cluster itself right.

Or converting it to array has any advantages 

 

bp
0 Kudos
Message 8 of 13
(50,859 Views)

@RavensFan

I will try that tool .

bp
0 Kudos
Message 9 of 13
(50,856 Views)

One of the main advantages of converting to array is one I didn't illustrate -- the ability to auto-index a For Loop over each element one at a time.

 

Some operations (such as the OR and AND I illustrated) can already be applied globally to a cluster, so the specific example I posted doesn't particularly benefit from this little trick.  But many of the earlier postings involved addressing each element by name, something my trick would bypass for cases where you want to treat them all alike anyway.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 10 of 13
(50,845 Views)