"Function block call requires a function instance" when calling action in Codesys

standeven

Member
Join Date
Feb 2015
Location
British Columbia
Posts
14
"Function block call requires a function instance" when calling action in Codesys

Using Codesys 2.3, I'm getting the following error:

"A function block call requires a function block instance."

My call to the function is in a PRG as follows:

Code:
PROGRAM TestProgram
VAR
[INDENT]testFunctionBlock:MyFunctionBlock;
callAction:BOOL;
[/INDENT]
END_VAR

testFunctionBlock(inputVar:=1);

IF (callAction) THEN
[INDENT]testFunction.testAction();[/INDENT]
END_IF;


Any idea why this won't build? The function block is instantiated, so I'm not sure what's going on. I suspect I might be calling the action wrong.

Thanks for any help!
 
Didn't seem to upload. Here's the code.

PROGRAM PLC_PRG
VAR
MyFB : test;
END_VAR

MyFB(InVar:= 1);
MyFB.act();

--------------
Here's the fb

FUNCTION_BLOCK test
VAR_INPUT
InVar:INT;
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR

;

----------------
And the code for act

;
 
Thanks (8{)} ( .), you helped me solve the problem.

The example code I provided was a bit simplified from my actual code, so I tried it and you're right, it does compile.

The problem was that I had a variable in the function block with the same name as the action (variable was zeroCount, action name was ZeroCount). This confused the compiler, so I renamed my action and now it works.

Thanks again.
 
my answer of yesterday did not come trhu, so again,
you are calling the FB twice, so it should be declared twice. If you do this with a timer it does compile, but the timer is not accurate.
same for FB .
it does compile and work fine, however the VAR are the same for both instances.
 
Thanks shooter. I think your answer did come through, just on the codesys board where I also asked this question :)

My understanding with this code is as follows:

An area is allocated for the function block in memory when I declare it as a variable, and an instance of the function block is created.

When I call the function block with input, it updates that instance with the new information.

When I call the action of the function block, it again refers to the same instance.

Isn't this okay? I want to be able to use different actions at different times with only one instance of the function block.
 
so you call a action via a function block
yes can be done, it is typical OOP, however it is hard to control in codesys, so why not use a function for it?
 

Similar Topics

Hi, I'm learning GX Works 2 for upcoming project. I want to use ST Function Blocks in Ladder Program and it works if the FB(Structured text)...
Replies
5
Views
1,583
Hi guys! need your help for proper syntax in calling a function block using structured text since i am a total noob in ST! this is kinda basic for...
Replies
4
Views
20,217
Please see attached file. I need this program in Function Block form but I am totally lost on this. Any help would be appreciated. Thanks!
Replies
8
Views
257
Hi! I am using a TM200CE40T PLC from Schneider to write data over Modbus. I have used Memory words (%MW) before using the Write variable...
Replies
1
Views
512
Hi folks. New to the forum, but been working with PLCs for several years now. Would like some advice on whether you would keep this logic, or...
Replies
9
Views
1,039
Back
Top Bottom