Hello. I was wondering if it is possible to declare structs as constant in AS? If I try to do so it results in compilation failure stating that the struct is undeclared.
Here is a minimal example of how to replicate the problem.
Types.typ file:
TYPE
TestConstStruct : STRUCT
value1 : DINT;
value2 : DINT;
END_STRUCT;
END_TYPE
Variables.var file:
VAR CONSTANT
test_struct : TestConstStruct := (value1:=10,value2:=20);
END_VAR
VAR
test_var : DINT;
test_struct2 : TestConstStruct := (value1:=10,value2:=20);
END_VAR
Main.c file:
#include <bur/plctypes.h>
#ifdef _DEFAULT_INCLUDES
#include <AsDefault.h>
#endif
void _INIT ProgramInit(void)
{
}
void _CYCLIC ProgramCyclic(void)
{
test_var = test_struct.value1;
}
void _EXIT ProgramExit(void)
{
}
I used table view to declare the variables so .var and .typ files were generated by AS. The only difference between test_struct and test_struct2 is that I marked test_struct as constant. test_struct2 can be used just file but using test_struct result in compilation error:
149 Error: ‘test_struct’ undeclared (first use in this function);
