Learn open62541 --- [28] NodeSet interpretation

NodeSet is the meaning of node set. NodeSet can provide a set of set nodes, which users can directly use instead of recreating them by themselves. Each NodeSet has its own NameSpace.

This article mainly describes how NodeSet works in open62541 and how to use it.


A NodeSet provided by default by open62541

Open CMakeLists.txt in the root directory of open62541 source code and find the following statement

set(UA_NAMESPACE_ZERO "REDUCED" CACHE STRING "Completeness of the generated namespace zero (minimal/reduced/full)")
SET_PROPERTY(CACHE UA_NAMESPACE_ZERO PROPERTY STRINGS "MINIMAL" "REDUCED" "FULL")

You can see that the value of the variable UA_NAMESPACE_ZERO is REDUCED by default. At this time, execute in the build directory cmake .. && maketo generate open62541 related files. After the generation is completed, we return to the source root directory and execute the following command,

grep nodeset_compiler.py -r ./*

Because NodeSet must be converted into C code through the nodeset_compiler.py tool before it can be used. The location of this tool is open62541/tools/nodeset_compiler/

After searching through grep, we found the following statement, which is a compilation instruction generated by CMake. The
Insert picture description here
picture is a bit unclear. The key statements are as follows:

/usr/bin/python /home/wh/work/opcua/encryp/open62541/tools/nodeset_compiler/nodeset_compiler.py --internal-headers --ignore=/home/wh/work/opcua/encryp/open62541/tools/nodeset_compiler/NodeID_NS0_Base.txt --xml=/home/wh/work/opcua/encryp/open62541/tools/schema/Opc.Ua.NodeSet2.Minimal.xml /home/wh/work/opcua/encryp/open62541/build/src_generated/open62541/namespace0_generated

The kind of -xml parameter is followed by open62541/tools/schema/Opc.Ua.NodeSet2.Minimal.xml, which is the NodeSet provided by default by open62541. From the name, it can be seen that it is a castrated version (Minimal), as follows,
Insert picture description here
it will eventually The
Insert picture description here
two files, namespace0_generated.c and namespace0_generated.h, generated under open62541/build/src_generated/open62541/ provide a function,

UA_StatusCode namespace0_generated(UA_Server *server);

The main function of this function is to add the NodeSet described in Opc.Ua.NodeSet2.Minimal.xml to the OPC UA Server. This function will finally be called in UA_Server_new(). The calling sequence is as follows,

UA_Server_new() -> UA_Server_init() -> UA_Server_initNS0() ->namespace0_generated()

The final calling code is as follows, and the source can be seen from the comments.
Insert picture description here
If you choose MINIMAL (REDUCED was selected by default before), then UA_Server_minimalServerObject() in the above figure will be called to manually create the minimum number of NodeSets, which does not need to be used The nodeset_compiler.py parses the xml file, and there is no need for the xml file.


Two add a custom NodeSet

This is easy to understand if you have read this and this article.

What we use modeling software to create is a custom NodeSet, but here is a very important point to know: There are dependencies between NodeSets .

Some NodeSets are responsible for providing Nodes that everyone will use, such as Opc.Ua.NodeSet2.xml, and some NodeSets are responsible for providing Nodes in a certain field, such as Opc.Ua.Di.NodeSet2.xml, and the latter will rely on the former. The advantage of this is that it can make the structure clearer, and those who do professional fields can concentrate on their own fields.

When we customize NodeSet, we need to rely on Opc.Ua.NodeSet2.xml, this NodeSet provides a foundation. At this point, the castrated version of NodeSet provided by open62541 by default cannot meet your needs, and you need to use the full version (because it is custom, so I don’t know which parts of the basic NodeSet will be used by the user, so I simply ask you to use the full version. Opc.Ua.NodeSet2.Minimal.xml is not applicable).

Use the full version of the basic NodeSet

First change the value of UA_NAMESPACE_ZERO to FULL, and then execute the following command in the open62541 source code root directory,

git submodule update --init

This command will download 2 things, one is mdns-related library code (for LDS and LDS-ME), the other is nodeset, located at open62541/deps/ua-nodeset/,
Insert picture description here
Opc.Ua.NodeSet2.xml is located In the Schema directory,
Insert picture description here
open this file, and you can see the description of the Model at the beginning. The key parameter is ModelUri.

  <Models>
    <Model ModelUri="http://opcfoundation.org/UA/" Version="1.04" PublicationDate="2019-05-01T00:00:00Z" />
  </Models>

Three add professional direction NodeSet

In addition to the Schema directory under open62541/deps/ua-nodeset/, there are many other directories. These are specialized NodeSets, such as PLCopen, POWERLINK, etc.

When we need NodeSets for one or several professional directions, we can add them to the OPC UA Server. The specific operations are as follows, here is PLCopen as an example:

  1. Open the PLCopen directory, find Opc.Ua.Plc.NodeSet2.xml, then open and find the Models tab,
    Insert picture description here
    you can see that the ModelURI of PLCopen is http://PLCopen.org/OpcUa/IEC61131-3/. This NodeSet depends on the other 2 NodeSets , namely http://opcfoundation.org/UA/andhttp://opcfoundation.org/UA/DI/

  2. Open the DI directory, find Opc.Ua.Di.NodeSet2.xml, then open and find the Models tab,
    Insert picture description here
    so that we can figure out the dependency between NodeSet, that is, PLCopen depends on UA ​​and DI, and DI depends on UA

  3. Use nodeset_compiler.py to compile DI and PLCopen,

    /usr/bin/python /home/wh/work/opcua/encryp/open62541/tools/nodeset_compiler/nodeset_compiler.py --existing  /home/wh/work/opcua/encryp/open62541/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml  --xml=/home/wh/work/opcua/encryp/open62541/deps/ua-nodeset/DI/Opc.Ua.Di.NodeSet2.xml /home/wh/work/opcua/encryp/open62541/build/src_generated/open62541/namespace_di
    
    /usr/bin/python /home/wh/work/opcua/encryp/open62541/tools/nodeset_compiler/nodeset_compiler.py --existing  /home/wh/work/opcua/encryp/open62541/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml  --existing  /home/wh/work/opcua/encryp/open62541/deps/ua-nodeset/DI/Opc.Ua.Di.NodeSet2.xml --xml=/home/wh/work/opcua/encryp/open62541/deps/ua-nodeset/PLCopen/Opc.Ua.Plc.NodeSet2.xml  /home/wh/work/opcua/encryp/open62541/build/src_generated/open62541/namespace_plcopen
    

    The path in the command needs to be modified according to your actual situation. The absolute path is used here, or you can use a relative path. In addition, the existing parameter used in the command is used to indicate the dependent NodeSet. You can see that PLCopen uses 2 existing parameters.
    In the end, namespace_di.c/.h and namespace_plcopen.c/.h will be generated. For how to add them to the Server, please refer to the third section of this article . In fact, it is the same as custom NodeSet.

The OPC Foundation also provides many other NodeSets, such as Robotics, which can be downloaded on github at https://github.com/OPCFoundation/UA-Nodeset

In order to ensure stability, please select the Release version to download. After downloading and decompressing, you can put it under open62541/deps/ua-nodeset/. This operation can also be used to update the existing NodeSet.


Four small tips

NodeSet name

I saw that the description of NodeSet is in the xml file, and the final name of the xml file is NodeSet2. For this, you can read ReadMe on the https://github.com/OPCFoundation/UA-Nodeset webpage.
Insert picture description here

Interpretation of the content of the xml file

NodeSet uses an xml file for description, so how to interpret the xml content? You can refer to Annex F in the official document OPC UA Part 6-Mappings

NodeSet的NameSpace index

Each NodeSet has a NameSpace Index. This is related to the order of addition. UA is the basic NodeSet and will be added first, so its NameSpace Index is 0. Add 1 in the order of adding later.

But sometimes if you don’t know the order of addition, you don’t know its NameSpace Index. You can use the following code to get it

UA_UInt16 ns = UA_Server_addNamespace(server, "http://PLCopen.org/OpcUa/IEC61131-3/");

The second parameter of this function is the ModelUri in the xml file corresponding to the NodeSet. In addition, this function can be called repeatedly without causing repeated additions.

This also explains why the namespace index defined when using the modeling tool does not work. Although the namespace index is specified in the modeling tool, the index changes after being added to the server. This is because the index is determined by the order of addition. , So it is recommended to use UA_Server_addNamespace() to re-determine the index


Five summary

This article mainly describes the meaning of NodeSet and how to use it in open62541. Once you know NodeSet, you can add any NodeSet at will.

If there is something wrong with the writing, I hope to leave a message to correct it, thank you for reading.

Guess you like

Origin blog.csdn.net/whahu1989/article/details/105747384
28