The accessibility can be defined for elementary variables (see example before) and for structured types like STRUCT, CLASS, FUNCTION_BLOCK and PROGRAM.
CONFIGURATION config
VAR_GLOBAL
{S7.extern=ReadWrite}
Motor1 : Motor; // the variables in Motor1 be read and written if enabled
{S7.extern=ReadOnly}
Motor2 : Motor; // the variables in Motor2 be only read if enabled
END_VAR
END_CONFIGURATION
CLASS Motor
VAR PUBLIC
{S7.extern=ReadWrite}
Run : BOOL;
ReverseDirection : BOOL;
END_VAR
VAR INTERNAL
{S7.extern=ReadOnly}
ActualVelocity : LReal;
END_VAR
// ...
END_CLASS
Notes:
-
To access variables inside structured types you must enable them at two locations!
- inside the CONFIGURATION (with exception of PROGRAM)
- inside a STRUCT, CLASS, FUNCTION_BLOCK or PROGRAM
-
The final accessibility is the most restrictive over all definitions
ReverseDirectionwill never be accessible (Hiddenis default)ActualVelocitywill always be read onlyMotor2.Runwill be read-only whereasMotor1.Runcan be written
Each structure level is adding its restriction if you nest multiple structured types like
CONFIGURATION config
VAR_GLOBAL
{S7.extern=ReadWrite}
s1 : struct1;
{S7.extern=ReadWrite}
s4 : struct4;
END_VAR
END_CONFIGURATION
TYPE
struct1 : STRUCT {S7.extern=ReadWrite} s2 : struct2; END_STRUCT;
struct2 : STRUCT {S7.extern=ReadOnly} s3 : struct3; END_STRUCT;
struct3 : STRUCT {S7.extern=ReadWrite} s4 : struct4; END_STRUCT;
struct4 : STRUCT {S7.extern=ReadWrite} s5 : INT; END_STRUCT;
END_TYPE
In this case the variable s5 will be read-only if accessed via s1.s2.s3.s4.s5 and can be written in case of s4.s5.