Configuration specific constants

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!

1 Like

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

2 Likes

You could take a look at this guide by @roger.vila
Define a variable depending on the HW configuration

3 Likes

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 :slight_smile:

Hi Hector,

have you tried using compiler switches? You can define them in the CPU-Properties:

This defines “HECTORS_SWITCH”.
With “-D #NameOfVariable”. This is Configuration specific and you use in the code like so:
image

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…

1 Like

Hi Hector @Hector_Pople,

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 :wink:

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”).

image

What we need:

  • 2 “variable file templates” holding the different constant values (“Cfg1Const.txt” and “Cfg2Const.txt”)
  • a batch file for overwriting the “SetupConst.var” with the suitable template file
  • a pre-build step calling that batch file in every configuration

The template files are nothing more then a text file holding the content of SetupConst.var with the wanted constant values:

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:

And finally, in the configuration dependent pre-build steps the batch file is called with those 2 arguments:

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.

Best regards!

3 Likes

Thanks everyone for your help and detailed explanations :smiley: