LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Merge clusters with overrides

Solved!
Go to solution

Dear Paul,

I have never heard of XNode before, so I just dragged and dropped it into the code from the folder, but it did not work.
I found this website and was able to run it successfully: https://lv.qizhen.xyz/en/oop_xnode.

 

It seems that, for the first time, with your solution it is mandatory to maintain the order of the cluster elements and also the enum list elements order too.

0 Kudos
Message 11 of 19
(192 Views)

Thanks for the lot of ideas. I have tested @PhillipDBrooks’ solution, and it seems that it will work for me, keeping in mind that converting to string and back is not a cheap thing.
With this solution, I like that it can be loaded back even when the order of the items in the enum is different from before.


@Andrey_Dmitriev: you are totally right. I need this because I am loading settings from before, and I have to maintain backward compatibility.

@paul_a_cardinale: Currently, the Xnode solution doesn’t work for me, but it would be quite elegant.

2025-11-17_20h51_56.png

Message 12 of 19
(188 Views)

Keep in mind that the conversion to string using the JSONText library does NOT preserve bit-by-bit values for single precision numbers. It's quite good, but for your example you need bit-perfect values, which this does NOT have. The author has a bit of discussion on this here:

 

https://bitbucket.org/drjdpowell/jsontext/issues/13/ni-json-number-of-digits-bug

 

Example:

Example_VI.png

 

For some values of floats you do get perfect retransmission, but for arbitrary "it's not actually a float it's a bitfield" values you will NOT get what you need, and it'll fail randomly depending on what your original bitfield was!

 

You may be able to make a custom serializer to do this, or maybe you could make some sort of pre-processing function that takes Floats and flattens them to a U8 array or string, then go to JSON and back, but that seems like a lot of work to avoid rearchitecting something into "the right way" (which is to store bitstreams as either a string or U8 array). It sounds like you're not using typedefs, which sucks, but going through it once will take a while... but fixing the bugs from this decision will likely bite you in the long run. Nobody here can make that call for you though... I'm sure we've all been in the "just get it going you don't have budget to fix it" spot before 🙂

0 Kudos
Message 13 of 19
(156 Views)

@denesdomjan wrote:

Dear Paul,

I have never heard of XNode before, so I just dragged and dropped it into the code from the folder, but it did not work.
I found this website and was able to run it successfully: https://lv.qizhen.xyz/en/oop_xnode.

 

It seems that, for the first time, with your solution it is mandatory to maintain the order of the cluster elements and also the enum list elements order too.


That's a bug.  I'll fix it.

0 Kudos
Message 14 of 19
(148 Views)
Solution
Accepted by topic author denesdomjan

Here's the fix.  Just replace the one VI (located in ,,, \Support\Merge Clusters).

Not really the proper way to make changes to an XNode, but as long as you first delete all the instances of the XNode on BDs, it should be OK.

(The problem was a race condition inside a property node.

Needs to be this: paul_a_cardinale_0-1763437464237.png, not this: paul_a_cardinale_1-1763437528440.png )

 

 

0 Kudos
Message 15 of 19
(137 Views)

Works well, thanks a lot to you and everyone who commented! 🙂 

0 Kudos
Message 16 of 19
(118 Views)

@denesdomjan wrote:


@Andrey_Dmitriev: you are totally right. I need this because I am loading settings from before, and I have to maintain backward compatibility.


If your goal is to save and load settings and you don't need to map old values using some logic (e.g. this element's name was changed) then you can simply use something like JSONtext as suggested or the OpenG Variant Configuration VIs or the MGI Read/Write Anything VIs. These should all allow you to convert a cluster to text format and then take that text and convert it back to the cluster. If the cluster has elements which don't exist in the text, then the default value from the cluster will be used for those elements. That way the conversion from the text to the new version of the cluster is done automatically.


___________________
Try to take over the world!
Message 17 of 19
(104 Views)

I have had a need for something similar to this in the past, but I just ended up writing a normal VI with type def clusters so it wasn't reusable.  In my case I had a cluster with a set of limits in it.  It was things like "Maximum Allowed Voltage", "Minimum Allowed Voltage", "Maximum Allowed Current", "Minimum Allowed Current" etc.  This cluster would be settings that the "System" could support.  The system might support 0V to 1000V range.  Then we would have the limits that the DUT would want, so it would have it's own set of "Maximum Allowed Voltage", and "Minimum Allowed Voltage" which could be more restrictive like 20V to 80V.  The "System" would have a cluster of limits, and the "DUT" would have the same type def cluster of limits that could be more, or less restrictive.  The VI I made needed to merge these two clusters finding the most restrictive set of limits.  If a limit was NaN then it wouldn't add any restriction on the existing limit.  There was also a third cluster set for the "Sequence" being ran.  It could have a "Maximum Allowed Voltage" which would need to be merged with the existing limits.  In practice the "Sequence" limits were usually NaN using whatever limits the System and DUT came up with.

 

Sorry for such a long explanation.  All of that is to say I could see an XNode of this type, or a similar kind, being useful in the past for merging sets of limits from various sources.

0 Kudos
Message 18 of 19
(45 Views)

@Andrey_Dmitriev wrote:
One approach is to use the “Cluster to Array of VData” and “Array of VData to VCluster” pair functions from the OpenG Toolkit. These let you convert a cluster into an array of variants, override the desired values, and then convert it back. This works under the simple assumption that your values are sequential, so the "Default" cluster always contains the “Strict” portion at the beginning:

 

 


You can combine the OpenG tools with the Data Parsing Tools to get the variant's element name. This appears to work:

 

BertMcMahan_0-1763591388976.pngBertMcMahan_1-1763591398602.png

 

 

I'd recommend switching this to a VIM, then it should work without any coercion dots or variant shenanigans. Please note I didn't test this fully, so there could be some corner cases that don't work (like nested clusters, clusters that contain actual variants, etc.). It also uses cluster element names to match up the data, so if your cluster elements are unnamed, it won't work.

 

0 Kudos
Message 19 of 19
(6 Views)