CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Feb 19, 2019 9:46 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Feb 05, 2019 2:57 pm 
Offline

Joined: Thu Oct 25, 2018 2:41 pm
Posts: 5
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


Top
   
PostPosted: Tue Feb 05, 2019 3:10 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 263
What do you mean with "instantiate methods"

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


Top
   
PostPosted: Tue Feb 05, 2019 3:25 pm 
Offline

Joined: Thu Oct 25, 2018 2:41 pm
Posts: 5
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


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Tue Feb 05, 2019 5:35 pm 
Offline
Frequent User
Frequent User

Joined: Tue Dec 03, 2013 11:52 pm
Posts: 106
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.


Top
   
PostPosted: Tue Feb 05, 2019 9:41 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 263
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


Top
   
PostPosted: Wed Feb 06, 2019 8:40 am 
Offline
Frequent User
Frequent User

Joined: Fri Feb 23, 2018 3:41 pm
Posts: 100
Looks like some wrong access specifier :
Codesys Help wrote:
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


Top
   
PostPosted: Wed Feb 06, 2019 12:58 pm 
Offline

Joined: Thu Oct 25, 2018 2:41 pm
Posts: 5
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!


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited