4 General information to IEC 61131-3 and OPC UA ToC Previous Next

4.3 Introductory Example ToC Previous Next

A simple example shall be used to explain how the above introduced OPC UA concepts are used to represent elements in an OPC UA Server.

According to IEC 61131-3, Ctrl Function Blocks consist of a name, Ctrl Variables with associated data types (input, output, internal), and a body containing the algorithm to be executed. These data are represented by OPC UA ObjectTypes derived from the ObjectType CtrlFunctionBlockType (see Figure 11).

To start, IEC 61131-3 requires a Ctrl Function Block type declaration. Here an integer up-counter is used which follows the standard counter Ctrl Function Block. CTU_INT contains three input Ctrl Variables (CU – counter up, R – reset, PV – primary value), one local Ctrl Variable (PVmax) and two output Ctrl Variables (Q, CV – counter value) with their respective data types. Furthermore, CTU_INT has a body containing the algorithm to do the actual counting. The formal declaration of CTU_INT using the Structured Text programming language is shown in Figure 9.


Figure 9 – Ctrl Function Block CTU_INT declaration

The OPC UA representation of CTU_INT is shown in Figure 11. The ObjectType CTU_INT is a subtype of the ObjectType CtrlFunctionBlockType. Its components are defined by instance declaration and referenced by HasInputVar, HasLocalVar, and HasOutputVar References.

After declaration of CTU_INT it is instantiated twice (MyCounter, MyCounter2) and used within a Ctrl Program MyTestProgram shown in Figure 10. Signal and Signal 2 are counted, the Ctrl Function Block output Ctrl Variables are transferred to some temporary Ctrl Variables but are not further processed in this example.


Figure 10 – Ctrl Function Block MyCounter / MyCounter2 instantiation and usage

The OPC UA representation of the Objects MyCounter and MyCounter2 is shown in Figure 11. The Objects are instances of the ObjectType CTU_INT which is indicated by the HasTypeDefinition References. The example specific ObjectType CTU_INT is derived from the ObjectType CtrlFunctionBlockType which is indicated by the HasSubType Reference. Current values at a certain point in time are provided by the instances, e. g. the current counter value of MyCounter equals 11. The Ctrl Program MyTestProgram is not represented in the figure.


Figure 11 – Introductory Example – OPC UA representation

Previous Next