EcoStruxure Machine Expert version 1.1 does not support the M258, LMC058 and LMC078 controllers.

Method

Overview

A method is a language element similar to a function that can be used in a context of a function block. It can be regarded as a function which contains an instance of the respective function block. Such as a function, a method has a return value, and its own declaration part for temporary variables and parameters.

Also as a means of object-oriented programming, you can use interfaces to organize the methods available in a project.

NOTE: When copying or moving a method or property from a POU to an interface, the contained implementations are deleted automatically. When copying or moving from an interface to a POU, you are requested to specify the desired implementation language.

Inserting a Method

To assign a method to a function block or interface, select the appropriate function block or interface node in the Applications tree, click the green plus button and execute the command Method. Alternatively, you can right-click the function block or interface node and execute the command Add Object > Method from the contextual menu.

In the Add Method dialog box, enter a Name, the desired Return Type, the Implementation Language, and the Access Specifier (see below). For choosing the return data type, click the button ... to open the Input Assistant... dialog box.

Access specifier: For compatibility reasons, access specifiers are optional. The specifier PUBLIC is available as an equivalent for having set no specifier.

Alternatively, choose one of the options from the selection list:

oPRIVATE: The access on the method is restricted to the function block.

oPROTECTED: The access on the method is restricted to the function block and its derivation.

oINTERNAL: The access on the method is restricted to the present namespace (the library).

Click Open to confirm. The method editor view opens.

Input Assistance when Creating Inheriting Function Blocks

EcoStruxure Machine Expert facilitates object-oriented programming using inheritance within function blocks: When you execute Add Object on a function block that inherits from another function block, the Action, Method, Property, and Transition elements used in the base function block are listed for selection:

oAction, Method, Property, and Transition elements with Access specifier = PUBLIC, PROTECTED, and INTERNAL defined in the base function block are available for selection. You can adapt the definition for the inherited object. In the inherited object, the same Access specifier is assigned as to the source elements.

oAction, Method, Property, and Transition elements with Access specifier = PRIVATE are not available for selection because access is restricted to the base function block.

Declaring a Method

Syntax:

METHOD <access specifier> <method name> : <return data type>VAR_INPUT  ... END_VAR

For a description on how to declare interface handling methods, refer to the Interface chapter.

Calling a Method

Method calls are also named virtual function calls. For further information, refer to the chapter Method Invocation.

Note the following for calling a method:

oThe data of a method is temporary and only valid during the execution of the method (stack variables). This means that the variables and function blocks declared in a method are reinitialized at each call of the method.

oMethods defined in an interface are only allowed to have input, output, and input/output variables, but no body (implementation part).

oMethods such as functions can have additional outputs. They must be assigned during method invocation.

Implementing a Method

Note the following for implementing a method:

oIn the body of a method, access to the function block instance variables is allowed.

oIf necessary, use the THIS pointer which always points on the present instance.

oVAR_TEMP variables of the function block cannot be accessed in a method.

Special Methods for a Function Block

Method

Description

Init

A method named FB_init is by default declared implicitly, but can also be declared explicitly. It contains initialization code for the function block as declared in the declaration part of the function block. Refer to FB_init method.

Reinit

If a method named FB_reinit is declared for a function block instance, it is called after the instance has been copied (like during Online Change) and will reinitialize the new instance module. Refer to FB_init, FB_reinit methods.

Exit

If an exit method named FB_exit is desired, it has to be declared explicitly. There is no implicit declaration. The Exit method is called for each instance of the function block before a new download, a reset or during online change for all moved or deleted instances. Refer to FB_exit method.

Properties and interface properties each consist of a Set and/or a Get accessor method.

Method Call Also When Application Is Stopped

In the device description file, it can be defined that a certain method should always be called task-cyclically by a certain function block instance (of a library module). If this method has the following input parameters, it is processed also when the active application is not running.

Example

VAR_INPUT
pTaskInfo : POINTER TO DWORD;
pApplicationInfo: POINTER TO _IMPLICIT_APPLICATION_INFO;
END_VAR

The programmer can check the application status via pApplicationInfo, and can define what should happen.

IF pApplicationInfo^.state = RUNNING THEN <instructions> END_IF