Object ‘Interface property’

Symbol: b77e7927c672813ec0a8640e002bebd1_5852137bc678be91c0a8640e005e2dcc

An interface property is a means of object-oriented programming. You add the object to an interface in the device tree in order to extend the description of the interface with the accessor methods Get and/or Set. The interface property contains no implementation code for the accessor methods. If you delete the Set accessor, then only a read access to the property exists, no write access.

The Get accessor is for the read access to the property.

The Set accessor is for the write access to the property.

If the property has no Get and/or Set, add this accessor to the interface property with the command Add object.

Note

If you extend a function block or a program with an interface containing properties, CODESYS automatically inserts them and their associated Get and/or Set accessors below the POU in the device tree. Subsequently, you can implement the code in the Get and/or Set accessors.

Example

../_images/13086c33c21e14dfc0a8640e00e00a19

The interface ITF has the property Prop1 with the accessor methods Get and Set. The Get accessor’s task is to read the name of some object from a function block that implements the interface. The Set accessor is used to write this name into this function block. You cannot edit either of the methods within the interface definition, but you can do so later on in the function block.

The function blocks FB1 and FB2 each implement the interface ITF: Therefore, CODESYS has automatically inserted the property Prop1 with the Get and Set methods below FB1 and FB2. At this point you can edit the accessor methods, for example so that the variable sVar1 is read and you obtain the name of an object. In FB2, which implements the same interface ITF, you can implement code in the Get method, which then returns the name of another object . You use the Set method to write the name supplied by the program PLC_PRG ('abc') to the function block FB2.

Two function blocks that implement the same interface ITF:

FUNCTION_BLOCK FB1 IMPLEMENTS ITF
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
sVar1: STRING:='xy1';
END_VAR


FUNCTION_BLOCK FB2 IMPLEMENTS ITF
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
sVar2: STRING:='xy2';
name_got_from_PLC_PRG: STRING;
END_VAR

Implementation of code in the accessor methods Get and Set underneath the two function blocks FB1 and FB2:

FB1.Get
VAR
END_VAR
name := sVar1;

FB2.Get
VAR
END_VAR
name := sVar2;

FB2.Set
VAR
END_VAR

Access to the function blocks via the program PLC_PRG

PROGRAM PLC_PRG
VAR
FB1_inst: FB1;
FB2_inst: FB2;
namexy1: STRING;
namexy2: STRING;
END_VAR

//get name out of fb
namexy1:=FB1_inst.Name;
namexy2:=FB2_inst.Name;
//write name to fb
FB2_inst.Name:='abc';

See also