S7 - Call of FB in a FC??

Halløj Dariusch :)

You can call an FB from an FC, and you can call an FC from an FB.

There is nothing wrong or questionable in either.
If it is a good idea depends on the task.
 
Dariusch,


  • is it possible? Definitely yes!
  • is it a good idea? Sure, I do it all the time. (I don't mean I only have good ideas :ROFLMAO: ). But if you're using a lot of FB calls, then you might considering calling these FB's as multiple instances from within another FB. This way you only need one instance DB for the calling FB instead of separate instance DBs for every FB call.
Kind regards,
 
Yes you can and yes it is.

Whether you actually want to is somewhat program format and application dependent. I can't remember how many levels of calls the different S7 models will support. But I'm sure all of them do at least 7 levels. So in most typical applications you don't need to worry about going that deep.

Where and how you use this is pretty much up to you. I often use FBs called from FCs when I have a functional math group that I want to keep together with its data. The FB allows you to do that easily. I also use FBs where I have a function that must be used more than once a program scan. I think this is the more classic use of the FB; multiple calls to the same code with different data. In this case you often have to call them from FCs just to keep the logical flow of your program reasonable.

Keith
 
Yes and yes, on both questions.
It's up to you to decide how to design your program.
The advatage is that you can create functions that are general in functionality. Thereafter you can reuse them in other projects.
The descision of using FC:s or FB:s is up to the enigneer.

Good luck
 
Calling FB's

Would you mind posting some examples of Calling a FB?

I was reading the help files and says that a call to a FB will always be no matter the results of RLO or any other condition.

How can I call an FB only when it meets certain conditions?

Do you have any idea?

Thanks in advance...
 
Nery said:
Would you mind posting some examples of Calling a FB?

I was reading the help files and says that a call to a FB will always be no matter the results of RLO or any other condition.

How can I call an FB only when it meets certain conditions?

Do you have any idea?

Thanks in advance...

Well, there are a couple of ways.

If you are using FBs without explicitly defining an associated instance DB, then you can use the UC and CC instructions, i.e.:

UC FB1
CC FB1

Or, you could simply jump around the call when necessary:

AN M10.0
JC M001

CALL FB1, DB1

M001: NOP 0
 
If you use CC or UC for FB's, I would say you need to know what you are doing. This type of call does not allow you to assign an instance DB, it also does not allow you to assign parameters. Below is an example of calling a FB and then an UC of the same FB.

Code:
	CALL  FB	 1 , DB20
	   Input1 :=M1.0
	   Input2 :=M2.0
	   Output1:=M3.0
 
	UC	FB	 1

If the FB has NO IN, OUT, INOUT or STAT parameters then there is no problem. If it does, then depending on whether you are calling from a FC or a FB, there are two ways of dealing with it.

The first can be done in both, where you generate a DB (by calling the FB and then deleting the call and replacing with UC). You would then open this IDB with OPN IDBx from within the FB.

OR, if calling from the FB, the UC FB musts have the identical parameter build as the calling FB. It can be shorter in length, but as much as there is, has the match the calling FB, then they will share the same IDB.
 
PeterW said:
If the FB has NO IN, OUT, INOUT or STAT parameters then there is no problem.

...and it may as well be an FC.

PeterW said:
..open this IDB with OPN IDBx from within the FB.

You should open the instance DB before calling the FB, otherwise you can never call the FB more than once. Very important note: You must also set AR2 prior to calling the FB as all variable access within a FB actually uses [AR2,P#x.y] indirect addressing.

PeterW said:
if calling from the FB, the UC FB musts have the identical parameter build as the calling FB. It can be shorter in length, but as much as there is, has the match the calling FB, then they will share the same IDB.

If calling an FB from an FB with UC, declare the FB you are calling as a multiple instance in the STAT area to make sure the instance data for the FB is allocated, you still need to set AR2 youself prior to the call to ensure the correct area is used.
Here is an example I did a while ago: http://www.plctalk.net/qanda/showpost.php?p=95075&postcount=7
 
SimonGoldsworthy said:
...and it may as well be an FC.

I agree with that sentiment.


You should open the instance DB before calling the FB, otherwise you can never call the FB more than once. Very important note: You must also set AR2 prior to calling the FB as all variable access within a FB actually uses [AR2,P#x.y] indirect addressing.

I have to look at what my German friends are doing then as this code appears in a FB called via UC.

Code:
	OPN   DI [#itpPos_db]

Funny thing its on the second segment, after some STAT's were used in the first. The structure again mirror'd the calling FB though.


If calling an FB from an FB with UC, declare the FB you are calling as a multiple instance in the STAT area to make sure the instance data for the FB is allocated,

I wholeheartedly agree with that too.

In the systems I'm working at the moment, we have one German supplier who's been playing every trick there is (I've learned a few things), which includes doing this very thing and also passing in FB's as 'IN' ANY parameters, FB's calling themselves (ie FB32 calls FB32) and I/O addresses stored in pointer format in datawords.

Forc the UC's the FB's STAT's are all made up of UDT's and all have the same two IN parameters, then the first block has all the UDT's, then blocks called within have the UDT's in order up to the point where the blocks specific UDT is.

I feel they did a lot of things just to make it awkward for other engineers to follow, keeping the knowledge in-house, they say its because of scan time restraints.

Maybe in reality a bit of both.
 

Similar Topics

I've gotten to the learning curve where I can program a call for pump to come on at set point but I'm not sure how to turn the same pump off when...
Replies
1
Views
106
Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
643
I created this FC and it compiles, but when I use it in my MAIN OB1, it appears to have two outputs. See pictures. What am I doing wrong here...
Replies
9
Views
1,453
Is there a way in CX-Programmer to call Ladder Instructions from a structured text program? I can see several functions in the autocomplete...
Replies
3
Views
1,896
Is there a way in CX-Programmer to call functions from a structured text program? I have found this manual that seems to describe the process...
Replies
1
Views
1,019
Back
Top Bottom