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

Methods Auto-Instantiation for a Library Function Block

Halim
2019-02-05
2019-02-06
  • Halim - 2019-02-05

    Hi,

    I'm creating a library function block with some Methods under/attached to that FB. I want the Methods to get instantiated automatically once the parent FB instance is created.
    Can someone guide me on how to do that?

    Thanks in advance for your time.

    BR

     
  • josepmariarams - 2019-02-05

    What do you mean with "instantiate methods"

    Sent from my Moto G (5S) Plus using Tapatalk

     
  • Halim - 2019-02-05

    I mean: Suppose I have a Function Block that has two attached Methods 1 & 2. When I instantiate the FB, I need the methods POUs to be instantiated as well under the new Function Block Instance. I attached a photo with the desired behavior for illustration.
    In red: the current behavior, I have to create the new methods POUs manually, and select the methods from a list.
    In green: I want all the methods in the template created in my project once I instantiate the FB

    IMG: desired.png

     
  • josepmariarams - 2019-02-05

    Hi.

    Instantiation of an FB is not the process of call him, is rhe process of the creation (the declaration between var end_var.

    In the body of the pou, you are calling an special method of the fb -the body of the fb-.

    The methods are not called automatically. You can call him from inside the own fb or from fb-init (only one time as comminback says).

    When you instantiate an fb, his methods is not necessary to recreate or instantiate. Are there if you need to use it.

    One FB is an structure of variables (variables that you have created inside the fb) and methods associates with it ( including the fb body).

    When you create an instance of an Fb, you have created one copy of the structure. The methods are the same for all FBs.

    When you call an method of an FB, this method works with the structure of the Fb.

    I don't know if it is the answer that you need...

    Salut!

    Sent from my Moto G (5S) Plus using Tapatalk

     
  • dFx

    dFx - 2019-02-06

    Looks like some wrong access specifier :

    Codesys Help hat geschrieben:
    Access specifier
    Controls access to data.
    PUBLIC or not specified: Access is not restricted.
    PRIVATE: Access is restricted to the program, function block, or GVL.
    The object is marked as (private) in the POU or device view. The declaration contains the keyword PRIVATE.
    PROTECTED: Access is restricted to the program, function block, or GVL with its derivations. The declaration contains the keyword PROTECTED.
    The object is marked as (protected) in the POU or device view.
    INTERNAL: Access to the method is restricted to the namespace (library).
    The object is marked as (internal) in the POU or device view. The declaration contains the keyword INTERNAL.

    https://help.codesys.com/webapp/_cds_obj_method;product=codesys;version=3.5.14.0

     
  • Halim - 2019-02-06

    Thanks a lot for your answers.

    I figured out that to keep the same structure and implement the base implementations each time a call happens, I have to use Interfaces (ITF). It works for me now, Thanks!

     

Log in to post a comment.