LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MGI Read anything: how to detect data structure change

Solved!
Go to solution

Hi,

 

I have started to use the MGI R/W anything VIs and I'm wondering if there is a way to detect if the data structure saved to the file is not the same as what I'd like to read. So for example: I write a cluster to file with three elements. Then I need to do some changes in the data and the cluster now has four elements. It seems that the MGI R/W anything reads back the content in the file to the appropriate fields of the new cluster which is great but it doesnt seem to signal that data in the file has only three elements.

 

Is there a built in way to detect the differences? I can read the control names of the cluster and compare them to the keys of the section like in an ini file. Its just hard to believe that I'm the first whos facing this problem.

 

Thanks!

0 Kudos
Message 1 of 4
(1,127 Views)
Solution
Accepted by topic author 1984

Actually, I've tended to view that behavior as a convenience rather than an inconvenience.  It lets me define default values in the code and then override *only* the cluster elements that are declared in the INI file.  So when the app is deployed, I can provide easy operator access to pretty limited subset of the parameters -- the ones which are readily visible in the originally deployed INI file.  That's all the operators know about, so that's all they can readily edit.  But that also leaves open the possibility for me to step in and do special troubleshooting by temporarily adding some of the hidden parameters back into the INI file.

 

But as to your actual question, I'd approach it the same kind of way I'd use to detect which optional wiring terminals of a subvi were wired.  Set the default values to "something illegal" that no one *should* pass in and then look for these illegal values.  (Then maybe follow up by reading a second time while wiring in a cluster containing your real default values).

 

Not foolproof of course -- for some cluster elements there'll be no such thing as an illegal value for you to detect.  Same kind of issue as detecting unwired terminals in a subvi.

 

 

-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.
Message 2 of 4
(1,053 Views)
Solution
Accepted by topic author 1984

What Kevin describes is how you are supposed to use this (or any other similar INI based file configuration solution like the OpenG library.

 

If you add new fields you should make sure that the inputs to the Read function has useful default values. In fact all fields should have proper default values as that makes the whole thing more robust. If you use INI files, you intentionally (or not) choose to make the file user editable. So you should be prepared for the possibility that items may be deleted and your software should have sensible default values for all of them that makes it still work in a useful way rather than throwing up lots of errors.

Rolf Kalbermatter
My Blog
Message 3 of 4
(1,040 Views)

Note: if you have a use case to treat ini structure changes more strictly, then you can add a "Revision" number, which you consult first to determine the format of the file. Then you can put in mutation code to convert to the latest revision.  So, for example, if revision 2 had Temperature in Celsius, but the current revision uses Kelvin, then you can convert the old settings.

Message 4 of 4
(1,022 Views)