Object ‘Method’

Symbol: 7e4507ebe4233ac0c0a8640e00a37b12_fa86424ae42c3199c0a8640e01338368

This object is used for object-oriented programming.

You insert the object below a function block or program in the Devices or POUs view. A method contains a sequence of instructions, but unlike a function it is not an independent POU and it must be assigned to a function block or program.

A method contains a declaration part and an implementation part.

You can use interfaces for the organization of methods.

Notes on methods

  • All data of a method are temporary data and are valid only during the execution of a method (stack variables). This means that CODESYS re-initializes all variables and function blocks that you have declared in a method each time the method is called.
  • Access to the variables of a function block instance or a program is permitted in the implementation part of a method.
  • Use the THIS pointer to point to the function block’s own instance.
  • You cannot access VAR_IN_OUT or VAR_TEMP variables of the function block in a method.
  • Methods that are defined in an interface may define only input, output and VAR_IN_OUT variables and may not contain any implementation.
  • Like functions, methods can be given additional outputs. You must assign these additional outputs in the method call.
Creating a new method
Return type Type of the value that is returned.
Implementation language Combo box for the implementation language for the method.
Access modifier

Combo box

  • PUBLIC: Corresponds to the specification of no access modifier.
  • PRIVATE: Access to the method is restricted to the function block or program. In this case, the object is identified by a symbol ( 7e4507ebe4233ac0c0a8640e00a37b12_d989b393c63eda05c0a8640e0153656a ).
  • PROTECTED: Access to the method is restricted to the program or the function block and its derivatives. In this case, the object is identified by a symbol ( 7e4507ebe4233ac0c0a8640e00a37b12_3f60b028c63f38c4c0a8640e00adcc7e ).
  • INTERNAL: Access to the method is restricted to the namespace (the library).

Attention

If you copy or shift a method from a POU to an interface, then CODESYS deletes the contained implementations automatically.

Note

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

Special methods for 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.

Properties and interface properties Each consists of a Set and/or a Get accessor method.

Monitoring for properties in online mode

The following pragmas are available for monitoring of properties in online mode. You insert them at the top position of the property definition:

  • {attribute 'monitoring:= 'variable'}: Each time the property is accessed, CODESYS saves the momentary value in a variable and displays the value of this variable. This value can become outdated if no further access to the property takes place in the code.
  • {attribute 'monitoring' := 'call'}: Each time the value is displayed, CODESYS calls the code of the Get accessor. If this code contains a side effect, then the monitoring executes the side effect.

You can monitor a property with the help of the following functions.

  • Inline monitoring

    Requirement: The option Activate inline monitoring is selected in the category Text editor of the Options dialog box.

  • Monitoring list

See also