11-26-2022 12:30 AM
I have a project with multiple VIs, there's a bunch of constants (some can change often, some are more permanent). I am wondering if there's an efficient and robust way of compiling all those constants in one place and have all my VIs read from that place.
11-26-2022 01:12 AM
Yeah, you can create an ini file with multiple sections (grouped logically) and create an LV2 that loads this ini file at the start of the application and read from this LV2 throughout your application.
Some even prefer an XML if you've complex structured data, but you're talking about constants which I would assume as scalar values that easily fit into ini file structure.
11-27-2022 12:13 PM - edited 11-27-2022 12:19 PM
I think the cryptic term "LV2" actually means a "LabVIEW 2 style global" (aka "functional global"), but since you need more functionality, an "action engine" is probably a better word. Are you familiar with those?
On "first call?" it would read the ini file, populate the data structures (e.g. held as cluster in a globally initialized feedback node), and return them. On later calls, it would just return the values. There should be modes to update individual values programmatically. There should also be a mode to write the current values back to the ini file. etc.
@jmerham wrote:
I have a project with multiple VIs, there's a bunch of constants (some can change often, some are more permanent). I am wondering if there's an efficient and robust way of compiling all those constants in one place and have all my VIs read from that place.
You probably need to be more specific, for example of something changes often, it is not really constant. 😄
Can the values change during the run or only between runs? What part of the program is responsible for the value changes? Should the final values be written do disk so the next session starts with the final values of the previous session? Are there good default values in case the ini file cannot be found?
so. many. questions!
11-27-2022 10:57 PM
Thanks, @altenback for clarifying the LV2 term, yes, I meant an FGV (aka LV2) based Action Engine to maintain the data loaded from the config file.
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000015BjzSAE&l=en-US
https://labviewwiki.org/wiki/Functional_global_variable
11-28-2022 06:43 AM
I'd be tempted to just use the simple Global Variable. All of the "constants" can be stored in a simple global VI. But these are not good for when you are performing actions on the data (read-modify-write) as that will create all kinds of race conditions.
Some references for things to consider:
Are Global Variables Truly Evil?
11-28-2022 08:51 AM
I meant @altenbach, I have to be careful while replying late at night.
@santo_13 wrote:
Thanks, @altenback for clarifying the LV2 term, yes, I meant an FGV (aka LV2) based Action Engine to maintain the data loaded from the config file.
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000015BjzSAE&l=en-US
https://labviewwiki.org/wiki/Functional_global_variable