Skip to main content

SA0038: 对输出变量的读访问

检测输出变量(VAR_OUTPUT) 可以通过 POU 内的读取权限进行访问

理由:根据 IEC 61131-3 标准,禁止读取 POU 内的输出。这表明输出不仅用作输出,而且还用作中间结果的临时变量。应该避免这种双重用途。

重要性:低

48. 例子
VAR_GLOBAL
    g_xGlob AT %QX0.0 : BOOL ;
    g_iGlob AT %QW1 : INT ;
END_VAR
PROGRAM PLC_PRG
VAR_OUTPUT
    xVarOut1:BOOL;
    xVarOut2:INT;
    xVarOut3:INT;
END_VAR
VAR
    iCondition : INT;
END_VAR
iCondition := iCondition + INT#1;
CASE iCondition OF
    INT#1:
        xVarOut1 := g_xGlob;
        xVarOut2 := g_iGlob;
    INT#2:
        xVarOut3 := xVarOut2;    // SA0038
    ELSE
        xVarOut1 := FALSE;
        g_xGlob := xVarOut1;    // SA0038
        xVarOut2 := INT#0;
        xVarOut3 := INT#-1;
END_CASE

输出在 留言 看法:

  • sa_icon_message.png SA0038:对输出变量“xVarOUT2”的读取访问

  • sa_icon_message.png SA0026:SA0038:对输出变量“xVarOUT1”的读取访问