使用明确定义了 FB_init 方法的 __NEW 初始化功能块
Initialize a Function Block using __NEW that has explicitly defined the FB_init method
假设我有一个定义了FB_init方法的功能块(A),例如:
{attribute 'enable_dynamic_creation'}
FUNCTION_BLOCK A
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL;
bInCopyCode : BOOL;
parameter: BOOL;
END_VAR
END_METHOD
END_FUNCTION_BLOCK
我还有另一个功能块 (B),我想从中动态初始化此 (A) FB:
FUNCTION_BLOCK B
VAR
a := POINTER TO A;
END_VAR
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL;
bInCopyCode : BOOL;
parameter: BOOL;
somethingElse: INT;
END_VAR
a := __NEW(A); // No matching FB_init method found for instantiation of A
a := __NEW(A(TRUE)); // Build returns errors
a := __NEW(A(parameter := TRUE)); // Build returns errors
END_METHOD
END_FUNCTION_BLOCK
我无法动态创建 A 功能块的实例。
这甚至可能,还是我做错了什么?
PS。我正在使用 Schneider SoMachine V4.3
您在功能块 B 中有错误。我尝试使用 TwinCAT 3 并且它有效。
改变
a := POINTER TO A;
至
a : POINTER TO A;
之后进行以下工作:
A:
{attribute 'enable_dynamic_creation'}
FUNCTION_BLOCK A
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)
parameter: BOOL;
END_VAR
B:
FUNCTION_BLOCK B
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
a : POINTER TO A;
END_VAR
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)
parameter: BOOL;
somethingElse: INT;
END_VAR
a := __NEW(A(parameter := TRUE));
假设我有一个定义了FB_init方法的功能块(A),例如:
{attribute 'enable_dynamic_creation'}
FUNCTION_BLOCK A
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL;
bInCopyCode : BOOL;
parameter: BOOL;
END_VAR
END_METHOD
END_FUNCTION_BLOCK
我还有另一个功能块 (B),我想从中动态初始化此 (A) FB:
FUNCTION_BLOCK B
VAR
a := POINTER TO A;
END_VAR
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL;
bInCopyCode : BOOL;
parameter: BOOL;
somethingElse: INT;
END_VAR
a := __NEW(A); // No matching FB_init method found for instantiation of A
a := __NEW(A(TRUE)); // Build returns errors
a := __NEW(A(parameter := TRUE)); // Build returns errors
END_METHOD
END_FUNCTION_BLOCK
我无法动态创建 A 功能块的实例。 这甚至可能,还是我做错了什么?
PS。我正在使用 Schneider SoMachine V4.3
您在功能块 B 中有错误。我尝试使用 TwinCAT 3 并且它有效。
改变
a := POINTER TO A;
至
a : POINTER TO A;
之后进行以下工作:
A:
{attribute 'enable_dynamic_creation'}
FUNCTION_BLOCK A
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)
parameter: BOOL;
END_VAR
B:
FUNCTION_BLOCK B
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
a : POINTER TO A;
END_VAR
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)
parameter: BOOL;
somethingElse: INT;
END_VAR
a := __NEW(A(parameter := TRUE));