LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Global variables vs. config. ini for e.g. physical constants

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!

0 Kudos
Message 1 of 6
(4,583 Views)
Hi CJ,

how should a global variable help here?

Use a file: ini, csv, txt, whatever you like...
Or use a VI contained in your user.lib to be accessible from each project!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(4,560 Views)

Hi,

Think for this situation is good solution file format (ini,csv,txt...).

With Best Regards

Hrachya

Certified LabVIEW Architect (CLA)
0 Kudos
Message 3 of 6
(4,554 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 6
(4,526 Views)

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.

Glad to answer questions. Thanks for any KUDOS or marked solutions 😉
0 Kudos
Message 5 of 6
(4,510 Views)

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.  

0 Kudos
Message 6 of 6
(4,500 Views)