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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2019-07-08
Originally created by: scott_cunningham
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...
FUNCTION_BLOCKFB_BVAR_INPUTEND_VARVAR_OUTPUTEND_VARVARÂ Â _Local:BOOL;END_VARPROPERTYProp1:BOOLGetroutine:Prop1:=_Local;Setroutine:_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".
FUNCTION_BLOCKFB_CVAR_INPUTÂ Â DoIt:BOOL;Â Â refB:REFERENCETOFB_B;END_VARVAR_OUTPUTEND_VARVAREND_VARrefB.Prop1:=DoIt;
Now create FB_A that creates instances of both FB_B and FB_C and does something really silly...
FUNCTION_BLOCKFB_AVAR_INPUTEND_VARVAR_OUTPUTEND_VARVAR
  MyB : FB_B;
  MyC : FB_C;
  Count : INT;END_VARCount :=Count+1;IFCount>20THEN
  Count :=0;END_IFIFCount>=10THEN
  MyC(DoIt:=TRUE, refB:=MyB);ELSE
  MyC(DoIt:=FALSE, refB:=MyB);END_IF
And call FB_A from PLC_PRG...
PROGRAMPLC_PRGVARÂ Â MyA:FB_A;END_VARMyA();
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
Originally created by: scott_cunningham
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...
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".
Now create FB_A that creates instances of both FB_B and FB_C and does something really silly...
And call FB_A from PLC_PRG...