06-02-2022 05:17 AM
hi,
I am currently working on redefining our methods for storing control values to ini files.
The way we go about it now is we read all VI panel controls and filter them by neccessity of storing (by using label text).
The downside of this is that each topmost cluster or array is stored only (all contained controls are part of the stored value).
This is mostly an issue when between versions of our executables the content (number and type of controls) of these clusters and arrays change.
I did some exploratory work with the OpenG library and found some solutions ot this by checking if the control is a cluster or an indexed cluster (an array containing clusters) looping through all the values needed to write and writing them to the element with the same label text.
This enables the storage to be more robust as it does not break everytime we add controls etc.
However, I ran into cases where we have deeper nested clusters (an array of clusters which themselves contain clusters again).
how do I create a sort of recursion for detecting the bottom most "child" within these nested clusters and work my way up from them to the top array?
See the screenshot below for the "exploratory" data reformatting methods I came up with:
for clarity, the problem arrised when I make a change in the deepest cluster of array 2 or array 3. This will result in the complete array not being written.
The solution is to implement another check for data typing and add the top solution for writing clusters, but how do I make this more recursive to solve any future cases of deeper nesting?
Solved! Go to Solution.
06-02-2022 03:10 PM
If I understand correclty, you can use a While Loop and a shift register with the ClassName and loop trough it until there is no Array or cluster
06-02-2022 08:39 PM
I would recommend getting away for INI files since they do not do well for embedded data. I would use JD Powell's JSONtext library to save the data to a JSON file. JSON is a lot easier to understand when you start dealing with clusters, arrays, arrays of clusters, etc. And that library works wonderfully, even if the cluster has changed definitions between your versions.
06-02-2022 09:16 PM
For such nested complex data structures, XML or JSON are better suited than INI files.
06-03-2022 02:43 AM - edited 06-03-2022 02:44 AM
I understand that JSON is an easier to read format.
Unfortunately, we do not want it to be human readable (due to customers being able to modify controls that they normally dont have access to).
I did some further digging yesterday and deviced a new method that still writes to INI files, but is able to check data for deviations and act accordingly (non-destructive) by using the JKI "Adapt to Type" VI.
I will share the code piece below for future reference:
new VI completely
write case of VI
if people are interested in this method, please let me know and I'll upload it.