Skip to main content

属性:no_virtual_actions

pragma 用于派生自 SFC 中实现的功能块的功能块,并使用该基类的基本 SFC 序列。从中调用的操作表现出与方法相同的虚拟行为。这意味着基类中操作的实现可以由具有自己特定实现的派生类替换。

如果将 pragma 应用于基类,则其操作会受到保护以防止重载。

句法:

{attribute 'no_virtual_actions'}

插入位置:功能块声明部分的首行

284.

功能块 POU_SFC 是派生功能块的基类 POU_child.派生类 POU_child 用特殊变量调用用SFC写的基类序列 SUPER.

_cds_img_pragma_virtual1.png
_cds_img_attribute_nva_ex1.png

此序列的示例性实施仅限于初始步骤,然后是带有链接步骤操作的单个步骤 ActiveAction.这个带有链接步骤操作的步骤负责配置输出变量。

an_int := an_int+1;    // Counting the action calls
test_act := 'father_action';
METH();              // Call of the method METH in order to set the string variable test_meth

在派生类的情况下 POU_child 步骤动作被一个特殊的实现所取代 ActiveAction. Active Action 与原来的区别仅在于字符串的分配 'child_action' 代替 'father_action' 在变量 test_act.

同样,方法 METH, 它分配字符串 'father_method' 到变量 test_meth 在基类中,被覆盖以便 test_meth 现在得到价值 'child_method'.主程序 PLC_PRG 调用功能块的实例 POU_child, 命名为 Child.正如预期的那样,字符串的值反映了派生类的操作和方法的调用:

_cds_img_pragma_virtual3.png

但是,现在您将 pragma {attribute 'no_virtual_actions'} 在基类前面:

{attribute 'no_virtual_actions'}

FUNCTION_BLOCK POU_SFC...

这改变了行为:虽然派生类的实现仍然用于该方法 METH,步骤动作的调用现在导致动作的调用 ActiveAction 基类的。所以 test_act 现在被赋予价值 'father_action':

_cds_img_pragma_virtual4.png