pyUANamespace
=============
pyUANamespace is a collection of python 2 scripts that can parse OPC UA XML Namespace definition files and transform them into a class representation. This facilitates both reprinting the namespace in a different non-XML format (such as C-Code or DOT) and analysis of the namespace structure.
### Documentation
The pyUANamespace implementation has been contributed by a research project of the chair for Process Control Systems Engineering of the TU Dresden. It was not strictly speaking created as a C generator, but could be easily modified to fullfill this role for open62541.
## Functionality in open62541
In open62541, the linked python namespace generated by the pyUANamespace classes are used to print C-Code that will automatically initialize a server. Apart from parsing XML, most classes also have a printOpen62541Header() or printOpen62541Header_Subtype() function that can reprint the node as C Code compatible with the project.
This function has been wrapped into the generate_open62541CCode.py program, which implements the compiler and option checking relevant to this task. The program is called as follows:
```bash
$ python generate_open62541CCode.py /path/to/NodeSet.xml /path/to/outputfile.c
```
Several options have been made available to further facilitate header generation. Calling the script without arguments will produce a usage helper listing all available options.
# Overwriting NodeSet definitions
Most notably, any number of XML files can be passed. The latest XML definition of a node found is used.
```bash
$ python generate_open62541CCode.py /path/to/NodeSet0.xml /path/to/OverwriteNodeSet0.xml /path/to/outputfile.c
```
# Blacklisting Nodes
If a set of nodes is not to be contained in the namespace, they can be specified as a blacklist file containing one nodeId per line in the following format:
```
ns=1;id=2323
id=11122;
```
This file can be passed to the compiler, which will remove these nodes prior to linking the namespace.
```bash
$ python generate_open62541CCode.py -b blacklist.txt /path/to/NodeSet.xml /path/to/outputfile.c
```
In this particular example, nodes `ns=1;id=2323` and `ns=0;id=11122` will be removed from the namespace (which may invalidate other nodes referring to them).
# Ignoring Nodes
Blacklisting removes nodes, which means that any other nodes referring to these nodes will contain invalid references. If a namespace should be generated that can use all datatypes, objectstypes, etc., but should only print specific nodes into the C Header, a set of nodes can be ignored. This will cause the compiler to use them in the linked namespace where other nodes can use them (e.g. in buildEncodingRules()), but they will not appear as part of the header file.
Ignorelists have the same format as blacklists and are passed to the compiler like so:.
```bash
$ python generate_open62541CCode.py -i ignorelist.txt /path/to/NodeSet.xml /path/to/outputfile.c
```
Given the blacklist example, the nodes `ns=1;id=2323` and `ns=0;id=11122` will not be part of the header, but other nodes may attempt to create references to them or use them as dataTypes.
# Supressing attributes
Most of OPC UA Namespaces depend heavily on strings. These can bloat up memory usage in applications where memory is a critical resource. The compiler can be instructed to suppress allocation for certain attributes, which will be initialized to sensible defaults or NULL pointers where applicable.
```bash
$ python generate_open62541CCode.py -s browsename -s displayname -s nodeid /path/to/NodeSet.xml /path/to/outputfile.c
```
Currently, the following base attributes of nodes can be suppressed:
- browseName
- displayName
- description
- nodeId
- writeMask
- userWriteMask
Further attributes may be added at a later point depending on demand.
## Core functionality
OPC UA node types, base data types and references are described in ua_node_types.py and ua_builtin_types.py. These classes are primarily intended to act as part of an AST to parse OPC UA Namespace description files. They implement a hierarchic/rekursive parsing of XML DOM objects, supplementing their respective properties from the XML description.
A manager class called ua_namespace is included in the respective source file. This class does _not_ correspond to a OPC UA Namespace. It is an aggregator and manager for nodes and references which may belong to any number of namespaces. This class includes extensive parsing/validation to ensure that a complete and consistent namespace is generated.
## Namespace compilation internals
Compiling a namespace consists of the following steps:
- Read one or more XML definitions
- Link references to actual nodes (also includes references to dataTypes, etc.)
- Sanitize/Remove any nodes and references that could not be properly parsed
- Derive encoding rules for datatypes
- Parse/Allocate variable values according to their dataType definitions
Reading and parsing XML files is handled by ua_namespace.parseXML(/path/to/file.xml). It is the first part of a multipass compiler that will create all nodes contained in the XML description.
During the reading of XML files, nodes will attempt to parse any attributes they own, but not refer to any other nodes. References will be kept as XML descriptions. Any number of XML files can be read in this phase. __NOTE__: In the open62541 (this) implementation, duplicate nodes (same NodeId) are allowed. The last definition encountered will be kept. This allows overwriting specific nodes of a much larger XML file to with implementation specific nodes.
The next phase of the compilation is to link all references. The phase is called by ua_namespace.linkOpenPointers(). All references will attempt to locate their target() node in the namespace and point to it.
During the sanitation phase called by ua_namespace.sanitize(), nodes check themselves for invalid attributes. Most notably any references that could not be resolved to a node will be removed from the nodes.
When calling ua_namespace.buildEncodingRules(), dataType nodes are examined to determine if and how the can be encoded as a serialization of OPC UA builtin types as well as their aliases.
The following fragment of a variable value can illustrate the necessity for determining encoding rules:
```xml
<Argument>
<Name>ServerHandles</Name>
<DataType>
<Identifier>i=7</Identifier>
</DataType>
<ValueRank>1</ValueRank>
<ArrayDimensions />
<Description p5:nil="true" xmlns:p5="http://www.w3.org/2001/XMLSchema-instance" />
</Argument>
```
The tags body, TypeId, Identifier, and Argument are aliases for builtin encodings or structures thereof. Without knowing which type they represent, an appropriate value class (and with that a parser) cannot be created. pyUANamespace will resolve this specific case by determining the encoding as follows:
```
LastMethodOutputArguments : Argument -> i=296
+ [['Name', ['String']], ['DataType', ['NodeId']], ['ValueRank', ['Int32']], ['ArrayDimensions', ['UInt32']], ['Description', ['LocalizedText']]] (already analyzed)
```
DataTypes that cannot be encoded as a definite serial object (e.g. by having a member of NumericType, but not a specific one), will have their isEncodable() attribute disabled. All dataTypes that complete this node can be used to effectively determine the size and serialization properties of any variables.
Having encoding rules means that data can now be parsed when a <Value> tag is encountered in a description. Calling ua_namespace.allocateVariables() will do just that for any variable node that holds XML Values.
The result of this compilation is a completely linked and instantiated OPC UA namespace.
An example compiler can be built as follows:
```python
class testing:
def __init__(self):
self.namespace = opcua_namespace("testing")
log(self, "Phase 1: Reading XML file nodessets")
self.namespace.parseXML("Opc.Ua.NodeSet2.xml")
self.namespace.parseXML("D
没有合适的资源?快使用搜索试试~ 我知道了~
open62541-open62541-0.2-rc2-0-g243237e.zip_OPC UA C_UAClient_c++
共181个文件
c:66个
h:31个
py:15个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 16 浏览量
2022-07-15
18:15:02
上传
评论
收藏 609KB ZIP 举报
温馨提示
open62541 OPC UA SDK for Client and Server
资源详情
资源评论
资源推荐
收起资源包目录
open62541-open62541-0.2-rc2-0-g243237e.zip_OPC UA C_UAClient_c++ (181个子文件)
AUTHORS 385B
Opc.Ua.Types.bsd 139KB
Custom.Opc.Ua.Transport.bsd 4KB
ua_server.c 66KB
ua_services_nodemanagement.c 60KB
ua_types_encoding_binary.c 57KB
check_types_builtin.c 53KB
check_services_attributes.c 49KB
ua_services_attribute.c 46KB
ua_client.c 35KB
ua_types.c 34KB
ua_server_binary.c 26KB
ua_services_view.c 26KB
ua_server_worker.c 25KB
ua_services_subscription.c 25KB
ua_network_tcp.c 25KB
ua_subscription.c 23KB
server.c 17KB
ua_securechannel.c 16KB
ua_client_highlevel.c 15KB
ua_client_highlevel_subscriptions.c 13KB
client.c 12KB
check_nodestore.c 10KB
ua_server_utils.c 9KB
ua_nodestore.c 9KB
ua_connection.c 9KB
ua_network_udp.c 8KB
check_types_memory.c 8KB
ua_services_call.c 8KB
ua_nodestore_concurrent.c 8KB
server_method.c 8KB
ua_services_session.c 7KB
ua_nodes.c 7KB
ua_securechannel_manager.c 7KB
check_utils.c 7KB
server_inheritance.c 6KB
ua_services_discovery.c 5KB
check_client_subscriptions.c 5KB
check_services_nodemanagement.c 5KB
check_services_subscriptions.c 5KB
check_chunking.c 4KB
ua_session.c 4KB
ua_config_standard.c 4KB
ua_session_manager.c 4KB
server_instantiation.c 4KB
server_readspeed.c 3KB
check_types_range.c 3KB
server_datasource.c 3KB
server_variable.c 3KB
server_certificate.c 2KB
libc_time.c 2KB
ua_services_securechannel.c 2KB
server_mainloop.c 2KB
check_server_jobs.c 2KB
check_session.c 2KB
check_server_binary_messages.c 2KB
ua_clock.c 2KB
check_client.c 2KB
server_udp.c 2KB
server_nodeset.c 2KB
check_services_view.c 2KB
client_firstSteps.c 2KB
pcg_basic.c 1KB
server_repeated_job.c 1KB
ua_log_stdout.c 1KB
testing_networklayers.c 1KB
check_server_userspace.c 1KB
server_firstSteps.c 905B
libc_string.c 850B
Toolchain-mingw32.cmake 3KB
Toolchain-mingw64.cmake 2KB
FindCheck.cmake 2KB
Toolchain-rpi.cmake 560B
Toolchain-rpi64.cmake 538B
FindSphinx.cmake 286B
Toolchain-gcc-m32.cmake 175B
localhost.cnf 11KB
server.cpp 2KB
NodeIds.csv 339KB
Opc.Ua.StatusCodes.csv 21KB
Dockerfile 287B
.gitignore 878B
ua_server.h 35KB
ua_types.h 31KB
ua_constants.h 31KB
ua_client_highlevel.h 29KB
queue.h 22KB
ua_services.h 14KB
ua_nodes.h 14KB
ua_client.h 14KB
ua_server_internal.h 9KB
ms_stdint.h 8KB
ua_connection.h 6KB
ua_session.h 5KB
ua_server_external_ns.h 5KB
ua_securechannel.h 5KB
ua_subscription.h 4KB
ua_log.h 4KB
ua_nodestore.h 3KB
ua_util.h 2KB
共 181 条
- 1
- 2
寒泊
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0