searching the forums didn't reveal any helpful advice.
I have a FB that is initialized through FB_init. It requires an additional parameter.
METHOD FB_init
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)
supportId : BYTE;
END_VAR
I have an array of these:
SupportHandlerArray:ARRAY[1..2] OF SupportHandler;
I can't successfully initialize all members of the array.
This works:
S1 : SupportHandler(1);
SupportHandlerArray:ARRAY[1..2] OF SupportHandler(0) := [S1];
This initializes all members to the same value:
SupportHandlerArray:ARRAY[1..2] OF SupportHandler(0);
These doesn't compile:
SupportHandlerArray:ARRAY[1..2] OF SupportHandler := [1, 2];
SupportHandlerArray:ARRAY[1..2] OF SupportHandler := [(1), (2)];
SupportHandlerArray:ARRAY[1..2] OF SupportHandler := [(supportId:=1), (supportId:=2)];
SupportHandlerArray:ARRAY[1..2] OF SupportHandler[(supportId:=1), (supportId:=2)];
The compilation errors range from syntax errors (for the last line) [ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0006: ';, := or (' expected instead of '[' [ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0138: No matching FB_init method found for instantiation of SupportHandler
To: [ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0138: No matching FB_init method found for instantiation of SupportHandler [ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0046: Identifier 'supportId' not defined [ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0018: 'supportId' is no valid assignment target [ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0046: Identifier 'supportId' not defined [ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0018: 'supportId' is no valid assignment target
What am I missing?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Works for me
I even deleted the return type BOOL for the function, and changed its capitalization like you did. Maybe you're on an older version? or a safety PLC? maybe you put the FB_Init not in the SupportHandler but in the calling FB? Maybe you have SupportHandler shadowed? Maybe on a different controller to Control Win, it doesn't like when you capitalize FB_Init differently, or don't use the return type BOOL?
searching the forums didn't reveal any helpful advice.
I have a FB that is initialized through FB_init. It requires an additional parameter.
METHOD FB_init
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)
supportId : BYTE;
END_VAR
I have an array of these:
SupportHandlerArray:ARRAY[1..2] OF SupportHandler;
I can't successfully initialize all members of the array.
This works:
S1 : SupportHandler(1);
SupportHandlerArray:ARRAY[1..2] OF SupportHandler(0) := [S1];
This initializes all members to the same value:
SupportHandlerArray:ARRAY[1..2] OF SupportHandler(0);
These doesn't compile:
SupportHandlerArray:ARRAY[1..2] OF SupportHandler := [1, 2];
SupportHandlerArray:ARRAY[1..2] OF SupportHandler := [(1), (2)];
SupportHandlerArray:ARRAY[1..2] OF SupportHandler := [(supportId:=1), (supportId:=2)];
SupportHandlerArray:ARRAY[1..2] OF SupportHandler[(supportId:=1), (supportId:=2)];
The compilation errors range from syntax errors (for the last line)
[ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0006: ';, := or (' expected instead of '['
[ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0138: No matching FB_init method found for instantiation of SupportHandler
To:
[ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0138: No matching FB_init method found for instantiation of SupportHandler
[ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0046: Identifier 'supportId' not defined
[ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0018: 'supportId' is no valid assignment target
[ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0046: Identifier 'supportId' not defined
[ERROR] LNDP-RTE-IPC: IPC_Handler(Line 12 (Decl)): C0018: 'supportId' is no valid assignment target
What am I missing?
What kind of data is SupportHandler?
It is a UDT?
Yes. It's my own Function Block.
I didn't make a test but try to take a look at the last post of this discussion:
https://forge.codesys.com/forge/talk/Engineering/thread/dbf5a245f1/
does it work for you?
No. It's a variant on one of the options I described above that doesn't compile.
For some reason the compiler tries to push INTs into the array and fails on compilation.
Works for me
I even deleted the return type BOOL for the function, and changed its capitalization like you did. Maybe you're on an older version? or a safety PLC? maybe you put the FB_Init not in the SupportHandler but in the calling FB? Maybe you have SupportHandler shadowed? Maybe on a different controller to Control Win, it doesn't like when you capitalize FB_Init differently, or don't use the return type BOOL?