infoAutomatic restart in case of error

Enable and disable error handling in CODESYS to log information about an exception and perform a restart of the controller or the runtime.

circle-exclamation

How can the controller be automatically restarted in case of an error?

The following article describes the function of 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 attempts to log and a restart of the system occurs.

    This is the “automatic hard reset in case of error”

Function description OnExceptionWrapper

In the start project "Empty" are located under the view POU the two functions

  • OnException and

  • OnExceptionWrapper

The feature 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 is already present.

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 function "OnExceptionWrapper (FUN)"

10. Configure "OnException" function

Last updated