Hi all,
I’m looking for an example or best practice on how to implement in user defined Function Block (FB) in B&R Automation Studio (IEC 61131-3 Structured Text) that resets the selected BOOL variables to FALSE during a Cold Restart or Warm Restart of the PLC. As we need some other variables in the same structure datatype to be in RETAIN mode, during Warm restart. So for that in Application we enabled, RETAIN.
Specifically, I’d like to:
If possible, could someone share a short Structured Text example or snippet that shows how this is typically done in B&R projects?
Thanks in advance for your guidance!
Chandrasekhar RK
Hi,
I haven’t implemented such a functionality so far, so I can’t provide a example.
But I think you need to identify, if your code is running inside a INIT program, and if the INIT reason is a cold- or warmstart (but not a program transfer).
As a function block is not running itself in the cyclic context but is always called by a task, the call of the function block also has to be done in the INIT program of a task (because the init reason can’t deliver any time context when the last action happened).
Both information, if running in a INIT program and if the INIT reason was a restart, can be gathered by two function blocks in the BRSystem library:
- RTinit() to determine if the call was done inside a INIT program
- RTInfo() to determine the last init reason (FB output .init_reason)
So, combining those both informations inside a function block, and calling this function block inside the INIT of a task could be worth a try.
Best regards!
Did a simple test just as example, should work like described.
I implemented a FB using the named functions:
Called the FB in the INIT of a program:
Here’s the output when INIT was triggered by warm restart …
… or when triggered by download …
… or when called in cyclic instead of init.
Finally, here’s the library with the test code from this example.
RebootChck.zip (1.9 KB)
3 Likes
Thank you for sharing. We got the idea how to proceed.
1 Like