According to the PLCOpen, IEC-61131 standard, is it possible to initialize a structure in the declaration?
I'm thinking of something along the lines of this C++ question.
According to the PLCOpen, IEC-61131 standard, is it possible to initialize a structure in the declaration?
I'm thinking of something along the lines of this C++ question.
 
    
     
    
    You can add default values to structure variables at struct declaration. You can also initialize variables with different values at variable declaration.
TYPE ST_Test :
STRUCT
    One     : INT   := 123;
    Two     : REAL  := 4567.5;
    Three   : STRING := 'Hello';
END_STRUCT
END_TYPE
In some block:
VAR
    //Original default values
    TestOriginalValues  : ST_Test;
    //Own initialization values
    TestOtherValues     : ST_Test := (One:=555, Two:=678.5, Three:='Whats up');
END_VAR
 
    
    The c++ example you gave is where they are defining a struct in a function.  The equivalent component in IEC61131 would be a function block.  You can initialize a struct in a function block 
FUNCTION_BLOCK SampleFunctionBlock
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
    internalBlockStruct:SampleStruct:=(One:=1,Two:=2,Three:=3);
END_VAR
and then use this struct in the function block code.  You can also initialize a struct in a pou if you wanted to by following the same syntax.
for reference this is my struct
TYPE SampleStruct :
   STRUCT
    One:INT;
    Two:INT;
    Three:INT;
END_STRUCT
END_TYPE
note: the example I gave is using Codesys syntax. Most IEC61131 languages have very similiar syntax.
