Hi community,
"Could you please explain to me how the method FB_init works? The block inside it states, 'the retain variables are initialized (reset warm / reset cold).' Every time I perform a 'cold' reset on the PLC, do I need to call FB_init? Am I thinking correctly?"
Then I do that
METHOD FB_init : BOOLVAR_INPUT bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start) bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)END_VARgvl.x:=gvl.x+1;
Create main program
PROGRAM MAINVAR test: test;END_VARtest(y:=15);test(y:=16);
I'm currently performing a cold reset on the PLC, and the value of 'x' is supposed to increase. However, the value of 'x' remains unchanged at 1 all the time. The variable 'x' is of the PERSISTENT type so a cold reset of the PLC doesn't to have any impact on it.
Why can explain for me why that happen?
Last edit: sarunas 2023-08-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't find information. All information about fb_init method is there "You can declare additional function block inputs in an FBinit method. Then you have to set these inputs in the declaration of the function block instance." and show example.
So when fbinit of method is call.
Last edit: sarunas 2023-08-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are trying to make something very simple really complex, but my best guess is that the order of execution is:
- initialize FB (x becomes 1)
- Load persistent (x is 1)
- start application (x remains 1)
PS, It could also be that your "persistent" variables are not stored correctly and that, at startup, the value is always 0. Did you add this variable to the Persistent Variable list? And did you make sure that this works correctly on the device you are using?
So maybe the execution order is:
- load persistent (x is 0, because it was not stored correctly)
- initialize FB (x becomes 1)
- start application (x remains 1)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi community,
"Could you please explain to me how the method FB_init works? The block inside it states, 'the retain variables are initialized (reset warm / reset cold).' Every time I perform a 'cold' reset on the PLC, do I need to call FB_init? Am I thinking correctly?"
Then I do that
Create function block
Create FB_init of function block
Create main program
I'm currently performing a cold reset on the PLC, and the value of 'x' is supposed to increase. However, the value of 'x' remains unchanged at 1 all the time. The variable 'x' is of the PERSISTENT type so a cold reset of the PLC doesn't to have any impact on it.
Why can explain for me why that happen?
Last edit: sarunas 2023-08-16
Your anwsers are here: https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_method_fb_init_fb_reinit.html
I don't find information. All information about fb_init method is there "You can declare additional function block inputs in an FBinit method. Then you have to set these inputs in the declaration of the function block instance." and show example.
So when fbinit of method is call.
Last edit: sarunas 2023-08-16
You are trying to make something very simple really complex, but my best guess is that the order of execution is:
- initialize FB (x becomes 1)
- Load persistent (x is 1)
- start application (x remains 1)
PS, It could also be that your "persistent" variables are not stored correctly and that, at startup, the value is always 0. Did you add this variable to the Persistent Variable list? And did you make sure that this works correctly on the device you are using?
So maybe the execution order is:
- load persistent (x is 0, because it was not stored correctly)
- initialize FB (x becomes 1)
- start application (x remains 1)