AS Configurations Constants

Hello community,

I am looking for a functional way to define different constant values for different configurations in AS.

Example.

I have a global constant MY_ARRAY_LENGHT = 10 based on which I have defined an array… but the size varies depending on the configuration.

How can I define this constant for each configuration without having to manually change it in the .var file after changing the machine configuration?

Thank you

Hi Michal,

In the pre-build you can run an Python script that is building an .var file based on your configurations with the correct values of that config.

1 Like

hi Tom,
is there any plug and play solution available? this sounds a bit advanced.

Are there also easier ways how to make in inside AS?

Hello,

can you check if this thread helps you.

Greetings
Michael

1 Like

I think the link @michael.bertsch shared with you is the perfect solution for you @michal.sekerka. I would use a PYTHON script if I needed to adapt more things in the configuration. If you need that, let me know and I will give you a contact for a PYTHON expert in B&R who will help you with it :wink:

hi, @michael.bertsch is this also usable for defining global constant that is used as array index for variables? because the use case there is more simple as it is just a assignment of variable.

Hello,

i am not an expert on this, i only provided a link to the other thread.

I think you would like to do this… a Define used in a .var File. → My Test showed that Automation Studio is not happy about it an throws some Errors. Also the SmartEdit marks it as red.


In ST-Code the Define is maked as Blue.

Greetings
Michael

I’ve noticed it’s also possible to add *.var files to configs in the configuration view. I thought this is the perfect way to declare some global constants that can be used for array size definition etc.

Unfortunately, I was not able to get it working. AS Help did not give me any hints either. Probably it’s a deprecated leftover or something.

If someone got it running, I would highly appreciate any insights.

What I do not like in case of the prebuilt script is that versioned source code gets manipulated at compile time. This implies challenges.

Hi there,

just to give my input: Instead of working around getting the array to the proper size, maybe instead just adjust the handling of it in the code? When you can use the mechanism of compiler flags there (seems so), you can just make sure to only use the amount of array elements you need. So using Michael’s example code with the flexible MAX_IDX but defining the array itself with the maximum size you need across all configs.
So example:
Array size: 100 elements (static value, no defining involved)
Config 1: Only iterates through 20 elements, 80 unsued
Config 2: Iterates through 80, 20 unused
Config 3: Iterates through 100, 0 unused

Maybe that’d do the job as well?