I am wondering if anyone has some tips/ideas on how to define constants that are configuration specific.
I have unique calibration values across hw configurations, but all use the same program. Ideally, I would use a variable declaration file within in each configuration and then reference this (via PV Mapping or otherwise) in the program.
Any information on how one might implement this would be appreciated. Thanks!
Hi Hector,
there is no “direct” method to do this. But you could put the project specific constants in separate Files with an Suffix other than “var” (e.g. constants_cfg1.txt, constants_cfg2.txt, …) and use a Pre-Build script to copy the correct file to another .var-file which then would be used for the build procedure.
Refer to GUID db8e9ccb-f4dd-48c7-9e16-96ee9f2089e9
Hi, thanks I’d had a look at that. The issue with this method for me is that the configuration-specific constants I am using in this case are structs.
One idea I had was just to define a number of global variables, and then use PV mapping to map in the correct variable for each configuration.
I was hoping there would be a more elegant solution though
This defines “HECTORS_SWITCH”.
With “-D #NameOfVariable”. This is Configuration specific and you use in the code like so:
With that, for every Configuration that has the Switch “HECTORS_SWITCH” the variable “VARIABLE_A” will have the value 100, every one without it will have the value 200.
Maybe you can do something with that…
coming back to @wielando 's suggestion:
I really like that idea so much that I did a simple sample to show how it could be used!
Of course it’s only a simple sample to show the principle, it could be even done better with more usability and functionality (for example storing also the batch file inside the project, use the internal system variable with the configuration name, and so on …) - but showing the “how it works” it’s good enough
Let’s assume we have 2 configurations with different member values inside the constant structure. The task “Program” uses the global constant structure variable named “myConfigConsts”, with variable declared in the global variable file “SetupConst.var” (and type declared in the global typ file “Global.typ”).
The batch file overwrites the “SetupConst.var” file with the wanted template file.
Input argument 1 (%1) to the batch file is the Automation Studio project path, argument 2 (%2) is the name of the template file:
So, when compiling for example configuration “Config2”, the pre-build step changes the “VarConst.var” content via the batch file to the wanted constant values.