11-10-2015 03:13 AM
Hello together,
this is my first post here. I tried to find an answer, but I did not.
I am an engineer and one of my task is to develop engineering solutions using e.g. LabVIEW. For different projects I am always using roughly the same physical constants. It is not comfortable to define them explicitly each time for each single project. So My intention is to have one "definition file" in which all these constants are defined. In each project I want to include this file so that also the constants are defined the same in each project (same number of digits, same units, etc....).
Is it better to use a config.ini or to use global variables? Or is there a third solution?
Thanks for answering!
11-10-2015 04:06 AM
11-10-2015 04:11 AM
Hi,
Think for this situation is good solution file format (ini,csv,txt...).
With Best Regards
Hrachya
11-10-2015 08:37 AM
We are dealing with CONSTANTS here. So Global Variables are awesome for this situation. Globals are really fast and if you are never writing to them (or only once at startup) then you do not have the race condition issue.
What I have done in a few applications is use a configuration file that is read to initialize the global variables which are then used as "constants" in the rest of the project.
11-10-2015 10:34 AM
With constants I normally have them all set up in the initialization phase of a Functional Global Variable. Then I can access all variables from this one FG easily. I use a TypeDEF cluster that can be read with an unbundle by name, or a second enum with a list of all readable items from my constant list without using an external unbundle by name.
This way I don't even have to bother reading an ini file, and it is simple to add any additional items by adding them into the TypeDEF and initializing them in the init of the case structure. I normally save ini files for items that are changed by the user or at least from program to program. It may not be as fast as a global variable, but it holds everything into tight code that is simple to manage from a common FG.
On a low end cRIO with limited memory this may not be the best approach and globals might be better.
11-10-2015 10:46 AM
Physical constants don't change from run to run of the application, so I make them an inlined subVI. Then they are compiled in, and often constant-folded into constant subcalculations.