# OPC-UA Agent for Legacy Programmable Logic Controllers +
## 2 Background
### OPC-UA for IEC 61131-3  
A PLC is a computing system for industrial control and automation and has been standardized by IEC 61131 [5]. A PLC replaces the hardware such as relays, timers, and counters in conventional control panels with software. It receives input from sensors, processes control logic, and transmits outputs to external devices such as motor drives. IEC 61131-3 defines the model of PLC software, and describes the software in terms of _configurations_, _resources_, _tasks_, and _program organization units_ (POUs) [19; 20; 21]. A configuration describes the hardware such as processors and memory and includes one or more resources. A resource can be considered to be a processing facility capable of executing PLC programs. A resource may contain one or more tasks, where a task controls the execution of a _program_ and/or a set of _function_ and _function blocks_. A task can be executed periodically or when a specified trigger, such as a variable change, occurs. A POU is the basic building block that contains data structures and algorithms. It can be a program, a function, or a function block. Generally, a program consists of functions and function blocks that pass data arguments. The specification of OPC-UA for IEC 61131-3 defines server and client technologies for enabling OPC-UA communication in PLC software [7; 8]. It explains the information model to describe the IEC 61131-3 software architecture and defines important object types that represent tasks, configurations, resources, and POUs. The OPC-UA client specification defines IEC 61131-3-compliant function blocks that allow PLC software to act as an OPC-UA client and communicate with external OPC-UA servers. These technologies enable the platform-independent, scalable, and secure communication of PLCs in industrial automation. Figure 1 shows the OPC-UA information model for PLCs and depicts the main object types and their relationships. The IEC 61131-3 object types derive from OPC-UA core and device integration (DI)-level object types and include CtrlTaskType, CtrlConfigurationType, CtrlResourceType, and CtrlProgramOrganizationUnitType. The CtrlTaskType object type defines a PLC task with an execution cycle (Interval), scheduler priority (Priority), and trigger event (Single). When a trigger event is set, the task runs on the rising edge of the event regardless of its period. CtrlConfigurationType represents the PLC configuration and includes global variables (GlobalVars) and resources (Resources). CtrlResourceType expresses PLC resource information. It includes global variables, task information (Tasks), and programs (Programs). CtrlProgramOrganizationUnitType defines a POU and represents a program (CtrlProgramType) or function block (CtrlFunctionBlockType). Each object can have an input variable (InputVar), an output variable (OutputVar), or an input and output variable (InOutVar). Relationships between objects are defined by the reference types HasSubType or HasComponent, which represent derivation and containment relationships, respectively. The application-level objects are defined based on the object types. The client function blocks support essential OPC-UA services, including service discovery, attributes, methods, monitored items, and subscription services. The function blocks for IEC 61131-3 are summarized in Table 1. The function blocks differ from the original OPC-UA API in that they use handles when nodes need to be specified for read and write operations. Taking UA_ReadList as an example, Figure 2 shows a diagram  
The use case of function blocks when using UA_ReadList or UA_WriteList to access data on a remote server is shown in Figure 2[8]. The PLC software first calls UA_Connect to connect to the server and open an OPC-UA session. If it needs the information model, it uses UA_NamespaceGetIndexList to read the namespace, and it calls UA_NodeGetHandleList with the node ID as an argument to acquire the handle of the node to read or write.