10-31-2014 02:44 PM
Hello,
I have been thinking about OO lately and I have a question regarding Configuration files. Currently I store all my data in one big clustersarus. I use Open G's write ini cluster to write the values to an INI file. If I go to an OO paradigm the open G Write INI cluster VI doesn't like classes. How do I save data stored in a class hierarchy to an ini file?
10-31-2014 03:15 PM
For classes I prefer xml for storing class data. Flatten to xml- write *.txt. Read *.txt and unflatten from xml it is wicked fast.
10-31-2014 03:43 PM
10-31-2014 07:45 PM
I have not done much with classes so I may misunderstand some things.
Could you create a method VI within the class which uses the ogtk VI internally?
Lynn
10-31-2014 08:28 PM - edited 10-31-2014 08:31 PM
Depending on your skill with OOP, the character lineator could be a good fit for what you want to do:
https://decibel.ni.com/content/docs/DOC-24015
What the character lineator gives you (along with many other tools for doing to/from string) is that it forces you to treat each value as a separate field you get and set and it tries to force you to use version numbers, so that your code can safely mutate from version 1.0 to version 1.1. The code is pretty heavy, but thats the basic idea.
I would personally recommend against "flatten to XML" because it is very inflexible. If you make any change to your data (even changing enums, for example), I've found that "unflatten" will pretty much always fail. At present the only reliable way I know to do flatten/unflatten in LabVIEW is to do it element-by-element (that is, manually build the string and parse the string, or use something like the character lineator as a tool to help you do that). That having been said it depends on how often you want to change the code and how much effort you want to invest. I usually do end up using flatten to XML or JSON just because its so easy.
10-31-2014 09:14 PM
h, you want something a bit more human editable than a flattened string.
I would still go XML for class data Still flatten to XML string but write to XML File. not a straight .txt
It looses a bit of speed over flattened xml data but not as much as other methods that can be opened in a browser. (like 100x the speed of parsing a JSON or "Non LV Schema" XML File DOMUserDefREF.DLL must run single threaded in the UI Thread
11-13-2014 12:50 PM
11-13-2014 01:33 PM
Save it with a *.vit extension in
C:\Program Files (x86)\National Instruments\LabVIEW 2013\templates\MyClass Methods\
The File>>New...Dialog will let you create a new vi from that template
CAUTION: Wire The Error chain- Get a File Path input in there and for gosh sakes use the name of the class as the section name (The default section [Data] would be common among all of your classes)
11-13-2014 01:48 PM
11-13-2014 01:57 PM
Currently you need to use file new... and save the vi
Then add it to your class.