Skip to main content

属性:no_virtual_actions

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

如果将编译指示应用于基类,则其操作将受到保护,免于重载。

句法

{attribute 'no_virtual_actions'}

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

10.

功能块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步骤操作被替换为特殊实现ActiveActionActive 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

然而,现在你把指令{attribute 'no_virtual_actions'}在基类前面:

{attribute 'no_virtual_actions'}

FUNCTION_BLOCK POU_SFC...

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

_cds_img_pragma_virtual4.png