I use a PFC200 with codesys for my home automation. I would like the light outputs to be persistent since it is a pain in the b... that every time when I re-upload the program or restart the PLC the lights go out...
I use push buttons an a toggle function block to control the lights. I have made the final output variable persistent, but when the program starts, the output "Q" of the toggle FB gets reset ofcourse and the light is switched off.
I have tried to define the entire block as retain variable but this does not seem to work. I cannot define the "Q" as retained in my POU since it is part of the FB...
Using an inout variable will suit your requirements.
More generally, if you need to know the previous state of an output variable, then it should be an inout. Inout refers to variables you want to read and write.
Just define the inout variable as persistent.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I use a PFC200 with codesys for my home automation. I would like the light outputs to be persistent since it is a pain in the b... that every time when I re-upload the program or restart the PLC the lights go out...
I use push buttons an a toggle function block to control the lights. I have made the final output variable persistent, but when the program starts, the output "Q" of the toggle FB gets reset ofcourse and the light is switched off.
I have tried to define the entire block as retain variable but this does not seem to work. I cannot define the "Q" as retained in my POU since it is part of the FB...
Is there an easy way to set this up?
Using an inout variable will suit your requirements.
More generally, if you need to know the previous state of an output variable, then it should be an inout. Inout refers to variables you want to read and write.
Just define the inout variable as persistent.