03-13-2024 02:30 PM
Hi,
I am working for a small company that produces controllable devices via telecommands and telemetries.
I have developed a software to control them for internal testing purposes (Control, acquire and analyse data for PASS/FAIL criteria), but I now need to review it completely because it was not scalable: A new device with an different On-Board Software means potentially a lot of new development on my software.
In this aim, I am currently thinking of working with classes (obviously) but mainly configuration files for each devices to avoid hard coding information and have it rather loaded dynamically. This (these?) file would:
The point being to have a file that is readable/editable both by humans and by my software. And I'm not sure which file format is the most adapted for that.
I would be the one preparing such a file (and how to manage it) but I wouldn't be the one filling it in, which is my tough part.
As I see it, I have roughly 2 solutions:
I am fairly new to this configurations ideas since my last application was not scalable in that manner 🙂 So any advices or just stuff to read are very welcome.
I have seen this post about a Configuration Editor Framework, it looks interesting and I will give it more thoughts, but I wanted to have some more options from people that most likely already had this issue before me 🙂
https://forums.ni.com/t5/Example-Code/Configuration-Editor-Framework-CEF/ta-p/3984276
Thanks a lot for your help.
Vincent.
03-13-2024 02:36 PM
I am personally a fan of JSON, especially if using the JSONtext library from JDP Science. It is not that bad to read in a text editor as long as you do proper indentation. I find it a lot easier to read than XML.
03-13-2024 03:50 PM
If this was a configuration file that would only be saved/edited using an interface of some kind I would agree with crossrulz about using JSON with that toolkit.
However, if a configuration file is meant to be edited by humans, I would recommend instead the standard "Config file" format, i.e. the format used by most *.INI files. JSON can be great for importing fields that aren't flat (like an array of clusters containing another array of clusters) but for anything that could just be called "flat" or easily made into something "flat" then INI files are probably best to hand-edit as it supports inserting comments in the file itself, has a built-in set of LabVIEW VIs for dealing with it, and is less dependent on having just the right setup of brackets and quotes to be computer-readable (since hand-edits could easily break that sort of thing).
03-13-2024 05:16 PM
@crossrulz wrote:
I am personally a fan of JSON, especially if using the JSONtext library from JDP Science. It is not that bad to read in a text editor as long as you do proper indentation. I find it a lot easier to read than XML.
Second that!
There is a joke about XML adapted from a different one about regular expressions.
I had a problem to store hierarchical data in a file and choose XML.
Now I have at least two problems!!
03-13-2024 10:53 PM
Recently, I have grown fond of the yaml format predominantly due to how easy it is to use in Python. If similar intuitiveness is available in LabVIEW, I will vouch for Yaml.
03-14-2024 03:51 AM
Hi,
Thank you for your answers.
I have never worked so far neither with JSON nor with yaml, I'm done to try any, just need to make sure that this will work for my colleagues too.
We're talking about 100s of Telecommands and telemetries, together with specific parameters and conversion factors (that all might or might not be shared from one device to another.) I'm afraid that a JSON might be quickly impossible to skim through in a text format and do specific changes, no?
In that case I would need to have a configuration file manager, which I am ok with, but it simply takes time to develop.
But before starting anything I need to be sure of my interfaces 🙂
03-14-2024 11:36 AM
If you go with JSON, I recomend using Notepad++, as it gives syntax highlighting (does XML and YAML cas well). Here is a small example JSON produced by the Config-file example in JSONtext:
03-14-2024 12:25 PM - edited 03-14-2024 12:25 PM
Yet another recommendation for JSON here as well, especially with drjdpowell's absolutely excellent JSONtext library. I've switched away from ini files completely as json is just SO MUCH more flexible. I'd suggest looking into YAML as well, just because it might fit your needs better, but I can say XML is MUCH harder to use and INI is (usually) much too simple for anything complicated.
If you literally only have key/value pairs, INI is fine, but the instant you need things like unique sections, or repeated key names, or arrays, etc, you'll wish you had something more flexible.
And another vote for Notepad++ for viewing it. Enormous JSON files aren't exactly "simple" to look at, but neither will a giant INI file. YAML might be a little easier on the eyes but I haven't used it for anything "real" before so I'm not certain how the flexibility works.
For my use case, I have one big JSON file that controls all of my "stuff" in my test program. It has different subsections for different things, and I've written viewers that let me edit just the important stuff for the section I'm working on. I can do this manually, but when you have a 2000+ line JSON file you'll want something more "automated" than trying to only ever do things by hand. For example, section C depends on items from sections A and B being correct for it to work, since it refers back to them. My custom editors can run a quick check so when I edit section C it'll tell me right away if I've done it right, or if I've tried to refer to something undefined in another section. That would be a giant pain to do manually in a text editor, and would cause annoying bugs that also take a long time to track down in the actual test routine software.
tl;dr: Use JSON because it's much more flexible than ini, much more readable than xml, and has a great parser already available (though I admit there may be a great YAML parser that I've simply never heard of).
03-14-2024 01:05 PM - edited 03-14-2024 01:09 PM
I prefer XML and if you use the free XML Notepad program XML files are very easy to create and edit.
The LabVIEW XML vi's are fairly straight forward to use to parse XML files.
What the raw XML file looks like
03-14-2024 02:12 PM
@RTSLVU wrote:
I prefer XML and if you use the free XML Notepad program XML files are very easy to create and edit.
The LabVIEW XML vi's are fairly straight forward to use to parse XML files.
I did the same thing for a little while. But I found the JSON libraries in LabVIEW A LOT easier to debug than XML. I have recently ripped almost all XML capability out of my HAL since I decided to stick with JSON as my standard.