Passing a BlockDB as a parameter two levels deep

  • Thread starter k.zonouzi ahmad
  • Start date
K

Thread Starter

k.zonouzi ahmad

Dear sirs,

I want to use a function block with an instance DB in a function that is called from another function twice, and this second function is called from OB1 with actual parameters.

So the situation is something like below:

FC1(first common function):
VAR_IN
DB_In : Block_DB
END_VAR
...
call FB1, DB_In
...

FC2(second function called by OB1):
VAR_IN
FC2_DB_1 : Block_DB
FC2_DB_2 : Block_DB
END_VAR
...
Call FC1
DB_In := FC2_DB_1 <--- ***
Call FC1
DB_In := FC2_DB_2 <--- ***
...
END_FUNC

At *** i get illegal parameter assignment

OB1:
...
Call FC2
FC2_DB_1 := DB1
FC2_DB_2 := DB2
...

So how may I do it?

Best regards,
k.zonouzi ahmad
 
Hello;

If this is for Siemens S7 CPUs (you don't mention the model of PLC), I would suggest that you replace FC2(second function called by OB1):
> VAR_IN
> FC2_DB_1 : Block_DB
> FC2_DB_2 : Block_DB
> END_VAR

by FC2(second function called by OB1):
> VAR_IN_OUT
> FC2_DB_1 : Block_DB
> FC2_DB_2 : Block_DB
> END_VAR

The In_Out variable can be used both as input and output of a FC/FB.

Tell us if it helps,
Daniel Chartier
 
K

k.zonouzi ahmad

Hi dear Chartier,

Declaring Block_DB as a parameter type is only permitted in VAR_INPUT part of a SCL block, or as INPUT in FBD/STL/LAD interface section. But as I have tested, the changes in the block are reflected on the actual parameter defined as Block_DB in the INPUT section, despite its declaration in INPUT section.

But my problem is that when I pass a local variable defined as Block_DB as the input of a function that has a Block_DB input, I got the invalid parameter, or something similar that means I can't do this, as an error.

I have seen a way to pass DB number as a word input to the called function in Siemens site, to mitigate the error, but I don't know how in the called function I may use the DB number to call a FB with this DB number as its instance DB, something like the below, that is what I was looking in my example:

call SFB4, DB_Block

or as a word parameter
call SFB4, DB [#DB_Number]

In a FB we may declare DB_Number in Static part, but when we declare it in other parts, that are available in FC also, we get a syntax error.

As a reference, I read somewhere, "...you can't pass a local variable to an FC inside an FC..." in "http://modbus.control.com/user/1026236263/index_html".

Best regards,
k.zonouzi ahmad
 
Top