Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Function or function block?

Dario
2006-06-27
2006-07-03
  • Dario - 2006-06-27

    Hi developers,

    could you explain me what's the real benefit of using FBs rather than functions

    IMHO they are quite similar.

    Best regards

     
  • Igor Petrov - 2006-07-03

    In the general case function is more preferable. It takes a little bit less memory and easy to use (you need not to declare instances). If you can use a function (you need not internal memory in the POU and 1 output is enough) then you have to use it.

    With one exception , if we need POU with many 'parameter' (constant) inputs FB can be more suitable, especially in cycles. For example:

    Function:

    Indeed I have only one 'x' varying value, but I have to write in all places:

    And each time the compiler will generate code for transferring all parameters.

    With FB I can write input parameters only once:

    Further in all places (or in cycles) I can write only:

     
  • Dario - 2006-07-03

    Thank you for the explanation

     

Log in to post a comment.