Location>code7788 >text

Qt + OPC development notes (I): OPCUA introduction, open62541 introduction, compilation and basic environment Demo

Popularity:21 ℃/2024-12-16 21:50:21

preamble

  This article introduces the OPC protocol, related open source libraries, compile and build the basic environment for Qt development OPC.

 

Demo

  在这里插入图片描述

 

OPC

  OPC (OLE for Process Control) is an industrial standard for data exchange and interoperability between different devices and applications in industrial automation systems. The following is a detailed description of OPC:

Origins and Development of OPC

  OPC originated in the 1990s. With the continuous development of industrial automation technology, data exchange and interoperability between devices and application software from different vendors has become an urgent problem. In order to solve this problem, OPC Foundation (OPC Foundation) came into being and launched the OPC standard. After years of development, OPC has evolved from a simple data exchange standard into a complete industrial automation communication architecture.
  Core Features of OPC

  • Cross-platform: OPC standards do not depend on specific operating systems or hardware platforms, and interoperability can be realized on different operating systems and hardware platforms.
  • Real-time: OPC standard supports real-time data exchange, which can meet the real-time requirements of industrial automation systems.
  • Security: The OPC standard provides a variety of security mechanisms, such as data encryption and authentication, to ensure the security and integrity of data transmission.
  • Ease of Use: The OPC standard provides simple interfaces and protocols that allow developers to easily implement data exchange and interoperability between devices.

Architecture of OPC

  The architecture of OPC consists of the following main components:

  • OPC Server: The OPC server is the data source in the industrial automation system, which is responsible for collecting and storing the data from the devices and providing it to the OPC clients for access.
  • OPC Client: An OPC client is a data consumer in an industrial automation system that obtains data from an OPC server and processes and analyzes it.
  • OPC Interface: The OPC interface is a bridge for data exchange between the OPC server and the OPC client, which defines the format and protocol for data exchange.

OPC Application Scenarios

  OPC is widely used in industrial automation, including but not limited to the following:

  • Monitoring system: OPC can be used to build a monitoring system that collects and displays the operating status and parameters of equipment in real time.
  • Control system: OPC can be used to build control systems to realize remote control and regulation of equipment.
  • Data Acquisition System: OPC can be used to build a data acquisition system that collects real-time data from devices and stores and analyzes it.
  • Historical data access system: OPC supports historical data access function, which can query and analyze the historical data of the equipment and provide decision support for optimizing production and management.

OPC UA(Unified Architecture)

  With the development of industrial automation technology and the rise of the Internet of Things (IoT), the OPC Foundation introduced the OPC UA standard, which is an upgraded version of the OPC standard that adopts a service-oriented architecture and a unified data model, providing more flexible and powerful data exchange and interoperability functions.OPC UA also supports cross-platform and cross-system data exchange and remote monitoring functions, which brings wider and deeper applications in the field of industrial automation. OPC UA also supports cross-platform, cross-system data exchange and remote monitoring functions, bringing more extensive and in-depth applications in industrial automation.

OPC UA open source library

  There are two open source libraries based on C/C++ as follows:

open62541

  • Key Features: A lightweight, embedded C/C++ OPC UA implementation.
  • Programming language: C/C++.
  • Features: supports cross-platform; follows the Mozilla Public License v2.0 license; provides a complete implementation of the OPC UA stack, including server, client, subscription and publishing features; easy to integrate and extend; detailed documentation and tutorials.

FreeOpcUa

  • Key Features: A full-featured C++ OPC UA server and client library.
  • Programming language: C++.
  • Features: follow the LGPL-3.0 license; support for data change events, state change events and filtering features; provide basic authentication and certificate handling features; support for automated code generation; detailed documentation and sample code; recently added features such as Python bindings and automation tools.
 

open62541

summarize

  open62541 is an open source implementation of the OPC UA (OPC Unified Architecture) protocol stack. written in a generic subset of the C99 and C++98 languages, open62541 works with all major compilers and provides the tools necessary to implement dedicated OPC UA clients and servers or to integrate OPC UA-based communication into existing applications. The open62541 library is platform-independent, all platform-specific functionality is implemented via exchangeable plug-ins, and plug-in implementations are provided for major operating systems.

Functional Features

  • Open Source Free: open62541 is licensed under the Mozilla Public License v2.0, so the open62541 library can be used in non-open source projects. Only changes to the open62541 library itself need to be released under the same license. The plugin, as well as the server and client examples, are public domain (CC0 license) and can be reused under any license without having to release changes.
  • Cross-platform: open62541 supports a variety of operating systems and platforms, including Windows, Linux, macOS, etc., with good portability.
  • High performance: open62541 adopts event-based architecture and asynchronous I/O mechanism, which has very good performance and scalability and is suitable for application scenarios with high real-time requirements.
  • Security: The OPC UA protocol provides a variety of security mechanisms, including authentication, encrypted transmission, etc. open62541, as an implementation of the OPC UA protocol stack, also inherits these security features.
  • Extensibility: open62541 supports flexible data models and service extensions that can be customized and extended according to specific needs. It also supports plug-in development, which can easily add protocol extensions, authentication mechanisms, encryption protocols and other functions.

application scenario

  The open62541 can be used in a variety of industrial automation and IoT scenarios, for example:

  • Industrial control system: to realize data exchange and control between different devices, and to realize the integration and optimization of industrial automation system.
  • Intelligent Manufacturing: Realize data sharing and collaboration between equipment to improve production efficiency and quality.
  • Intelligent buildings: to realize the monitoring and management of building equipment, and to improve the efficiency of energy use and comfort.
  • IoT application: realizing data transmission and communication between IoT devices, realizing application scenarios such as smart home and smart city.

Source Code Download

  在这里插入图片描述

  在这里插入图片描述

 

Compile open62541

Step 1: Download and unzip

  在这里插入图片描述

Step 2: Configure configure

  Use cmake to configure it:
  在这里插入图片描述

  在这里插入图片描述

  在这里插入图片描述

  在这里插入图片描述

  在这里插入图片描述

  在这里插入图片描述

  在这里插入图片描述

  The configuration went through without a hitch, remember to configure the path to install install, and then you also need to reconfigure it to take effect:
  在这里插入图片描述

Step 3: Generate project Generate

  在这里插入图片描述
  在这里插入图片描述

  At this point, the use of CMake is complete.

Step 4: Compilation

  在这里插入图片描述

  在这里插入图片描述

  Start compiling:
  在这里插入图片描述

  在这里插入图片描述

  Compilation completed
  在这里插入图片描述

Step 5: Installation

   在这里插入图片描述

  在这里插入图片描述

Step 6: Check the installation directory

  在这里插入图片描述

  在这里插入图片描述

  .a is the static library way, you can configre configure it as a dynamic library way, whatever here.
  Modified to release version, only 1.2MB now:
  在这里插入图片描述

 

modularization

  在这里插入图片描述

 

Demo Source Code

QString OpcClientManager::getVersion()
{
    UA_Client *client;
    LOG << client;
    client = UA_Client_new();
    LOG << client;
    UA_ClientConfig_setDefault(UA_Client_getConfig(client));

    return QString(UA_OPEN62541_VERSION);
}

  在这里插入图片描述

 

Engineering Templates v1.0.0

  在这里插入图片描述

 

fig. make a career out of it

Pitfall 1: Can't find the library

concern

  Function Error
   在这里插入图片描述

  在这里插入图片描述

rationale

  This is missing some windows base libraries.

tackle

  fill in (blanks, gaps etc)

LIBS += -lws2_32

  在这里插入图片描述