Last updated on April 10, 2022
This tutorial is separated into multiple posts and provides a complete walkthrough from creating a custom OPC UA information model, compiling this model into an OPC UA NodeSet2.xml file, and then using the open62541 OPC UA Stack to create a running OPC UA server.
Contents
Structure of the Tutorial
The guide is organized in several articles. Each article covers a single step of all steps required to generate a custom UANodeSet and run it on an open62541 server. All steps are linked here:
- Setup open62541 on Linux & Build first server
- Setup UA-ModelCompiler with Visual Studio
- Alternative: Setup UA-ModelCompiler on Linux
- Setup Visual Studio as ModelDesign Editor
- Alternative: Additional Software which can be used as ModelDesign Editor
- Alternative: Overview and Setup of OPC UA NodeSet Editors
- ModelDesign Explained – An Overview on the Concepts
- OPC UA ModelDesign Best Practices
- Writing a ModelDesign file
- Alternative: Edit UANodeSet files with Free OPCUA Modeler
- Compile ModelDesign to UANodeSet
- Connect Application Variables to open62541
- Compile open62541 server with custom UANodeSet
- Using UAExpert to connect to an OPC UA server
The articles are organized according to the following graph:
All steps are assigned to different stages (DESIGN
, EDITING
& APPLICATION
) of the complete process.
The steps in the top-half area (SETUP
) describe initial setup procedures of all required software tools.
The dotted (...
) paths in the guide mark an alternative workflow that substitutes the two-step process of editing ModelDesign files and compiling them to UANodeSet files with a single-step process of directly editing UANodeSet files. Pick either of both approaches. The result will be an UANodeSet file in both cases.
With all SETUP
steps completed, you can start MODELING
.
The steps in the bottom-half area (MODELING
) are horizontally aligned to their matching SETUP steps. They describe how to use the respective tools to design, edit and apply a custom UANodeSet.
The dash-dotted (-*-
) element in the MODELING
area of the graph indicates the process of associating the variables of the ModelDesign with the variables of the application program. While this step is absolutely necessary for any application of OPC UA, it’s not required for editing and testing OPC UA models.
Note
Once set up, this toolchain enables you to develop an OPC UA nodeset by frequently iterating on its design with little effort. If the target nodeset is already well defined, direct editing and compilation of the nodeset C99 source and header files may be more efficient. This is equal to omitting the DESIGN
and EDITING
stage and takeing the steps of the APPLICATION
stage only. See https://open62541.org/doc/current/tutorial_server_variable.html and it’s open62541 source code pendant tutorial_server_variable.c
for reference.
Tools
This walkthrough was implemented with the following tools:
- Windows 10 with Hyper-V
- Debian as Hyper-V guest
- Visual Studio 2019 Community Edition
- UAExpert
- git, bash and PowerShell
Whenever applicable, alternative solutions and tools will be mentioned. They are visualized in the following image and explained below:
This tutorial presents a Windows- and a Linux-based approach for step 2 and step 3 each. Deciding on the right approach for you boils down to answering the following questions:
- Do you prefer to edit and compile the ModelDesign on Windows/Visual Studio or Linux/IntelliJ?
- Do you prefer to use the offical UA-ModelCompiler or the author’s fork of UA-ModelCompiler?
On question 1:
There are 3 ways to convert a ModelDesign.xml to UANodeSet2.xml
- Docker:
- Linux-only
- The latest stable version of ModelCompiler
- UA-ModelCompiler is already compiled for you and ready to use
- Pro/UA-ModelCompiler:
- Linux or Windows
- the latest stable version of ModelCompiler
- you have to compile UA-ModelCompiler yourself on Windows or Linux (with Mono)
- OPCFoundation/UA-Modelcompiler:
- Linux or Windows
- the latest untested version of ModelCompiler
- you have to compile UA-ModelCompiler yourself on Windows or Linux (with Mono)
The answer to this question is a matter of personal preference. This tutorial recommends the Docker-approach.
On question 2:
Why is the author maintaining the fork https://github.com/Pro/UA-ModelCompiler of https://github.com/OPCFoundation/UA-ModelCompiler ?
The author’s fork is set up with a CI/CD chain for Docker and will make sure that its UA-ModelCompiler will be functional at any time. The fork was necessary, because https://github.com/OPCFoundation/UA-ModelCompiler tends to introduce breaking commits to its master branch occasionally.
Commonly used Reference Material
The following links expose the main resources used in this guide. More specific links will be provided throughout the guide.
- https://open62541.org/doc/current/
- https://github.com/open62541/open62541
- https://github.com/OPCFoundation/UA-ModelCompiler
- its submodule https://github.com/OPCFoundation/UA-Nodeset
- https://docs.microsoft.com/en-us/visualstudio/xml-tools/xml-tools-in-visual-studio?view=vs-2019
- OPC UA Standard Documents (Web and PDF format hold the same information, but PDF format requires a free account)
Credit
This tutorial is published with the kind permission of Harald Eschbach.
Start with Step 1
Be First to Comment