SA0102: Access to program/fb variables from the outside
Function | Determines read accesses from outside to local variables of programs or function blocks. |
Reason | TwinCAT determines external write access operations to local variables of programs or function blocks as compilation errors. Since read access operations to local variables are not intercepted by the compiler and this violates the basic principle of data encapsulation (concealing of data) and contravenes the IEC 61131-3 standard, this rule can be used to determine read access to local variables. |
Importance | Medium |
Samples:
Function block FB_Base:
FUNCTION_BLOCK FB_Base
VAR
nLocal : INT;
END_VARMethod FB_Base.SampleMethod:
METHOD SampleMethod : INT
VAR_INPUT
END_VARnLocal := nLocal + 1;Function block FB_Sub:
FUNCTION_BLOCK FB_Sub EXTENDS FB_BaseMethod FB_Sub.SampleMethod:
METHOD SampleMethod : INT
VAR_INPUT
END_VARnLocal := nLocal + 5;Program PRG_1:
PROGRAM PRG_1
VAR
bLocal : BOOL;
END_VARbLocal := NOT bLocal;MAIN program:
PROGRAM MAIN
VAR
bRead : BOOL;
nReadBase : INT;
nReadSub : INT;
fbBase : FB_Base;
fbSub : FB_Sub;
END_VARbRead := PRG_1.bLocal; // => SA0102
nReadBase := fbBase.nLocal; // => SA0102
nReadSub := fbSub.nLocal; // => SA0102