【实例简介】
open ua统一标准指导文档,基于C语言的。包含了节点,函数,类型等基础说明。以及open ua服务器/客户端建立的一些基本实例。
Contents
1 Introduction
I1 OPC Unified Architecture
en62541 Features
1.3 Getting Hel
1. 4 Contributing
2 Building open 62541
2.1 Building the Examples
2.2 Building the library
2.3 Build Options
3 Tutorials
3.1 Working with Data Types
9
3.2 Building a Simple Server
3.3 Adding Variables to a Server
.13
3.4 Connecting a Variable with a Physical Process
.,,14
3.5 Working with Variable Types
3.6 Working with Objects and Object Types
19
3.7 Adding Methods to Objects
3.8 Building a Simple Client
4 Protocol
31
4.1 Establishing a Connection
4.2 Structure of a protocol message
5 Data Types
5.1 Builtin Types
5.2 Generic Type Handling
47
5.3 Array handling
49
5. 4 Random Number generator
49
5.5 Generated Data Type Definitions
49
5.6 Deprecated Data Types APl
94
6 Services
6.I D
97
6.2 Secure Channel service set
6.3 Session Service set
6.4 Node management Service Set
100
6.5 View Service Set
.,...100
6.6 Query Service Set
10
6.7 Attribute Service Set
102
6.8 Method Service set
102
6.9 MonitoredItem service set
103
6.10 Subscription Service Set
104
7 Information Modelling
l07
7.1 Base Node Attributes
107
7. 2 Variable Node
7.3 Variable TypeNode
7.4 MethodE
109
7.5 ObjectNode
110
7.6 ObjectTypeNode
l10
7.7 Reference'TypeNode
110
7.8 Data TypeNode
7.9 View Node
...112
7.10 Nodestore Plugin API
112
8 Server
I15
8.1 Server Configuration
8.2 Server Lifecycle
117
8.3 Repeated Callbacks
118
8.4 Reading and writing Node attributes
118
8.5B1
123
8.6 Discovery
124
8.7 Information model callbacks
8.8 Node addition and deletion
129
8.9 Reference Management
l34
8.10 Utility Functions
134
8.11 Deprecated Server API
134
9 Client
137
9.1 Client Lifecycle
137
9.2 Client Lifecycle callback
137
9.3 Subscription Inactivity callback
137
9. 4 Client Configurat
138
9.5 Connect to a Server
,,,,,,,.,,,,,138
9.6 Discovery
.139
9.7 Services
140
9.8 Asynchronous Services
143
10 Standard-Defined Constants
155
10.1 Attribute Id
10.2 Access Level masks
155
10.3 Write masks
156
10.4 Status Codes
156
10.5 Namespace Zero Nodelds
164
11 XML Nodeset Compiler
189
11.1 Getting started
189
11.2 Creating object instances
194
11.3 Combination of multiple nodesets
.195
12 Internals
199
12.1 Networking Plugin API
199
12.2 Access Control Plugin API
.202
12.3 Logging plugin APl
CHAPTER 1
Introduction
open62541(http://open62541.org)isanopensourceandfreeimplementationofOpcUa(opCunIfiedArchitec
ture)written in the common subset of the C99 and C++98 languages. The library is usable with all major compilers
and provides the necessary tools to impleinent dedicated OPC UA clients and servers, or to integrate OPC UA-
based communication into existing applications. open62541 library is platform independent. All platform-specifie
functionality is implemented via exchangeable plugins. Plugin implementations are provided for the major oper
ating systems
open62541 is licensed under the Mozilla Public License v2.0. So the open62541 library can be used in projects
that are not open source. Only changes to the open62541 library itself need to published under the same license
The plugins, as well as the server and client examples are in the public domain( Cco license). They can be reused
under any license and changes do not have to be published
1.1 OPC Unified Architecture
OPC UA is a protocol for industrial communication and has been standardized in the ieC 62541 series. At its
core. opc ua defines
an asynchronous protocol(built upon Tcp Http or Soap) thaT defines the exchange of messages via
sessions,(on top of)secure communication channels, (on top of)raw connections
a type system for protocol messages with a binary and XML-based encoding scheme,
a meta-model for information modeling, that combines object-orientation with semantic triple-relations, and
set of 37 standard services to interact with server-side information models. The signature of each service
is defined as a request and response message in the protocol type system
The standard itself can be purchased from IEC or downloaded for free on the website of the OPC Foundation at
https://opcfoundation.org/(youneedtoregisterwithavalidemail
The OPC Foundation drives the continuous improvement of the standard and the development of companion spec-
ifications Companion specifications translate established concepts and reusable components from an application
domain into OPC UA. They are created jointly with an established industry council or standardization body from
the application domain. Furthermore, the OPC Foundation organizes events for the dissemination of the standard
and provides the infrastructure and tools for compliance certification
open62541 Documentation, Release 0.3. dev
1.2 open62541 Features
open62541 implements the OPC Ua binary protocol stack as well as a client and server SDK. It currently supports
the micro embedded Device server Profile plus some additional features Server binaries can be well under lookb
in size, depending on the contained information nodel
· Communication stack
OPC UA binary protocol
Chunking(splitting of large messages)
Exchangeable network layer(plugin) for using custom networking APIs(e. g on embedded targets)
Encrypted communication
Asynchronous service requests in the client
· Information model
Support for all OPC UA node types(including method nodes)
Support for adding and removing nodes and references also at runtime
Support for inheritance and instantiation of object-and variable-types(custom constructor/destructor
instantiation of child nodes
Access control for individual nodes
Subscriptions
Support for subscriptions/monitoreditems for data change notifications
Very low resource consumption for each monitored value(event-based server architecture)
Code-Generation
Support for generating data types from standard XML definitions
Support for generating server-side information models(nodesets) from standard XMl definitions
Features on the roadmap for the 0.3 release series but missing in the initial v0. 3 release are
Encry pted communication in the client
Events(notifications emitted by objects, data change notifications are implemented
Event-loop(background tasks) in the client
1.3 Getting Help
For discussion and help besides this documentation, you can reach the open6254 1 community via
the mailing list
· our Irc channel
· the bugtracker
1.4 Contributing
As an open source project, we invite new contributors to help improve open62541. Issue reports, bugfixes and
new features are very welcome. The following are good starting points for new contributors
Report bugs
Improve the documentation
2
Chapter 1. Introduction
open62541 Documentation, Release 0.3. dev
Work on issues marked as easy hacks
1.4. Contributing
open62541 Documentation, Release 0.3. dev
Chapter 1. Introduction
CHAPTER
Building open62541
2.1 Building the Examples
USing the GCC compiler, the following calls build the examples on linux
p/path-tc/open62541*.# copy singie-file distr: but ion to the iocal directory
cp /path-tc/examples/server_variable c. copy the example server
gcc -std-c99 openc2541 c server variablec -o server
2.2 Building the Library
2.2.1 Building with CMake on Ubuntu or Debian
sudc apt-get install git buzld-essential gcc pkg-contig cmake python python-six
f enable addiLional eaLure
sudc apt-get install cmake-curses-gui for the ccmake graphical interface
dc apt-get install libmbedtls-dev for encryp
sudc apt-get install check for unit tests
sudc apt-get install python-sphinx graphviz t fcr documentation generation
cd cpen62541
f select additional features
make doc htmi documentation
nake doc_pdr pdr ciocumeniaLion (requires IdTeX
5
open62541 Documentation, Release 0.3. dev
2.2.2 Building with CMake on Windows
Here we explain the build process for Visual Studio(2013 or newer). To build with Ming w, just replace the
compiler selection in the call to CMake
Download and install
Python2.7.x(python3.xworksaswell):https://python.org/downloads
Install python-six with the pip package manager(pip install six)
CmakE:http://www.cmake.org/cmake/resources/software.html
MicrosoftVisualStudio:https://www.visualstudio.com/products/visual-studio-community-vs
Download the open I sources(using git or as a zipfile from github)
Open a command shell (cmd)and run
cd \openE254
mkdir build
cd build
\cmake. exe .. - Visual Studio 14 2015
You can useuse cmake-gui for a graphical uiser-interface tc seiect features
Then open buildopen62541 sln in Visual Studio 2015 and build as usual
2.2.3 Building on OS X
· Download and install
Xcodehttps://itunes.apple.com/us/app/xcode/id497799835?is=l&mt=12
He
omebrew:http://brew.sh/
Pip(a package manager for python, may be preinstalled): sudo easy install pip
Run the following in a shell
brew install cmake
f python 2/3 compatibility workarounds
pip insTall sphinx #for documentation generdLicn
pip install sphinx_rtdtheme documentation style
brew install grapaviz fcr graphics in the documentation
brew install check f for unit tests
brew install userspace-rcu for multi-threading support
Follow Ubuntu instructions without the apt-get commands as these are taken care of by the above packages
2.2.4 Building on Open BSD
The procedure below works on Open BSD 5. 8 with gcc version 4.8.4, cmake version 3. 2.3 and Python version
2.7.10.
Install a recent gcc, python and cmake
kg_add gcc py
Tell the system to actually use the recent gcc (it gets installed as egcc on OpenBSD)
export cc=egcc Cxx=eg++
Now procede as described for Ubuntu/Debian
6
Chapter 2. Building open62541
【实例截图】
【核心代码】