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

"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

Hello, I'm trying to call a function block in Weintek which returns 'a'. The code is pretty simple, I return 'a' as 1, 2 or 3. All I'm doing is...
8
Replies
1,271
Views
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)...
5
Replies
5,036
Views
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...
4
Replies
23,011
Views
Hi I'm new to HMS/RedLion Crimson Function Blocks programming. Does anyone knows whether this straton engine includes the native straton Binding...
1
Replies
129
Views
I've watched some tutorials and am trying to gradually write some FBD that can handle a model of an intersection (traffic lights in 4 directions...
29
Replies
1,531
Views
Top