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 added an interface property below an interface.

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

See also

Dialog Add property

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

Call: 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 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 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 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.

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 cannot contain any additional input variables or (as opposed to a function or method) output variables.

Example

FB

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 like an input parameter. When the Get accessor is called, the property is read. It is used like an output parameter. Access is restricted via access modifiers, 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

Access modifiers

  • 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.

  • 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 (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 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.

  • 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