LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to obtain which element changed in a clusters using events?

Solved!
Go to solution

Hi, I have a program where I need to check which element in a cluster has changed. The main cluster contains sub-clusters with multiple different data types. Right now I have a value change event for each element in the cluster, but this is very messy and prone to error with many elements. 

 

Since I have sub-clusters, I cannot compare Old and New values as arrays since the array will contain the sub-clusters.

 

I have attached a minimum example of my issue. Based on which element has happened, a different case should be executed. How can I better do this if the amount of elements are too much?

0 Kudos
Message 1 of 21
(5,140 Views)

It sounds like it will be a very complex user interface to operate with that data structure. Can you upload for 2016 and I'll take a look?

0 Kudos
Message 2 of 21
(5,064 Views)

Once you compare the new and old, the resulting structure is the same, but all datatypes are boolean. You could just create a subVI that does some unbundling to built an array of all entries, where you can find the changed one.

 

WhatJustChanged.png

 

(Often, only a few items need a special case, so all you need is pick these while changes in others can be dealt with the default case.)

 

 

(Be aware that tools like val(sgnl) can change none or more than one element, so handle it accordingly)

0 Kudos
Message 3 of 21
(5,055 Views)

Dynamic registered events might be what you are looking for. As a side note, you don't need to use close reference on any reference that inherits from GObject (so any control classes).

 

ItemChanged.png

Matt J | National Instruments | CLA
0 Kudos
Message 4 of 21
(5,052 Views)

@Jacobson-ni wrote:

Dynamic registered events might be what you are looking for.


Wouldn't you just get the name of the inner cluster instead of the second-level controls?

In the given example, Controls[] only gives two elements, the "checkbox" and "cluster 2". We need events for all three: (1) checkbox, (2) numeric & (3) string.

 


@Jacobson-ni wrote:

As a side note, you don't need to use close reference on any reference that inherits from GObject (so any control classes).


For more details, have a look at the "exception" paragraph here.

 

Message 5 of 21
(5,047 Views)

@altenbach wrote:


Wouldn't you just get the name of the inner cluster instead of the second-level controls?

In the given example, Controls[] only gives two elements, the "checkbox" and "cluster 2". We need events for all three: (1) checkbox, (2) numeric & (3) string.


You are correct. If you wanted you could probably just do a recursive search for elements in clusters.

 

search.png

Matt J | National Instruments | CLA
Message 6 of 21
(5,039 Views)

asdasdasd


@Gregory wrote:

It sounds like it will be a very complex user interface to operate with that data structure. Can you upload for 2016 and I'll take a look?


See attachment. The UI isn't too complex.

 

@altenbach wrote:

Once you compare the new and old, the resulting structure is the same, but all datatypes are boolean. You could just create a subVI that does some unbundling to built an array of all entries, where you can find the changed one.

 


I suppose this works and is cleaner than what I have, but it would be great if there was a dynamic option that scales with the amount of elements.

 


@Jacobson-ni wrote:


You are correct. If you wanted you could probably just do a recursive search for elements in clusters.

 

search.png


This gives an array of references to each individual element in the cluster. But how can I know from this which has changed?

0 Kudos
Message 7 of 21
(5,012 Views)

Recursive Cluster To Array.PNG

 

Not the prettiest peace of code, but effective.

 

Use the array to find the first true. Then use that to index a label, reference, or whatever...

 

Note that if you signal values, there can be 0..n changed elements instead of always 1.

0 Kudos
Message 8 of 21
(4,994 Views)

@Basjong53 wrote:

@Jacobson-ni wrote:


You are correct. If you wanted you could probably just do a recursive search for elements in clusters.

 

search.png


This gives an array of references to each individual element in the cluster. But how can I know from this which has changed?


You can feed that array of references into the register for event node. That event will trigger on value change of any individual element and give you a reference to the specific element that was changed.

Matt J | National Instruments | CLA
Message 9 of 21
(4,946 Views)

While all of the above are sound there is another option.

 

Register different events for each of the things in the cluster.

 

Let LV detect the change so when the event for the contained item changes we know exactly what needs to be done and no reverse engineering required.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 10 of 21
(4,931 Views)