CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Sun May 28, 2017 9:34 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Apr 28, 2017 8:07 pm 
Offline

Joined: Wed Oct 14, 2015 2:27 pm
Posts: 2
I have created a class (FB with Methods and Properties).

I would like one the variables within this class to be another class (FB with Methods and Properties).

But when I try to use F2 to enter a specific method or property of the instance within the instance, I cannot find the instance within.

I would like to access the elements something like:
ourLargeSystem[3].mySubSystem.mySubInt := 4;

This doesn't seem to work. I get an error that 'mySubSystem' is not an input of largeSystem.

Here's some pseudo-code. What I am doing wrong.

Thanks for any ideas. I must be missing something.
JP

GlobalVariables
ourLargeSystems : ARRRAY[1..10] OF largeSystem;
END Global Variables


FB largeSystem
VAR
_myInt : INT;
_myReal : REAL;
mySubSystem : subSystem

END_VAR
etc... with Methods and Properties



FB subSystem
VAR
_mySubInt : INT;
END_VAR
etc. with Methods and Properties


Top
   
PostPosted: Fri Apr 28, 2017 10:58 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 218
Your problem is scope of variables. Items defined as VARs of FBs are not available outside of the FB.


Top
   
PostPosted: Fri Apr 28, 2017 11:46 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 105
If you want to acces variables outside fb you habe to declare its as var_input.

But is a best practice to acces its via methotds (get set).


Top
   
PostPosted: Sat Apr 29, 2017 4:43 pm 
Offline

Joined: Thu Apr 23, 2015 4:51 pm
Posts: 26
For true OOP you should be able to make the new fb with the extends or implements setting and then also use the super command too see the following as a good example. https://infosys.beckhoff.com/english.ph ... 9.html&id=

Sent from my SM-N9005 using Tapatalk


Top
   
PostPosted: Wed May 10, 2017 9:55 pm 
Offline

Joined: Wed Oct 14, 2015 2:27 pm
Posts: 2
Josep M. Rams wrote:
If you want to acces variables outside fb you habe to declare its as var_input.

But is a best practice to acces its via methotds (get set).



Thank you. That was the issue. I plan to use the methods for the member instances, but I could not "see" the member methods and properties until I moved the variable to VAR_INPUT.

Thanks.
jcp :D


Top
   
PostPosted: Fri May 12, 2017 3:27 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 218
You can also define the object as a VAR in your function block and then create a property for your function block that returns a reference to the object. Only create the get - delete the set. You can then have access to the internal object's methods and properties.


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 6 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