Programming guideline
In the following you find the minimum requirements that you must observe and implement when programming your library.
🗹 Naming the library |
Using several libraries within one project can cause problems if they do not have a unique name. Phoenix Contact recommends to include the library version number in the name.
Example: Modbus_RTU_3 |
||||||||||||||||||||
🗹 Naming function blocks and functions |
Using several libraries within one project can cause problems if they do not have a unique ID.
Example: MB_RTU_Master_5 |
||||||||||||||||||||
🗹 Checking input parameter validity |
To avoid unexpected program behavior, the value ranges of the input paramters must be checked.
Possible actions:
Example: (* arrBuffer is ARRAY[1..512] *) |
||||||||||||||||||||
🗹 Checking the field limits |
To avoid unexpected program behavior, you must check the field limits.
Example: (* arrBuffer is ARRAY[1..512] *) |
||||||||||||||||||||
🗹 Input and outputs |
Naming of inputs and outputs The user finds his way around more quickly if the names of the inputs and outputs are the same as the function behind them.
Comments for inputs, outputs and inouts If the inputs, outputs and inouts are commented, the user can understand the function faster by reading the comments.
Required inputs and outputs
|
||||||||||||||||||||
🗹 Library ID for global variables and user-defined data types |
To avoid conflicts when using several libraries that use global variables and/or user-defined data types, the names of the global variables and user-defined data types in libraries must start with the library ID. Syntax for global variables: <LIB_ID>_<Variable name> Syntax for user-defined data types: <LIB_ID>_<data type name>
Example for a global variable: MB_iCounter Example for a user-defined data type: MB_ARR_W_1_100 : ARRAY[1..100] OF WORD; |
||||||||||||||||||||
🗹 Software compilations without warnings |
Warnings are always indications of potential errors that can only occur in specific runtime configurations. Therefore, all warnings must be eliminated prior to software release.
|
||||||||||||||||||||
🗹 Spaces between keywords, operators and operands |
In extended identifiers, the use of some operand symbols is permitted. To avoid problems with the use of extended identifiers and to improve readability, spaces should be used to separate keywords, operators and operands.
Example: iTemp3 := iTemp1 + iTemp2; Negative Example: iTemp3 := iTemp1+iTemp2; |
→ Next step: Testing a Library
Or go back to Overview.
• Published/reviewed: 2024-11-21 • Revision 17 •