marcoqf73

Error E: S5004: Function blocks instances are invalid i

3 posts in this topic

Hello,
In past i was using Siemens S7 300 and Simatic 5.3. So a long time ago.
I restart look back to plc because i need to monitor the temperature of my heating system.
So bought a plc that is a IEC61131-3 standard and  OpenPCS as Develop software. 

So i begin to play with OpenPCS because  Im very rusty.
 SO i create a function, that i named FC_TEST .
When i compile the below code i get an error
E: S5004: Function blocks instances are invalid in 'FUNCTION'-POUs, STRUCTs, and in ARRAYs. 

It seams that Timer block inside the function FC_TEST are not allowed, i understood right ?

(*  --------- DECLARATION  ---------  *)
VAR_INPUT
T_1 : TIME ; (*Declare T_1 as a Time Input ==> Set the Time of Timer *)
START : BOOL; (*Declare START ad BOOL Input ==> Start The Time of the TIMER *)
END_VAR

VAR
MY_TON : TON; (*Instantiate MY_TON as Timer type TON*) 
END_VAR

(*  --------- FC PROGRAM  ---------  *)
MY_TON(IN := START , PT := T_1 );
FC_TEST := MY_TON.Q;
 

(*  --------- CALL THE FC---------  *)
tmp2 := FC_TEST(T#2s, I0_0);  (* I0_0 is a input*)


Thanks 
Marco

 

Share this post


Link to post
Share on other sites

Hi marcoqf73,

I don't know the OpenPCS software, but in IEC61131-3 there is a difference between a Function (FC) and a Function block (FB)

Function (FC) is PLC code excluding static data, meaning that all local variables lose their value when the function is ended. The variables are initialized again the next time the function is ‘called’. The function typically carries out a mathematical calculation and returns the finally calculated value.

Functions block (FB) is PLC code including static data. The local variables retain their values between each ‘call’ to the function.
For Siemens PLC there will be one 'instance db'
for every called function block that stores the local variables.

I think you have to put your code in an Function block (FB) instead of a Function (FC), because otherwise the compiler won't allocate
memory to store the local variable (MY_TON) between two calls

 

 

1 person likes this

Share this post


Link to post
Share on other sites
10 hours ago, AndreasW said:

AndreasW. 
Thanks, you are right, is now working.

I think you have to put your code in an Function block (FB) instead of a Function (FC), because otherwise the compiler won't allocate
memory to store the local variable (MY_TON) between two calls

Grazie
Marco

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now