In the event that you are working on an PAM application and are concerned that one or more functions in your code could return an invalid result and throw the PAC into an error state, there is a fairly simple way to prevent the PAC from crashing and handle the exception. This can be done using POUs for implicit checks.
The selected POUs will be executed any time the relevant operation is called, do note that this may cause POU slowdown because of this.
- For instance, a divide operation where the divisor is a REAL set to zero will call CheckDivReal. Note that division checks for DINT also apply to smaller integer datatypes like INT and USINT through implicit type conversion.
- Checks are also available for array boundaries, ensuring the application never tries to read or write to an array location that is beyond its boundaries (for instance, location 30 of a 20-index array).
- Range checking is also available, but this only applies to integer datatypes declared to use less than their typically available data range. For instance, the variable declaration MyInt : INT (-100..100); creates an integer that rolls over at 100 and -100. This is useful for creating integers with built-in modulo functions. The range check POU can cap such values at their specified maxima and minima.
- There is also a POU to check pointers. Pointers are likely sources of spontaneous errors because they can point to any memory location. If the programmer is not careful, they may point to a memory location that is outside of the PAC runtime memory structure or point to a location with restricted access. Unfortunately, there is no standard way to check for pointer access violations and no standard way to correct them. It is therefore up to the programmer to either develop a way to check/correct pointers in the implicit POU or to root out any pointer bugs in development.