I wonder if there is a way to trigger the Init and Exit routine with user program?
Basically, I’m trying to use the program to do the thing that normally will get triggered if you download to the PLC with “Execute Exit/Init routines” ticked.
I tried the system function ST_tmp_suspend() and ST_tmp_resume() but it seems these functions will only stop and start the POU’s cyclic program without going through the Init and Exit routine.
Move your code in the Exit section to an Action and call that in the Exit routine. You can then create a conditional call to the same Action anywhere in your cyclic code to run the same code lines.
One thing to remember is that during Init and Exit routines the Cycle time monitoring is not active and some function blocks, which are normally acyclic work in a cyclic manner. If you are doing something that takes a lot of CPU time, you could run into problems in the Cyclic portion.
You can use RTCyclic(), RTInit() and RTExit() to change the behaviour of your action if some adjustments are necessary to handle the differences.
Unfortunately, this approach doesn’t serve my purpose. I am looking for a way to run through the Init and Exit process of a POU without rebooting the PLC. If I can run the program currently written in Init and Exit routine in a cyclic task, I don’t need to seek a solution anymore.
I’m pretty sure there’s no way to start / execute INIT and EXIT from user code, sorry.
INIT is only executed once while bootup or download (if configured), EXIT is only executed when the task is deleted from the PLC because of a download happening (if configured).