Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

How to make the output of a function blok persistent?

benbammens
2020-11-07
2020-11-09
  • benbammens - 2020-11-07

    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?

     
  • dFx

    dFx - 2020-11-09

    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.

     

Log in to post a comment.