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 Sun Aug 18, 2019 6:16 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Jul 08, 2019 3:02 pm 
Offline

Joined: Thu Jun 13, 2019 9:38 am
Posts: 4
Hey,

I'm struggling with the properties of a FunctionBlock in CODESYS V3.5.

I have a FB A, which instances two different FBs B and C.
Now I want to change a property from FB B in FB C.

The error message says, that the FB B is not an entry of FB A.

If I write my own setter-method in FB B for the property and call it in the FB C it works and I don't get an error message.

Can anybody explain why I'm able to call a function from the other FB but not a property?

Thank you for your help!

Fabian


Top
   
PostPosted: Mon Jul 08, 2019 7:00 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 304
Are you giving FB_C a reference to FB_A's instance of FB_B?

FB_C knows nothing about FB_B, unless you define an FB_B instance in FB_C. But, since you want to have FB_C specifically affect FB_A's instance of FB_B, then you need to setup FB_C to have a REFERENCE TO FB_B, instead of it's own instance of FB_B.

Silly example:

Create FB_B with a simple Property that maps to a local variable...

Code:
FUNCTION_BLOCK FB_B
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
   _Local : BOOL;
END_VAR

PROPERTY Prop1 : BOOL

Get routine:
Prop1 := _Local;

Set routine:
_Local := Prop1;



Now setup FB_C so it can take somebody else's instance (aka REFERENCE TO FB_B). You could also do POINTER TO FB_B or use an interface... I will use REFERENCE TO...

Here, FB_C will set FB_B's property "Prop1" to match "DoIt".

Code:
FUNCTION_BLOCK FB_C
VAR_INPUT
   DoIt : BOOL;
   refB : REFERENCE TO FB_B;
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR

refB.Prop1 := DoIt;



Now create FB_A that creates instances of both FB_B and FB_C and does something really silly...

Code:
FUNCTION_BLOCK FB_A
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
   MyB : FB_B;
   MyC : FB_C;
   Count : INT;
END_VAR

Count := Count + 1;
IF Count > 20 THEN
   Count := 0;
END_IF
IF Count >= 10 THEN
   MyC(DoIt:=TRUE, refB:=MyB);
ELSE
   MyC(DoIt:=FALSE, refB:=MyB);
END_IF


And call FB_A from PLC_PRG...

Code:
PROGRAM PLC_PRG
VAR
   MyA : FB_A;
END_VAR

MyA();

_________________
Scott Cunningham
KEB America, Inc.
www.kebblog.com
www.kebamerica.com


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 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