The compiler enables you to write your own exception programs for handling particular system events. The following exceptions can be handled:

  • Startup (before the first cycle)
  • Shutdown (after the last cycle)
  • Division by zero

Startup

You can write your own exception program to be executed before the first application cycle is executed:

  1. Create a new main program that will handle the exception. It cannot be a SFC program.
  2. In the editor of global defines, insert the following line:

 

#OnStartup ProgramName

 

attentionAttention

The program is executed before all other programs within the fisrt cycle. This implies that the cycle timing may be longer during the first cycle. You cannot put breakpoints in the Startup program.

Shutdown

You can write your own exception program to be executed after the last application cycle when the Runtime Service system is cleanly stopped:

  1. Create a new main program that will handle the exception. It cannot be a SFC program.
  2. In the editor of global defines, insert the following line:

 

#OnShutdown ProgramName

attentionAttention

You cannot put breakpoints in the Shutdown program.

Division by zero

You can write your own exception program for handling the "Division by zero" exception. Below is  the procedure you must follow for setting an exception handler:

  1. Create a new sub-program without any parameter that will handle the exception
  2. In the editor of global defines, insert the following line:

 

#OnDivZero SubProgramName

 

In the sub-program that handles the exception you can perform any safety or trace operation. You then have the selection between the following possibilities:

  • Return without any special call. In that case the standard handling will be performed: a system error message is generated, the result of the division is replaced by a maximum value and the application continues.
  • Call the FatalStop function. The Runtime Service then stops immediately in Fatal Error mode.
  • Call the CycleStop function. The Runtime Service finishes the current program and then turns in cycle setting mode.

Handlers can also be used in DEBUG mode for tracking the bad operation. Just put a breakpoint in your handler. When stopped, the call stack will show you the location of the division in the source code of the program.

Array index out of bounds

You can write your own exception program for handling the "Array index out of bounds" exception. Below is  the procedure you must follow for setting an exception handler:

  1. Create a new sub-program without any parameter that will handle the exception
  2. In the editor of global defines, insert the following line:

#OnBadArrayIndex SubProgramName

Note: this is anyway a fatal error. If the "Check array bounds" compiling option is set, the Runtime Service goes in "fatal error" mode after calling your sub-program.

Pragmas to add texts for Messages, Warnings and Errors in the build report

The compiler supports the following pragmas to add textlines:

Parameters

Description

#message text line

Adds the line text to the build report.

#warning text line

Adds the line text to the build report and treats it as a warning.

#error text line

Adds the line text to the build report and treats it as an error text.

Hint: For a message to be colored in red, the text must contain a “:” character.

Example:

#ifdef CONFIG ONE

…

#else

#ifdef CONFIG_TWO

…

#else

#error You must define a configuration (ONE or TWO) for compiling

#endif

#endif

Handling exceptions

IEC 61131-3 Automation platform > Programming - Reference guide > Handling exceptions

Previous chapterNext chapter


Created with the Personal Edition of HelpNDoc: Keep Your Sensitive PDFs Safe with These Easy Security Measures