Communication method and device based on CODESYS OPC UA composite data type

By automatically identifying and generating OPCUA address space nodes, the automatic mapping and overall reading and writing of composite data type variables in the CODESYS project are realized, solving the problem of manual configuration and improving configuration and transmission efficiency, while ensuring the accuracy and consistency of data reading and writing.

CN123164172APending Publication Date: 2026-11-24ZHONGKE TIMES (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611655620.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-26
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

In existing technologies, complex data type variables in CODESYS projects need to be manually disassembled and configured, making it impossible to read and write them as a whole and lacking consistency verification. This results in a large workload for configuration, a high risk of errors, and low data transmission efficiency.

Method used

By automatically identifying composite data type variables in the CODESYS project that have been marked with OPCUA mapping, the system automatically generates OPCUA address space nodes and unique node identification information, and establishes mapping relationships to achieve overall read/write and consistency verification, including automatic node mapping and overall read/write of complex data types such as arrays and structures.

Benefits of technology

It improves configuration and transmission efficiency, reduces human configuration errors, ensures the accuracy and consistency of data reading and writing, and adapts to the interaction needs of batch data and structured data in industrial settings.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123164172A_ABST
    Figure CN123164172A_ABST
Patent Text Reader

Abstract

This disclosure relates to the field of industrial automation control and communication technology, and provides a communication method and apparatus for OPC UA composite data types based on CODESYS. The method includes: automatically identifying composite data type variables in a CODESYS project that have been marked with OPC UA mapping; automatically generating corresponding OPC UA address space nodes and unique node identification information based on the declaration information; and establishing a mapping relationship between OPC UA address space nodes and composite data type variables; receiving data interaction requests sent by OPC UA clients; responding to data interaction requests, locating target nodes in the OPC UA address space based on node identification information, and performing overall read or overall write operations based on the mapping relationship between target nodes and composite data type variables; performing consistency verification based on node identification information, and rejecting data interaction requests if the verification fails.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the fields of industrial automation control and communication technology, and in particular to a communication method and apparatus, electronic device and computer-readable storage medium based on CODESYS OPCUA (Open Platform Communications Unified Architecture) composite data type. Background Technology

[0002] In industrial automation control systems, OPCUA is the mainstream standard protocol for data exchange between devices. However, traditional OPCUA services mostly only support single-point transmission of basic data types such as Boolean, integer, and floating-point numbers. When the PLC program contains complex data types such as arrays, structures, and arrays of structures, it is usually necessary to manually decompose them into individual variables and configure nodes one by one. This configuration workload is large, error-prone, and the data transmission efficiency is low, which cannot meet the needs of batch data and structured data exchange in industrial settings.

[0003] Specifically, in the traditional approach, complex data type variables such as arrays and structures in a CODESYS project need to be manually broken down into individual basic data type variables, and then OPCUA nodes need to be configured one by one, with the correspondence between nodes and variables manually maintained. This method is difficult to automatically identify complex data type variables and cannot automatically generate OPCUA address space nodes that retain array dimensions and structure member hierarchy relationships, as well as unique node identification information. During data interaction, reading and writing can only be performed on a single basic data type variable as the transmission unit, and it is impossible to read and write complex data type variables as a whole. At the same time, because there is no automatic association between the node and the declaration information of complex data type variables, it is difficult to perform consistency checks on data type, array length, and structure members during the read and write process.

[0004] In summary, how to achieve automatic OPCUA node mapping, overall reading and writing, and consistency verification during the reading and writing process for complex data type variables such as arrays and structures in CODESYS projects is a technical problem that urgently needs to be solved. Summary of the Invention

[0005] In view of this, the present disclosure provides a communication method, apparatus, electronic device and computer-readable storage medium based on CODESYS OPCUA composite data type to solve the technical problems in the prior art that complex data type variables need to be manually disassembled and configured, cannot be read and written as a whole and lack consistency verification.

[0006] A first aspect of this disclosure provides a communication method for OPCUA composite data types based on CODESYS, comprising: automatically identifying composite data type variables in a CODESYS project that have been marked with an OPCUA mapping tag; automatically generating corresponding OPCUA address space nodes and unique node identification information based on the declaration information of the composite data type variables; and establishing a mapping relationship between the OPCUA address space nodes and the composite data type variables; wherein the composite data type variables are defined in the CODESYS development environment, and the composite data type includes at least one of arrays, structures, nested structures, and arrays of structures; the composite data type variables are marked with an OPCUA mapping tag, which is used to identify the composite data type variables to be mapped, thereby triggering the automatic generation of OPCUA address space nodes, and carrying or associating at least one of the mapping configuration information of the composite data type variables, including the declaration information. The system receives data interaction requests from OPCUA clients. These requests carry the node identification information of the target node and include read and / or write requests. In response to the data interaction requests, the system locates the target node in the OPCUA address space based on the node identification information. Based on the mapping relationship between the target node and the composite data type variable, the system performs a full read or write operation on the composite data type variable, with the composite data type variable as the smallest transmission unit. During the execution of the data interaction requests, the system determines the composite data type variable and its declaration information corresponding to the target node based on the node identification information. It performs a consistency check between the data type, array length, and structure members carried in the read and / or write requests and their declaration information. If the check fails, the system rejects the data interaction request and returns a standard error code.

[0007] A second aspect of this disclosure provides a communication device for OPCUA composite data types based on CODESYS, comprising: a mapping module, configured to automatically identify composite data type variables in a CODESYS project that have been marked with OPCUA mapping tags, automatically generate corresponding OPCUA address space nodes and unique node identification information based on the declaration information of the composite data type variables, and establish a mapping relationship between OPCUA address space nodes and composite data type variables; wherein, the composite data type variables are defined in the CODESYS development environment, and the composite data type includes at least one of arrays, structures, nested structures, and arrays of structures, and the composite data type variables are marked with OPCUA mapping tags, which are used to identify the composite data type variables to be mapped, thereby triggering the automatic generation of OPCUA address space nodes, and carrying or associating at least one of the mapping configuration information of the composite data type variables, the declaration information including array dimensions. The system comprises the following modules: array upper and lower limits, structure member hierarchy, and member data types; a receiving module, used to receive data interaction requests sent by OPCUA clients, which carry the node identification information of the target node and include read and / or write requests; a read / write module, used to respond to data interaction requests, locate the target node in the OPCUA address space based on the node identification information, and perform a whole read or whole write operation on the composite data type variable based on the mapping relationship between the target node and the composite data type variable, wherein the whole read or whole write operation uses the composite data type variable as the smallest transmission unit; and a verification module, used during the execution of data interaction requests, to determine the composite data type variable and its declaration information corresponding to the target node based on the node identification information, to perform consistency verification on the data type, array length, and structure members carried by the read and / or write requests with the declaration information, and to reject the data interaction request and return a standard error code if the verification fails.

[0008] A third aspect of this disclosure provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method described above.

[0009] A fourth aspect of this disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described method.

[0010] The beneficial effects of this disclosure compared to the prior art are as follows: This disclosure automatically identifies composite data type variables with added OPC UA mapping tags in the CODESYS project, automatically generates OPC UA address space nodes and unique node identification information, and establishes a mapping relationship between nodes and variables, thereby realizing automatic mapping of composite data type variables; by locating the target node according to the node identification information, and performing overall reading or overall writing on the composite data type variables based on the mapping relationship, overall reading and writing of composite data type variables is realized; by performing consistency verification of the data type, array length, and structure members carried by the read request and / or write request with the declaration information, consistency verification of read and write data is realized, thereby realizing standardized communication of OPC UA composite data types based on CODESYS, improving configuration efficiency and transmission efficiency and ensuring data read and write accuracy without the need for manual disassembly and configuration. Attached Figure Description

[0011] To more clearly illustrate the technical solutions in the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 This is a flowchart illustrating the communication method for OPC UA composite data types based on CODESYS provided in this embodiment. Figure 2 This is a flowchart illustrating the parsing process for composite data type variables in this embodiment.

[0013] Figure 3 This is a schematic diagram of the structure of a communication device based on CODESYS OPC UA composite data type provided in an embodiment of this disclosure; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0014] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, so as to provide a thorough understanding of the embodiments of this disclosure. However, those skilled in the art will understand that this disclosure may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this disclosure with unnecessary detail.

[0015] The following will describe in detail, with reference to the accompanying drawings, the communication scheme of the CODESYS-based OPC UA composite data type according to the embodiments of this disclosure.

[0016] Figure 1 This is a flowchart illustrating a communication method based on CODESYS OPC UA composite data type provided in an embodiment of this disclosure. Figure 1 As shown, the communication method based on CODESYS OPC UA composite data type in this embodiment includes: Step S101: Automatically identify composite data type variables in the CODESYS project that have been marked with OPC UA mapping. Automatically generate corresponding OPC UA address space nodes and unique node identification information based on the declaration information of the composite data type variables, and establish a mapping relationship between OPC UA address space nodes and composite data type variables. The composite data type variables are defined in the CODESYS development environment. Composite data types include at least one of arrays, structures, nested structures, and arrays of structures. The composite data type variables are marked with OPC UA mapping tags. The OPC UA mapping tags are used to identify the composite data type variables to be mapped, so as to trigger the automatic generation of OPC UA address space nodes, and carry or associate at least one of the mapping configuration information of the composite data type variables. The declaration information includes array dimensions, array upper and lower limits, structure member hierarchy relationship, and member data types.

[0017] Step S102: Receive a data interaction request sent by the OPC UA client. The data interaction request carries the node identification information of the target node and includes a read request and / or a write request.

[0018] Step S103: In response to the data interaction request, locate the target node in the OPC UA address space according to the node identification information, and perform a whole read or whole write operation on the composite data type variable based on the mapping relationship between the target node and the composite data type variable, wherein the whole read or whole write operation takes the composite data type variable as the smallest transmission unit.

[0019] Step S104: During the execution of the data interaction request, the composite data type variable and its declaration information corresponding to the target node are determined according to the node identification information. The data type, array length and structure members carried by the read request and / or write request are checked for consistency with the declaration information. If the check fails, the data interaction request is rejected and a standard error code is returned.

[0020] Specifically, in this technical solution, composite data type variables with added OPC UA mapping tags in the CODESYS project are first automatically identified. Then, based on the variable declaration information, OPC UA address space nodes and unique node identification information are automatically generated, and a mapping relationship between nodes and variables is established. The data interaction request sent by the client carries the node identification information, and the server locates the target node based on this information and performs a complete read or write operation on the composite data type variable through the mapping relationship. During the read and write process, the variable and its declaration information are also determined based on the node identification information, and consistency checks are performed on the data type, array length, and structure members. This solution links automatic mapping, complete read and write operations, and consistency checks through "node identification information" to form a complete closed loop.

[0021] This solution enables automatic node mapping and overall reading / writing of composite data type variables such as arrays, structures, nested structures, and arrays of structures in CODESYS projects, eliminating the need for manual decomposition into individual basic type variables and configuration of nodes one by one. This improves configuration and transmission efficiency, reduces manual configuration errors, and ensures that read / write data matches variable declaration information through consistency checks, reducing the risk of controller malfunctions caused by illegal data.

[0022] In this embodiment of the disclosure, composite data type variables in the CODESYS project that have been marked with OPC UA mapping are automatically identified, such as... Figure 2 As shown, based on the declaration information of composite data type variables, the corresponding OPC UA address space node and unique node identifier information are automatically generated, including: Step S201: Parse the declaration information of the composite data type variable and extract the array dimension information and the structure member hierarchy information.

[0023] Step S202: Construct a node hierarchy tree in the OPC UA address space that is consistent with the structure of the composite data type variable, according to the array dimension information and the structure member hierarchy information.

[0024] Step S203: Assign unique node identification information to each node in the node hierarchy tree, where the parent node corresponds to the entire composite data type variable, and the child node corresponds to the child element or structure member of the composite data type variable.

[0025] Step S204: Configure the access permissions, read / write attributes, description information, and engineering unit metadata of each node in the node hierarchy tree.

[0026] By parsing the declaration information to extract array dimension information and structure member hierarchy information, a node hierarchy tree consistent with the structure of composite data type variables can be constructed. By assigning unique node identifier information to each node and distinguishing between parent and child nodes, both whole-database and member-database access can be supported. By configuring metadata such as access permissions, read / write attributes, description information, and engineering units, the configurability requirements of industrial sites can be met. This solution accurately restores the hierarchical structure of composite data type variables in the OPC UA address space, ensuring that array dimensions and structure member relationships are not lost. Parent nodes correspond to the whole database, and child nodes correspond to child elements or structure members, facilitating flexible client access. Metadata configuration improves node availability and project reusability.

[0027] In step S202, a node hierarchy tree consistent with the structure of composite data type variables is constructed in the OPC UA address space, including: supporting individual access to child nodes in the node hierarchy tree and overall access to parent nodes, with individual access and overall access sharing the same underlying data storage area.

[0028] If parent and child nodes use different data replicas, inconsistencies between overall read / write operations and child node read / write results can easily arise. Therefore, sharing the same underlying storage area is a crucial prerequisite for ensuring data consistency. This solution explicitly states that individual access by child nodes and overall access by parent nodes share the same underlying data storage area, and guarantees that both overall access by parent nodes and individual access by child nodes read or write the same actual data, thus avoiding data inconsistency; reducing additional storage overhead; and improving the reliability of data synchronization between overall read / write operations and member read / write operations.

[0029] In step S103, a total read or write operation is performed on the composite data type variable, including: serializing the composite data type variable to generate a total data frame compatible with the first OPC UA specification; when the size of the total data frame exceeds the maximum message length of a single transmission of the OPC UA protocol, the total data frame is fragmented to generate multiple data fragments, and each data fragment is assigned a fragment sequence number and a total fragment count identifier; the multiple data fragments are transmitted sequentially to the OPC UA client or received from the OPC UA client, and reassembled at the receiving end according to the fragment sequence number and the total fragment count identifier to restore the complete composite data type data.

[0030] For complex data type variables, the overall data volume may be large, and direct transmission may exceed the single message length limit of the OPC UA protocol. Therefore, it is necessary to first serialize and generate a complete data frame, and then fragment the data for transmission when the maximum message length is exceeded. At the receiving end, the complete data is reassembled based on the fragment sequence number and the total number of fragments. This system supports the overall transmission of complex data type variables such as large arrays and large structures, avoiding transmission failures due to single message length limitations. The fragmentation and reassembly mechanism ensures data integrity, reduces the number of single-point read / write requests on the client, lowers network overhead, and improves the efficiency of batch structured data transmission.

[0031] In this embodiment of the disclosure, the method further includes a subscription and publication step: receiving a subscription request initiated by an OPC UA client for a composite data type variable, the subscription request including a data refresh cycle parameter; monitoring the value change of the composite data type variable according to the data refresh cycle; when a value change is detected, sending the current overall value of the composite data type variable as subscription notification data to the OPC UA client, the subscription notification data including the complete structure data of the composite data type variable and the last update timestamp.

[0032] Industrial supervisory control systems often require real-time monitoring of changes in variables with complex data types, rather than repeated polling. This solution receives subscription requests containing refresh cycle parameters, monitors variable value changes periodically, and sends subscription notifications containing complete structured data and the last update timestamp when changes occur, enabling overall data subscription and publication. This solution supports OPC UA clients in obtaining the overall changes of variables with complex data types through subscription, reducing polling communication overhead; it monitors by refresh cycle, flexibly adapting to different real-time requirements; and the subscription notifications contain complete structured data and timestamps, facilitating real-time monitoring, data logging, and fault analysis by the supervisory control system.

[0033] In step S104, the data type, array length, and structure members carried in the read request and / or write request are checked for consistency with the declared information. This includes: extracting the target data type identifier, target array length, and target structure member list carried in the read request and / or write request; comparing the target data type identifier with the declared data type of the composite data type variable, comparing the target array length with the declared array length of the composite data type variable, and comparing the target structure member list with the declared structure member list of the composite data type variable; if any comparison result is inconsistent, a verification failure message is generated, the verification failure message is written to the system log, and a rejection response mapped to the OPC UA standard error code is returned to the OPC UA client.

[0034] Only by extracting the target data type identifier, target array length, and target structure member list carried in the read and / or write requests, and comparing them item by item with the declared data type, declared array length, and declared structure member list of the composite data type variable, can type mismatches, length inconsistencies, or member mismatches be detected before data interaction. Writing to the log and returning a standard error code when verification fails ensures that exceptions are traceable and identifiable by the client. This solution prevents data with mismatched data types, array lengths, or structure members from being read or written incorrectly, improving the accuracy of data interaction; standard error codes facilitate unified exception handling by the client; and system logs facilitate maintenance troubleshooting and problem tracing.

[0035] In this embodiment of the disclosure, the method further includes a boundary verification step: upon receiving a write request, parsing the array index value and data value range carried in the write request; determining whether the array index value is within the upper and lower limits of the declared array of the composite data type variable, and whether the data value range is within the valid range of the data type of the corresponding member of the composite data type variable; when the array index value or the data value range exceeds the corresponding range, rejecting the write request, and generating an out-of-bounds alarm message to write to the system log.

[0036] Even if the data type, array length, and structure members are consistent, writing data may still result in array index out-of-bounds errors or values ​​exceeding the valid range of members. Therefore, upon receiving a write request, it is necessary to parse the array index value and the data value range, and compare them with the declared upper and lower limits of the array and the valid range of the member data type. If the values ​​exceed these limits, the write operation is rejected and an out-of-bounds alarm is generated. This solution can further prevent illegal array indexes or out-of-range data from being written to the controller, avoiding program abnormalities or device malfunctions caused by out-of-bounds writing; improve write security; and log out-of-bounds alarms to facilitate locating the source of illegal writing and performing operational analysis. The technical solution of this disclosure embodiment may also include a connection fault tolerance step: monitoring the communication connection status between the OPC UA server and the OPC UA client; when an abnormal disconnection of the communication connection is detected, recording a snapshot of the state of the composite data type variable at the time of disconnection; after the communication connection is restored, comparing the current value of the composite data type variable with the state snapshot, and synchronizing the difference data to the OPC UA client.

[0037] Improve the reliability of OPC UA communication connections. When a connection is abnormally disconnected, record a state snapshot of variables of composite data types. After the connection is restored, synchronize only the changed data by comparing differences, avoiding inconsistencies between client and controller data caused by disconnection; at the same time, reduce the overhead of full synchronization after recovery and improve data synchronization efficiency.

[0038] The technical solution of this disclosure embodiment may further include a communication parameter configuration step, which includes at least one of the following: configuring the service port, IP address, maximum number of connections, and communication timeout of the OPC UA server; configuring security policies, including a no-security-policy mode and a Basic256Sha256 security mode, as well as a username and password authentication method; configuring data parameters, including the maximum array dimension, the maximum number of nested structures, the data refresh cycle, and the subscription buffer size; and configuring different users' read and write permission levels for composite data type variables.

[0039] This solution offers flexible communication parameter configuration capabilities, enabling the OPC UA server to adapt to different network environments, security requirements, and data scales in various industrial settings; it enhances communication security through security policies and username / password authentication; it prevents unauthorized users from reading or writing complex data type variables through hierarchical permission settings; and it supports array and structure applications of varying complexity through data parameter configuration.

[0040] The technical solution of this disclosure embodiment may further include status monitoring and diagnostic steps: real-time collection of OPC UA server running status data, including the number of currently connected clients, data transmission throughput, and the number of mapped composite data type variables; for each mapped composite data type variable, recording its current value, data type identifier, and last update time, and displaying it through a monitoring panel; generating running logs, including connection logs, data read / write logs, and abnormal alarm logs, and supporting log export and query; providing a diagnostic interface for outputting communication statistics and error count indicators.

[0041] Enhance the visualization and operational support capabilities of the OPC UA server. Real-time collection of connection counts, throughput, and the number of mapped variables facilitates understanding of service operational status; displaying the current value, type, and update time of variables with composite data types facilitates monitoring data changes; log recording and export queries facilitate anomaly tracing and problem localization; and the diagnostic interface outputs communication statistics and error counts, facilitating remote operation and maintenance and fault diagnosis.

[0042] The technical solution of this disclosure embodiment can be used to develop application software based on the CODESYS programmable controller development platform, which provides a complete OPC UA communication solution specifically for complex data types such as arrays and structures, realizes automatic node mapping, overall reading and writing and subscription monitoring of complex data types, thereby greatly improving the configuration efficiency and transmission reliability of data interaction in industrial control systems.

[0043] This software can be applied to industrial automation scenarios such as intelligent manufacturing, process control, and equipment data acquisition. It can be deployed in PLCs, industrial PCs, and embedded controllers that support CODESYS runtime. As an OPC UA server component, it provides standardized complex data type interaction capabilities for SCADA systems, MES systems, data acquisition platforms, and upper-level monitoring software. It is suitable for business scenarios such as production line data acquisition, equipment status monitoring, and batch parameter distribution.

[0044] Specifically, the software can be integrated into the CODESYS project as a function library, supporting native definitions and automatic mapping of various complex data types such as one-dimensional / multi-dimensional arrays, single-level / nested structures, and structure arrays; it provides complete OPC UA server capabilities, supporting overall reading, writing, and subscription / publishing of complex data; and it has built-in auxiliary functions such as data verification, connection management, status monitoring, and logging to ensure the consistency and stability of data transmission.

[0045] During software development, Windows 7 SP1 / Windows 10 / Windows 11 64-bit operating systems can be used, along with the CODESYS Development System V3.5.17.0 or later development platform, and the standard OPC UA client testing tool as an auxiliary tool. Hardware configurations can include an Intel Core i3 or higher CPU, 4GB or more of memory, and 500MB or more of storage space.

[0046] During software operation, PLC controllers, industrial PCs, and embedded industrial control computers that support CODESYS Runtime can be used as hardware carriers; the processor can be ARM Cortex-A8 600MHz or higher or x86 1GHz or higher; the memory can be 256MB RAM or higher; the storage space can be 100MB of available storage space or higher; the operating system can be CODESYS Control Runtime V3.5.15 or higher, compatible with operating systems supported by CODESYS such as Windows, Linux, and VxWorks; the network supports Ethernet communication and TCP / IP protocol stack.

[0047] Furthermore, the software can adopt a modular design, comprising 6 core functional modules, the functions of which are as follows: The first module is the complex data type definition module. This is the foundational module of the software, fully compatible with the IEC 61131-3 standard, and supports the definition of various complex data types in CODESYS projects using structured text, ladder logic, and other programming languages. Specifically, this module supports the definition of one-dimensional, two-dimensional, and multi-dimensional arrays, allowing users to customize array upper and lower limits and data element types; it supports the definition of single-level and nested structures, with structure members containing basic data types, arrays, and sub-structures; it supports the definition of combined types such as structure arrays and array structures, meeting the needs of complex business data modeling; and it includes a built-in library of commonly used industrial data templates, containing general types such as equipment status structures and alarm information arrays, which can be directly called.

[0048] Second is the OPC UA node auto-mapping module, which automatically maps CODESYS variables to the OPC UA address space and is a core functional module of the software. Specifically, this module has the following features: it automatically identifies array and structure variables marked in the CODESYS project and automatically generates corresponding OPC UA nodes and unique NodeIds (node ​​identifiers); it fully preserves array dimensions and structure member hierarchy relationships, restoring the data structure in the OPC UA address space, while supporting individual access to child nodes and overall access to parent nodes; it supports manual configuration of node access permissions, read / write attributes, description information, engineering units, and other metadata; it supports batch import and export of node configurations, supports project reuse, and reduces repetitive configuration workload.

[0049] Thirdly, there is the data interaction and transmission module, which enables efficient transmission of complex data under the OPC UA protocol and fully complies with the official OPC UA 1.04 specification. This module supports the overall reading and writing of arrays and structures without breaking them down into individual variables, significantly improving transmission efficiency; it supports batch reading of multiple complex data variables, supports publish-subscribe mode, and allows flexible configuration of the data refresh cycle; it supports data fragmentation transmission, automatically splitting large arrays and large structure data into packets to ensure data integrity; and it is compatible with all standard OPC UA client access, requiring no additional client adaptation development.

[0050] Fourth is the data verification and fault tolerance module, which ensures the accuracy of data transmission and the stability of system operation. Specifically, the functions of this module include: performing consistency checks on the data type, array length, and structure members of read and write requests, automatically rejecting them and returning standard error codes when types do not match; performing out-of-bounds checks on array subscripts and data value ranges to prevent illegal data writing from causing controller program abnormalities; supporting automatic reconnection in case of OPC UA connection failures, and automatically synchronizing the latest data of the current array structure after reconnection; and generating alarm information and writing it to the system log when data transmission is abnormal or verification fails.

[0051] Fifth is the communication configuration management module, which provides visual configuration capabilities for software parameters, including: basic OPCUA service configuration, which allows configuring service port, IP address, maximum number of connections, and communication timeout; security policy configuration, supporting multiple security modes such as no security policy and Basic256Sha256, and supporting username and password authentication; data parameter configuration, which allows configuring the maximum array dimension, maximum structure nesting level, data refresh cycle, and subscription buffer size; and permission configuration, which allows configuring read and write permissions for different users on array and structure variables, supporting read-only, write, and other permission levels.

[0052] Sixth is the status monitoring and logging module, which provides visualization of operational status and operational support capabilities. Specifically, it includes: real-time monitoring of the OPC UA service's operational status, the number of currently connected clients, and data transmission throughput; real-time display of the current value, data type, and last update time of mapped array and structure variables; support for recording operational logs, including connection logs, data read / write logs, and exception alarm logs, with support for log export and querying; and a diagnostic interface that supports reading communication statistics, error counts, and other operational metrics.

[0053] This software breaks through the limitations of traditional OPC UA, which only supports basic data types. It natively supports the overall interaction of various complex data types such as arrays, nested structures, and arrays of structures, eliminating the need for manual splitting and ungrouping, thus improving configuration efficiency by over 70%. Based on CODESYS variable declarations, it automatically generates OPC UA address space nodes, eliminating the need for manual node configuration code, lowering the development threshold, and reducing manual configuration errors. Employing a combination of overall data serialization and fragmented transmission, it improves the efficiency of batch complex data transmission by over 50% compared to single-point variable transmission, significantly reducing network overhead. Fully compatible with the CODESYS ecosystem and standard OPC UA protocols, it requires no additional hardware support and is integrated into CODESYS projects as a function library, resulting in low resource consumption and compatibility with most industrial controllers. Built-in multi-dimensional data verification logic for type, length, and boundaries ensures data transmission accuracy and prevents controller malfunctions caused by illegal data.

[0054] When operating this software, first import the software library file into the CODESYS development environment and add it to the library manager of the current project; then define the required array and structure data types in the CODESYS program, declare the corresponding variables, and add OPC UA mapping tags; next, open the software configuration interface, set parameters such as OPC UA service port, security policy, and refresh cycle, and enable the automatic node mapping function; then compile the CODESYS project, download it to the target controller, and start running it; after that, use a standard OPC UA client to connect to the controller's IP address and corresponding port to access array and structure variables in the OPC UA address space and perform read, write, and subscription operations; finally, through the monitoring panel of the configuration interface, view the service running status and data transmission status, and query the running logs.

[0055] All of the above-mentioned optional technical solutions can be combined in any way to form the optional embodiments of this application, and will not be described in detail here.

[0056] According to the communication method for CODESYS-based OPC UA composite data types in this disclosure, the method automatically identifies composite data type variables with added OPC UA mapping tags in the CODESYS project, automatically generates OPC UA address space nodes and unique node identification information, and establishes a mapping relationship between nodes and variables to achieve automatic mapping of composite data type variables. It locates the target node based on the node identification information and performs a complete read or write operation on the composite data type variable based on the mapping relationship to achieve complete read and write operation of the composite data type variable. It performs consistency verification of the data type, array length, and structure members carried by the read and / or write requests with the declaration information to achieve consistency verification of read and write data. This enables standardized communication of CODESYS-based OPC UA composite data types, improving configuration efficiency and transmission efficiency while ensuring data read and write accuracy without requiring manual configuration disassembly.

[0057] The following are embodiments of the apparatus disclosed herein, which can execute the method embodiments of this disclosure. The methods provided in the embodiments of this disclosure can be executed by any electronic device with computer processing capabilities, such as an industrial control computer. The communication apparatus based on CODESYS OPC UA composite data type described below and the communication method based on CODESYS OPC UA composite data type described above can be referred to in correspondence with each other. For details not disclosed in the apparatus embodiments of this disclosure, please refer to the method embodiments of this disclosure.

[0058] Figure 3 This is a schematic diagram of the structure of a communication device based on CODESYS OPC UA composite data type, provided in an embodiment of this disclosure. Figure 3As shown, the communication device based on CODESYS OPC UA composite data type includes: The mapping module 301 is used to automatically identify composite data type variables in the CODESYS project that have been marked with OPCUA mapping. Based on the declaration information of the composite data type variables, it automatically generates the corresponding OPCUA address space node and unique node identification information, and establishes a mapping relationship between the OPCUA address space node and the composite data type variable. The composite data type variable is defined in the CODESYS development environment. The composite data type includes at least one of array, structure, nested structure, and structure array. The composite data type variable has an OPCUA mapping mark added to it. The OPCUA mapping mark is used to identify the composite data type variable to be mapped, so as to trigger the automatic generation of the OPCUA address space node, and carries or associates at least one of the mapping configuration information of the composite data type variable. The declaration information includes array dimension, array upper and lower limits, structure member hierarchy relationship and member data type.

[0059] The receiving module 302 is used to receive data interaction requests sent by the OPCUA client. The data interaction requests carry the node identification information of the target node and include read requests and / or write requests.

[0060] The read / write module 303 is used to respond to data interaction requests, locate the target node in the OPCUA address space according to the node identification information, and perform a whole read or whole write operation on the composite data type variable based on the mapping relationship between the target node and the composite data type variable, wherein the whole read or whole write operation uses the composite data type variable as the smallest transmission unit.

[0061] The verification module 304 is used to determine the composite data type variable and its declaration information corresponding to the target node based on the node identification information during the execution of the data interaction request. It performs consistency verification on the data type, array length and structure members carried by the read request and / or write request with the declaration information, and rejects the data interaction request and returns a standard error code when the verification fails.

[0062] According to the CODESYS-based OPC UA composite data communication device of this disclosure, the device automatically identifies composite data type variables with added OPC UA mapping tags in the CODESYS project, automatically generates OPC UA address space nodes and unique node identification information, and establishes a mapping relationship between nodes and variables to achieve automatic mapping of composite data type variables. It locates the target node based on the node identification information and performs overall reading or writing of the composite data type variables based on the mapping relationship to achieve overall reading and writing of composite data type variables. It performs consistency verification of the data type, array length, and structure members carried by the read request and / or write request with the declaration information to achieve consistency verification of read and write data. This enables standardized communication of CODESYS-based OPC UA composite data types, improving configuration efficiency and transmission efficiency while ensuring data read and write accuracy without the need for manual configuration disassembly.

[0063] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this disclosure.

[0064] Figure 4 This is a schematic diagram of the electronic device 4 provided in an embodiment of this disclosure. Figure 4 As shown, the electronic device 4 of this embodiment includes a processor 401, a memory 402, and a computer program 403 stored in the memory 402 and executable on the processor 401. When the processor 401 executes the computer program 403, it implements the steps in the various method embodiments described above. Alternatively, when the processor 401 executes the computer program 403, it implements the functions of each module in the various device embodiments described above.

[0065] Electronic device 4 can be a desktop computer, laptop, handheld computer, cloud server, or other electronic device. Electronic device 4 may include, but is not limited to, processor 401 and memory 402. Those skilled in the art will understand that... Figure 4 This is merely an example of electronic device 4 and does not constitute a limitation on electronic device 4. It may include more or fewer components than shown, or different components.

[0066] The processor 401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0067] The memory 402 can be an internal storage unit of the electronic device 4, such as a hard disk or RAM of the electronic device 4. The memory 402 can also be an external storage device of the electronic device 4, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc., equipped on the electronic device 4. The memory 402 can also include both internal and external storage units of the electronic device 4. The memory 402 is used to store computer programs and other programs and data required by the electronic device.

[0068] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0069] If the integrated module is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program may include computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium may be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.

[0070] The above embodiments are only used to illustrate the technical solutions of this disclosure, and are not intended to limit it. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be included within the protection scope of this disclosure.

Claims

1. A communication method for composite data types using the OPC UA unified architecture of the CODESYS open platform, characterized in that, Includes the following steps: Automatically identify composite data type variables in the CODESYS project that have been marked with OPC UA mapping, automatically generate corresponding OPC UA address space nodes and unique node identification information based on the declaration information of the composite data type variables, and establish a mapping relationship between the OPC UA address space nodes and the composite data type variables; The composite data type variable is defined in the CODESYS development environment. The composite data type includes at least one of array, structure, nested structure, and structure array. The composite data type variable is marked with the OPC UA mapping tag. The OPC UA mapping tag is used to identify the composite data type variable to be mapped, so as to trigger the automatic generation of OPC UA address space nodes and carry or associate at least one of the mapping configuration information of the composite data type variable. The declaration information includes array dimension, array upper and lower limits, structure member hierarchy relationship and member data type. Receive data interaction requests sent by OPC UA clients, wherein the data interaction requests carry node identification information of the target node, and the data interaction requests include read requests and / or write requests; In response to the data interaction request, the target node is located in the OPC UA address space according to the node identification information, and based on the mapping relationship between the target node and the composite data type variable, a whole read or whole write operation is performed on the composite data type variable, wherein the whole read or whole write operation takes the composite data type variable as the smallest transmission unit. During the execution of the data interaction request, the composite data type variable and its declaration information corresponding to the target node are determined according to the node identification information. The data type, array length and structure members carried by the read request and / or write request are checked against the declaration information for consistency. If the check fails, the data interaction request is rejected and a standard error code is returned.

2. The method according to claim 1, characterized in that, The automatic identification of composite data type variables in the CODESYS project that have been marked with OPCUA mapping, and the automatic generation of corresponding OPC UA address space nodes and unique node identification information based on the declaration information of the composite data type variables, including: Parse the declaration information of the composite data type variable to extract array dimension information and structure member hierarchy information; Based on the array dimension information and structure member hierarchy information, construct a node hierarchy tree in the OPC UA address space that is consistent with the structure of the composite data type variable; Assign unique node identifier information to each node in the node hierarchy tree, wherein the parent node corresponds to the entire composite data type variable, and the child node corresponds to the child element or structure member of the composite data type variable; Configure the access permissions, read / write attributes, description information, and engineering unit metadata of each node in the node hierarchy tree.

3. The method according to claim 2, characterized in that, The construction of a node hierarchy tree in the OPC UA address space that is consistent with the structure of the composite data type variable includes: supporting individual access to child nodes in the node hierarchy tree and overall access to parent nodes, wherein the individual access and the overall access share the same underlying data storage area.

4. The method according to claim 1, characterized in that, The step of performing a complete read or write operation on the composite data type variable includes: The composite data type variable is serialized to generate an overall data frame compatible with the first OPC UA specification; When the size of the overall data frame exceeds the maximum message length of a single transmission of the OPC UA protocol, the overall data frame is fragmented to generate multiple data fragments, and each data fragment is assigned a fragment sequence number and a total fragment count identifier. The multiple data fragments are transmitted sequentially to or received from the OPC UA client. At the receiving end, they are reassembled according to the fragment sequence number and the total number of fragments to restore the complete composite data type.

5. The method according to claim 1, characterized in that, The method also includes a publish-subscribe step: Receive subscription requests initiated by OPC UA clients for the composite data type variable, wherein the subscription requests include data refresh cycle parameters; Monitor the value changes of the composite data type variable according to the data refresh cycle; When a value change is detected, the current overall value of the composite data type variable is sent to the OPC UA client as subscription notification data. The subscription notification data includes the complete structure data of the composite data type variable and the last update timestamp.

6. The method according to claim 1, characterized in that, The step of verifying the consistency of the data type, array length, and structure members carried in the read request and / or write request with the declared information includes: Extract the target data type identifier, target array length, and target structure member list carried in the read request and / or write request; The target data type identifier is compared with the declared data type of the composite data type variable; the target array length is compared with the declared array length of the composite data type variable; and the target structure member list is compared with the declared structure member list of the composite data type variable. If any comparison result is inconsistent, a verification failure message is generated, the verification failure message is written to the system log, and a rejection response mapped to the OPC UA standard error code is returned to the OPC UA client.

7. The method according to claim 6, characterized in that, The method also includes a boundary verification step: Upon receiving a write request, the array index value and data value range carried in the write request are parsed. Determine whether the array index value is within the upper and lower limits of the declared array of the composite data type variable, and whether the data value range is within the valid range of the data type of the corresponding member of the composite data type variable; When the array index value or the range of the data value exceeds the corresponding range, the write request is rejected, and an out-of-bounds alarm message is generated and written to the system log.

8. A communication device based on CODESYS OPC UA composite data type, characterized in that, include: The mapping module is used to automatically identify composite data type variables in the CODESYS project that have been marked with OPC UA mapping, automatically generate the corresponding OPC UA address space node and unique node identification information according to the declaration information of the composite data type variable, and establish the mapping relationship between the OPC UA address space node and the composite data type variable. The composite data type variable is defined in the CODESYS development environment. The composite data type includes at least one of array, structure, nested structure, and structure array. The composite data type variable is marked with the OPC UA mapping tag. The OPC UA mapping tag is used to identify the composite data type variable to be mapped, so as to trigger the automatic generation of OPC UA address space nodes and carry or associate at least one of the mapping configuration information of the composite data type variable. The declaration information includes array dimension, array upper and lower limits, structure member hierarchy relationship and member data type. The receiving module is used to receive data interaction requests sent by the OPC UA client. The data interaction requests carry node identification information of the target node and include read requests and / or write requests. The read / write module is used to respond to the data interaction request, locate the target node in the OPC UA address space according to the node identification information, and perform a whole read or whole write operation on the composite data type variable based on the mapping relationship between the target node and the composite data type variable, wherein the whole read or whole write operation takes the composite data type variable as the smallest transmission unit. The verification module is used to determine the composite data type variable and its declaration information corresponding to the target node based on the node identification information during the execution of the data interaction request, to perform consistency verification between the data type, array length and structure members carried by the read request and / or write request and the declaration information, and to reject the data interaction request and return a standard error code when the verification fails.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 7.