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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
What do you mean with "instantiate methods"
Sent from my Moto G (5S) Plus using Tapatalk
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
I think you are asking about this: https://help.codesys.com/webapp/_cds_method_fb_init_fb_reinit;product=codesys;version=3.5.14.0#interface-of-the-fb-init-method
Using the FB_Init method will call anything you ask it to when the function block is created.
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
Looks like some wrong access specifier :
https://help.codesys.com/webapp/_cds_obj_method;product=codesys;version=3.5.14.0
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!