A property in extension to the IEC 61131-3 is available as a means of object-oriented programming. It consists of a pair of accessor methods (Get, Set). They allow encapsulating a read or write access to variables declared inside of a POU or a GVL into a function call, while keeping the syntax of a variable access.
To insert a property as an object below a program, a function block, a GVL, or an interface node, select the node in the Applications tree, click the green plus button, and execute the command Property. As an alternative, right-click the node and execute the command Add Object > Property from the contextual menu.
In the Add Property dialog box specify the Name, Return Type, desired Implementation Language, and optionally an Access Specifier.
The same access specifiers are available as for methods:
oPUBLIC
oPRIVATE
oPROTECTED
oINTERNAL
NOTE: Properties can also be declared within interfaces.
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.
Get and Set Accessors of a Property
2 special methods, named accessor, are inserted automatically in the Applications tree below the property object. You can delete one of them if the property should only be used for writing or only for reading. An accessor, like a property (see previous paragraph), can get assigned an access modifier in the declaration part, or via the Add Object dialog box, when explicitly adding the accessor.
oThe Set accessor is called when the property is written.
oThe Get accessor is called when the property is read.
Example:
Function block FB1 has a property seconds that uses a local variable milli. This variable is determined by the properties Get and Set:
Get implementation example
seconds := milli / 1000;
Set implementation example
milli := seconds * 1000;
You can write the property of the function block (Set method), for example by fbinst.seconds := 22;.
(fbinst is the instance of FB1).
You can read the property of the function block (Get method) for example by testvar := fbinst.seconds;.
In the following example, property seconds is assigned to function block FB1:
A property can have additional local variables but no additional inputs and - in contrast to a function or method - no additional outputs.
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.
A property can be monitored in online mode either with help of inline monitoring or with help of a watch list. The precondition for monitoring a property is the addition of the pragma {attribute 'monitoring' := 'variable'} (refer to the chapter Attribute Monitoring) on top of its definition.