I'm using WAGO PLC PFC200 in my home automation project. I've plenty of POUs, each for one room. Each room implements IRoom interface and uses base POU for common logic like turning off all lights. For lights management, I'm using
I've solved it by declaring a FbLatchingRelay in the VAR RETAIN PERSISTENT area in my POU. But then after reading here that:
If you declare a local variable in a function block as RETAIN, CODESYS stores the complete instance of this function block in the Retain range (all data of the function block); however, only the declared RETAIN variable is treated as such.
I decided to change that in order not to waste RETAIN memory for a bunch of variables which are in POU but are not needed to be stored as RETAIN.
So right now I have something like that:
the VAR RETAIN PERSISTENT area is only declared in my main program
it stores structures for each room (each POU) only with needed data - FbLatchingRelay POU and few other variables
while initializing the room (POU) I'm passing those structures to my rooms using VAR_IN_OUT
each room (POU) uses then this data
VAR RETAIN PERSISTENT
Bathroom(PersistData := BathroomPersistentData, xMainLightSwitch := DI1_13, xMirrorLightSwitch := DI2_3, xMirrorLightSwitchActuator => DO2_1, xMainLightSwitchActuator => DO1_11);
Is this a good approach? What do you think?
It complicates project a bit but I'm not wasting RETAIN memory for things which should not be there (whole POUs).
I used to do it the way you've described. I now do it this way, which I've found easier.
FUNCTION BLOCK TEST_FB
Setpoints: SETPOINT_STRUCT; //all persistent variables
Then, within the PersistentVars variable list, go to "Declarations/Add all instance paths". The paths of all your persistent variables will be automatically created.
You asked about the whole function block being added to the retain memory area. I'm not sure what the manual means by this, but I have not found that to be the case. See this post, I never got an answer to this question: https://forge.codesys.com/forge/talk/Engineering/thread/fbd343d7ad/?limit=25#0473
I know about "Declarations/Add all instance paths" function but I was thinking that it will store the whole function block in the retain memory area. Just like it was written in the manual (https://help.codesys.com/api-content/2/codesys/184.108.40.206/en/_cds_vartypes_retain_persistent/).
I will try to do some tests just like you did in your post.
Log in to post a comment.