Automatic reboot in case of error
Enable and disable error handling in CODESYS to log exception information and perform a restart of the controller or the runtime.
Please note that for the full functionality of the OnException function you need at least firmware version 3.2 .
The OnException function is preconfigured for powerIO devices and is recommended only for powerIO devices.
How can the controller be automatically restarted in case of an error?
The following article describes how an exception error can be logged during runtime and how the runtime or the device can be restarted in the exceptional state.
Description
That the controller on an exception without "emergency stop" (no kernel panic) of the system, the message is logged and a restart of the CODESYS runtime takes place. This is the "automatic soft reset in case of error".
That the controller on an exception with "emergency stop" (kernel panic) of the system, the message tries to log and a system restart takes place.
This is the "automatic hard reset in case of error"
Function description OnExceptionWrapper
In the start project "Empty" under the view POU there are the two functions
OnException and
OnExceptionWrapper
The OnExceptionWrapper, calls the OnException function with the specified settings.
OnException(
EventPrm:=EventPrm,
xDebug := FALSE,
xLogExceptionToFile:=TRUE,
xRestartRuntimeOnException := TRUE,
tExceptionFunctionTimeout := TIME#45S0MS
);Enable/disable the exception handling function
1. Click on "Task Configuration"

2. Click on "System Events"

3. Check if the "Exception" function already exists.

4. If present, check if it is "Active"

5. If not active, then activate it

Adding the exception handling function
If you want to add exception handling to an existing project, you can copy the two functions from the start project "Empty" and add the event task yourself.
To do this, proceed as described below:
1. Navigate to "Task Configuration"

2. Open the "System Events" tab

3. Click "Add Event Handler"

4. Select event type "Exception"

5. Enter exception name "OnExceptionWrapper"

6. Click "POUs"

7. Click "OK"

8. Switch the view to "POUs"

9. Open the function "OnExceptionWrapper (FUN)"

10. Configure the "OnException" function

Last updated

