Object ‘Method’

Symbol:

Keyword: METHOD

Methods are an extension of the IEC 61131-3 standard and a tool for object-oriented programming that is used for data encapsulation. A method contains a declaration and an implementation that includes a series of statements. However, unlike a function, a method is not an independent POU, and it is assigned to a function block or program. You can use interfaces for the organization of methods.

You can add a method below a program or a function block. Click Project ‣ Add object ‣ Method to open the Add method dialog.

Declaration:

Implementation:

Hint

If you copy a method below a POU and add it below an interface, or move the method, then the contained implementation is removed automatically.

See also

Dialog Add method

Function: Configures the method that is added by closing the dialog.

Call: Project ‣ Add object ‣ Method ; context menu

Requirement: A program (PRG) or a function block (FUNCTION_BLOCK) is selected in the POUs view or the Devices view.

Name Example: meth_DoIt
Return type

Default type or structured type of return value

Example: BOOL

Implementation language Example: Structured Text (ST)
Access specifier

Controls access to data.

  • PUBLIC or not specified: Access is not restricted.

  • PRIVATE: Access is restricted to the program, function block, or GVL.

    The object is marked as (private) in the POU or device view. The declaration contains the keyword PRIVATE.

  • PROTECTED: Access is restricted to the program, function block, or GVL with its derivations. The declaration contains the keyword PROTECTED.

    The object is marked as (protected) in the POU or device view.

  • INTERNAL: Access to the method is restricted to the namespace (library).

    The object is marked as (internal) in the POU or device view. The declaration contains the keyword INTERNAL.

Add Adds a new method below the selected object.

Special methods of a function block

FB_Init

Declarations are automatically implicit. Explicit declaration is also possible.

Contains initialization code for the function block, as is defined in the declaration part of the function block.

FB_Reinit Explicit declaration is necessary. After the instance of the function block is copied (as during an online change): calls and reinitializes the new instance module.
FB_Exit

Explicit declaration is necessary.

Call for each instance of the function block before a new download or a reset or during an online change for all shifted or deleted instances.

Attributes and interface attribute Provides Set and/or Get accessor methods.

See also

Input assistance when creating inheriting blocks

When you do object-oriented programming and want to use inheritance for blocks, you have the following support: When you insert a method, action, etc. below an inherited block, the Add Object dialog box includes a combo box with a list of methods, actions, etc. used in the base block. In this way, you can easily accept a method definition of the base and adapt it accordingly for the inherited method of the block. Methods and attributes with the PRIVATE access modifier are not available in this selection because they should not be inherited. When accepted into the inherited block, methods and attributes with the PUBLIC access modifier automatically have a blank access modifier field. (Functionally, this means the same thing.)

See also