07-02-2019 08:45 AM
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?
Solved! Go to Solution.
07-03-2019 01:31 PM
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?
07-03-2019 02:37 PM
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.
(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)
07-03-2019 02:51 PM
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).
07-03-2019 03:09 PM - edited 07-03-2019 03:12 PM
@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.
07-03-2019 03:27 PM
@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.
07-04-2019 03:58 AM
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.
This gives an array of references to each individual element in the cluster. But how can I know from this which has changed?
07-04-2019 05:13 AM
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.
07-08-2019 10:17 AM
@Basjong53 wrote:
@Jacobson-ni wrote:
You are correct. If you wanted you could probably just do a recursive search for elements in clusters.
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.
07-08-2019 11:49 AM
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