Object ‘Property’

Symbol:

Keyword: PROPERTY

Properties are an extension of the IEC 61131-3 standard and a tool for object-oriented programming. Properties are used for data encapsulation because they allow for external access to data and act as filters at the same time. For this purpose, a property provides the accessor methods Get and Set which allows for read and write access to the data of the instance below the property.

You can add a property with accessor methods below a program, a function block, or a global variable list. Click Project ‣ Add Object ‣ Property to open the Add Property dialog.

Note

You can add an interface property below an interface.

When you copy a property that is inserted below a POU and add it below an interface, or if you move the property there, the included implementations are removed automatically.

See also

Dialog ‘Add Property’

Function: Creates a new property below the selected POU when the dialog is closed.

Call: Menu bar: Project ‣ Add Object ‣ Property ; context menu

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

Name Name (identifier) of the property
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 unspecified 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 object is marked as (protected) in the POU or device view. The declaration contains the keyword PROTECTED.

INTERNAL

Access is restricted to the namespace (library).

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

   
Abstract : Identifies that the property does not have an implementation and the implementation is provided by the derived FB
Add

Adds a new property be low the selected object and below that the accessor methods Get and Set

Note: When you select a property, you can also add a previously removed accessor explicitly by clicking Add Object.

Editor ‘Property’

You can program the data access in the editor. The code can contain additional local variables. However, it must not contain any additional input variables or (as opposed to a function or method) output variables.

Example

Function block

FUNCTION_BLOCK fb_A
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
        iA : INT;
        iB : INT;
END_VAR

iA := iA + 1;

Property Value_A

PROPERTY PUBLIC Value_A : INT

Accessor method fb_A.Value_A.Get

VAR
END_VAR
Value_A := iA;

Accessor method fb_A.Value_A.Set

VAR
END_VAR
iB := Value_A;

Get and Set accessors

When the Set accessor is called, the property is written. It is then used in the same way as an input parameter. When the Get accessor is called, the property is read. It is then used in the same way as an output parameter. Access is restricted by means of access specifiers, and the objects are marked accordingly.

When a property is accessed as read only or write only, you can delete the unneeded accessors.

You can add accessors explicitly by selecting a property and clicking Add Object. A dialog opens, either Add Get Accessor or Add Set Accessor. There you can set the implementation language and the access.

Dialog Add Get (Set) Accessor
Implementation language Example: Structured Text (ST)
   
Access specifier  
PUBLIC or unspecified 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.

PROTECTED

Access to the property is restricted to the program, function block, or GVL and its derivations. The declaration contains the keyword.

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

INTERNAL

Access to the method is restricted to the namespace (the library).

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

   
Add Adds the accessor methods Get or Set below the selected property.

Monitoring of properties in online mode

The following pragmas are provided for the 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 actual value to a variable and displays the value of this variable. This value can become outdated if no more 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 Enable inline monitoring option is selected in the Text Editor category of the Options dialog.

  • Watch list

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