Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Plant SCADA

Defensive Programming

  • Last UpdatedJul 18, 2023
  • 2 minute read

Defensive programming is an approach to improve software and source code. It aims to improve general quality by reducing the number of software bugs. It promotes making the source code readable and understandable. It aims to make your code behave in a predictable manner despite unexpected input or user actions.

You should try to:

  • Verify that your code does not produce unexplained hardware alarms.

  • Check that denominators in division are not zero.

  • Check that array indexes cannot go out of range.

  • Check that arguments from external sources are valid.

  • Check that loop terminations are obvious and achievable.

  • Only write code once. If you find that two sections of code look identical or almost identical it is worth spending the time to re-write or re-design it. This will generally reduce the size of the code in question by a third or more, which reduces complexity and therefore maintenance and debugging time. An effective method to achieve this is to convert the identical code to a new function.

  • Do not access the module data in any function other than the member functions.

  • Write the member functions whenever an array is defined. Do not try to pass arrays between functions, make the arrays the centre piece of the object.

  • Cicode is a multitasking language. Several tasks (commands, expressions and tasks created by TaskNew function) can be executed concurrently. This powerful feature of Cicode should be used with care as some of the functions may be modifying module data. It is essential that the number of tasks running at any point in time be minimized. This may require the use of semaphores to help protect the module data from interference and corruption. (For the use of semaphores, refer to SemOpen, SemClose, SemSignal and SemWait functions in on-line help or the Cicode Reference manual).

UNINTENDED EQUIPMENT OPERATION

  • Write your Cicode programs with the minimum number of concurrent instructions suitable to your application.

  • Use semaphores or some related means to coordinate program flow if your program will execute a high number of concurrent instructions.

    Failure to follow these instructions can result in death, serious injury, or equipment damage.

See Also

Using Cicode Programming Standards

Modular Programming

Function Error Handling

TitleResults for “How to create a CRG?”Also Available in