Functions

Define functions in the Functions section of a controller in the . Program functions with Function Block Diagram (FBD), Ladder Diagram (LD), or Structured Text (ST).
For functions, specify these properties:
Function Properties
Properties
Description
Code Generation
Generate Debug Info
Generate information required for debugging with step-by-step execution.
Info
Comment
Plain text
Description
Rich text
Full Name
(Read-only) Full name of the function with the project and controller to which it belongs
Language
(Read-only) Programming language of the program organization unit (POU)
Name
(Read-only) Name of the function. Function names are limited to 128 characters beginning with a letter followed by letters, digits, and single underscores. The last character for a function name must be a letter or digit; function names cannot end with an underscore character. Reserved words, defined words, or data types, such as elementary, structures, or arrays are not valid names. The same type of elements within a scope must have unique names.
Order
Execution order of the POU
Password Protected
(Read-only) Password controls access to the function
Path
(Read-only) Complete path to the function files on the computer
When adding functions, define required parameters. Functions can have a maximum of 128 parameters (inputs and outputs). When defining parameters, consider the following limitations:
  • Parameter names are limited to 128 characters beginning with a letter followed by letters, digits, and single underscores. The last character for a parameter name must be a letter or digit; parameter names cannot end with an underscore character. Reserved words, defined words, or data types such as, elementary, structures, or arrays, are not valid names. Use unique names for the same type of elements within a scope.
  • Possible data types for parameters are BOOL, SINT, USINT, BYTE, INT, UINT, WORD, DINT, UDINT, DWORD, LINT, ULINT, LWORD, REAL, LREAL, TIME, DATE, STRING, Array types, Structure types, Function blocks
  • For String type variables, string capacity is limited to 255 characters excluding the terminating null character (0), a byte for the current length of the string, and a byte for the maximum length of the string
  • For user defined addresses, the format is hexadecimal and the value ranges from 1 to FFFF
  • For dimensions, example: [1..10] for a one dimensional array, [1..4,1..7] for a two dimensional array
Perform these tasks for functions:
Function Tasks
Task
Procedure
Add a function
  1. In the , right-click the
    Functions
    element, point to
    Add Functions
    , and then select the programming language for the function.
  2. To define the parameters for the function, right-click the function, and then select
    Parameters
    .
Export a function
Export functions as exchange files (*.pxf). Also export functions from libraries.
  1. In the , right-click the function, and then select
    Export...
    .
  2. In the dialog box, browse for the location in which to store the function exchange file, and then select
    Save
    .
    TIP: If a user-defined structure contains user-defined structures, create at least one variable for each user-defined structure to support a successful POU export.
Add a function from an exchange file
Import functions previously saved as exchange files (*.pxf).
TIP: For POUs in version control, check out the POU before importing the exchange file (*.pxf).
  1. In the , right-click the
    Functions
    element, point to
    Add Functions
    , and then select
    Existing Function...
    .
  2. In the dialog box, locate the exchange file containing the function, and then select
    Open
    .
  3. In the dialog box, select the element to import, and then select
    Import
    .
Set properties for a function
In the , right-click the function, and then select
Properties
.
Copy and paste a function
  1. In the , right-click the function, and then select
    Copy
    .
  2. Right-click the
    Function
    element, and then select
    Paste
    .
Rename a function
In the , right-click the function, then select
Rename
, and then type a name for the function.
Delete a function
In the , right-click the function, and then select
Delete
.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal