Skip to content

Step 7: Compile the ModelDesign file with UA-ModelCompiler

Last updated on April 10, 2022


Compile the ModelDesign file to UANodeSet and auxiliar files.

This Post is part of the OPC UA Information Model Tutorial.


Compile ModelDesign

Use my provided example ModelDesign file to test your compiler setup. Download this file:

https://github.com/Pro/opcua-modeling-tutorial/blob/master/FooFltModel.xml

Now, depending if you are on windows, you need to have your own compiled Version of the UA-Model Compiler (see this Post).
On Linux you can use the precompiled Docker Container to compile the ModelDesign file, as described in this Post.

The resulting files are also available on Github in the master-published branch:

https://github.com/Pro/opcua-modeling-tutorial/tree/master-published/Published/FooFlt

First compile the UA-Model compiler as described here. Make sure to complete the section Required: Make UA-ModelCompiler to compile AnalogItemType at the end of this article before proceeding.

Then use PowerShell (or any other console) to compile the model:

# Windows PowerShell
# Copyright (C) Microsoft Corporation. All rights reserved.
# 
# PS X:\>
cd C:\FLT_SW\UA-ModelCompiler\Bin\Release

# PS C:\FLT_SW\UA-ModelCompiler\Bin\Release>
.\Opc.Ua.ModelCompiler.exe `
-d2 C:\FLT_SW\Wiki\OpcUa\documents\FooFltModel.xml `
-cg C:\FLT_SW\Wiki\OpcUa\documents\FooFltModel\FooFltModel.csv `
-o2 C:\FLT_SW\Wiki\OpcUa\documents\FooFltModel `
-console

# PS C:\FLT_SW\UA-ModelCompiler\Bin\Release>
dir C:\FLT_SW\Wiki\OpcUa\documents\FooFltModel\

This will give you the following files:

    Directory: C:\FLT_SW\Wiki\OpcUa\documents\FooFltModel


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       12.03.2020     14:30          36368 FooFlt.Classes.cs
-a----       12.03.2020     14:30          24740 FooFlt.Constants.cs
-a----       12.03.2020     14:30           8651 FooFlt.DataTypes.cs
-a----       12.03.2020     14:30          65702 FooFlt.NodeSet.xml
-a----       12.03.2020     14:30          21616 FooFlt.NodeSet2.xml
-a----       12.03.2020     14:30           5009 FooFlt.PredefinedNodes.uanodes
-a----       12.03.2020     14:30          35953 FooFlt.PredefinedNodes.xml
-a----       12.03.2020     14:30            701 FooFlt.Types.bsd
-a----       12.03.2020     14:30           1117 FooFlt.Types.xsd

On Linux you can either use the precompiled Docker Container or compile the UA-ModelCompiler on your own. More details are described here.
The following instruction is for the simpler Docker Container usage:

cd opcua-modeling-tutorial
docker run \
	  --mount type=bind,source=$(pwd),target=/model/src \
	  --entrypoint "/app/PublishModel.sh" \
	  sailavid/ua-modelcompiler \
	   /model/src/FooFltModel FooFlt /model/src/Published

The same command is also used to automatically build the ModelDesign on Github. Therefore your resulting files should be identical to these:

https://github.com/Pro/opcua-modeling-tutorial/tree/master-published/Published/FooFlt

At this point, you have successfully compiled a ModelDesign to an UANodeSet.

Files such as Types.bsd and Nodes.csv are auxiliar files used by nodeset_compiler.py as indicated by https://open62541.org/doc/current/nodeset_compiler.html

You can use UAModeler to check consistency.

Note: UAModeler can not open UANodeSet files by default. You have to create a new “modeling only” project and include FooZebraCompression.xml

When trying to compile a ModelDesign with an AnalogItemTyp it will fail as follows:

PS C:\FLT_SW\UA-ModelCompiler\Bin\Release> .\Opc.Ua.ModelCompiler.exe `
>> -d2 C:\FLT_SW\Wiki\OpcUa\documents\FooFltModel.xml `
>> -cg C:\FLT_SW\Wiki\OpcUa\documents\FooFltModel\FooFltModel.csv `
>> -o2 C:\FLT_SW\Wiki\OpcUa\documents\FooFltModel `
>> -console
Could not load resource 'Opc.Ua.ModelCompiler.Design.BuiltInTypes.xml'.
   at Opc.Ua.Schema.SchemaValidator.LoadResource(Type type, String path, Assembly assembly) in C:\FLT_SW\UA-ModelCompiler\Core\Types\Schemas\SchemaValidator.cs:line 303
   at Opc.Ua.ModelCompiler.ModelCompilerValidator.LoadBuiltInModel() in C:\FLT_SW\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 800
   at Opc.Ua.ModelCompiler.ModelCompilerValidator.LoadBuiltInTypes() in C:\FLT_SW\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 101
   at Opc.Ua.ModelCompiler.ModelCompilerValidator.Validate2(IList`1 designFilePaths, String identifierFilePath, Boolean generateIds) in C:\FLT_SW\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 972
   at Opc.Ua.ModelCompiler.ModelGenerator2.ValidateAndUpdateIds(IList`1 designFilePaths, String identifierFilePath, UInt32 startId, String specificationVersion) in C:\FLT_SW\UA-ModelCompiler\ModelCompiler\ModelGenerator2.cs:line 96
   at Opc.Ua.ModelCompiler.Program.ProcessCommandLine2(List`1 tokens) in C:\FLT_SW\UA-ModelCompiler\ModelCompiler\Program.cs:line 424
PS C:\FLT_SW\UA-ModelCompiler\Bin\Release>

A workaround is suggested in https://github.com/OPCFoundation/UA-ModelCompiler/issues/46 with the following diff:

johndoe@winpc MINGW64 /c/FLT_SW/test/UA-ModelCompiler ((8817477...))
$ git diff
diff --git a/ModelCompiler/ModelDesignerValidator.cs b/ModelCompiler/ModelDesignerValidator.cs
index 5d5da75..7da31be 100644
--- a/ModelCompiler/ModelDesignerValidator.cs
+++ b/ModelCompiler/ModelDesignerValidator.cs
@@ -52,7 +52,7 @@ namespace Opc.Ua.ModelCompiler
         {
             m_context = ServiceMessageContext.GlobalContext;
             m_startId = startId;
-            EmbeddedResourcePath = "Opc.Ua.ModelCompiler.Design";
+            EmbeddedResourcePath = "Opc.Ua.ModelCompiler.Design.v104";
         }
         #endregion

After introducing that change, clean and rebuild the UA-ModelCompiler solution with Visual Studio. Opc.Ua.ModelCompiler.exe will now succeed to compile ModelDesign files that use AnalogItemType.

Published inInformation Modeling

14 Comments

  1. Fridolin Fridolin

    Hey there, I get an error when starting the compiler, following your instructions for windows, and using exactly your files: “The TypeDefinition reference for node ApeType_MyVariable3 is not valid: AnalogUnitRangeType.
    at Opc.Ua.ModelCompiler.ModelCompilerValidator.FindNode(XmlQualifiedName sym
    bolicId, Type requiredType, String sourceName, String referenceName) in C:\Users\XKh\Desktop\Fridolin\OPCUA\OPCUA.rocks\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:Zeile 3521. […]”

    Does this have to do with using branch v1.04 and not master?

    • Fridolin Fridolin

      …Is the branch master already used, before entering those two lines you suggest in step 2?:
      “git branch -a
      git checkout v1.04”,
      or is there anything else to do, to use it?

      • Benedict Simlinger Benedict Simlinger

        Hi Fridolin,

        your comment prompted me to revisit
        https://github.com/OPCFoundation/UA-ModelCompiler

        Please note:

        1) The maintainer of UA-ModelCompiler claims that the issue, that made me change to branch ‘v1.04’ initially, is fixed by now.
        https://github.com/OPCFoundation/UA-ModelCompiler/issues/46#issuecomment-615938876
        Consequently, you should be able to work with ‘master’, without the workaround from
        https://github.com/OPCFoundation/UA-ModelCompiler/issues/46#issuecomment-603875272
        which I used in this post.

        2) The UA-Nodeset submodule was removed
        https://github.com/OPCFoundation/UA-ModelCompiler/commit/408bc5f60b0afffd3291f841babe04242cffdb97
        from UA-ModelCompiler and (instead?) the NETStandard submodule was added
        https://github.com/OPCFoundation/UA-ModelCompiler/commit/00c8d5465f4356db7ea6199e933acccf5187c8dd

        Considering those two points, I don’t recommend following my documentation to the letter anymore, since the ‘master’ branch of UA-ModelCompiler has changed in a significant way by now.

        I don’t know when I will find the time to update the documentation accordingly. Until then, you have to rely on your own troubleshooting skills.

        • Benedict Simlinger Benedict Simlinger

          But long story short, you should try with ‘master’. It’s impossible to make it work with branch ‘v1.04’ for reasons mentioned in exactly this post.

          • Fridolin Fridolin

            Hey Benedict!
            Thanks again for your intensive research on this topic.
            After a little while I finally could compile the example FooFltModel.xml-file. As I changed FooZbrFlt:MyVariable3 and 4 to AnalogItemType (3 from AnalogUnitRangeType and 4 from AnalogUnitTyoe) I could even compile it using branch v1.04.

            What led to this?
            So my biggest mistake was really to not check the pathes properly: I didn’t even have the folder that I used instead “FooFltModel” in the path “C:\FLT_SW\Wiki\OpcUa\documents\FooFltModel” (relating to line 11 under Compile Instructions in this file). I just had organized the data a little different.
            By the way, I checked my commit ID, and it’s the same that you were using.
            Next, the workaround suggested for branch master didn’t work right away, but updating that line
            EmbeddedResourcePath = “Opc.Ua.ModelCompiler.Design.v104”;
            worked for me.
            Also, I seemed to have a problem with my .NET Framework, when I tried to compile on branch master. Updating to the right version was irritating complicated and I don’t understand what was making it work in the end, but now it seems that Version 4.6.2 is running properly.

            I’m somehow new to coding and stuff, and I had a mentor helping me with this very much. We ran some of the bat.files as well, and he did much debugging which I couldn’t follow in every detail. But I think that this were the biggest issues!

        • Fridolin Fridolin

          Hi Benedict,
          thanks a lot for your quick answer and the whole tutorial, which is very helpful.
          So I will test my own troubleshooting skills 🙂 Should I succeed I will let you know ^^
          stay healthy!

          • Benedict Simlinger Benedict Simlinger

            Hi Fridolin,

            your question made me setup the toolchain again and have a go at it myself.

            My target is, to compile FooFltModel.xml from
            https://github.com/Pro/opcua-modeling-tutorial/tree/master
            as instructed in this post.

            Here is what i did (copy the comment to a text editor for better readability):

            [TLDR at the end]

            ==========

            Checkout UA-ModelCompiler, current ‘master’.
            At the time of writing that is commit 3754f9bb141b33d0f2a32cad984795295a060782

            ==========

            I DO NOT apply the fix as recommended in “Recommended: Make UA-ModelCompiler master branch work to compile AnalogItemType” this post,
            because the maintainer claims that this is fixed
            https://github.com/OPCFoundation/UA-ModelCompiler/issues/46#issuecomment-615938876
            (Spoiler: it seems not)

            Build UA-ModelCompiler in Release configuration as instructed in this guide.
            That worked and resulted in C:\UA-ModelCompiler\Bin\Release\Opc.Ua.ModelCompiler.exe

            ==========

            !!! ATTENTION: This is new !!!

            Following the advice from
            https://github.com/OPCFoundation/UA-ModelCompiler/issues/59#issuecomment-695170371
            I run
            git cerry-pick 19c669ec9c63ef05e7b12483ff97a90517a7a63d
            to successfully run

            PS C:\UA-ModelCompiler> .\BuildStandardTypes.bat

            and

            PS C:\UA-ModelCompiler> .\BuildEngineeringUnits.bat

            Without that cherry-pick, execution of .\BuildStandardTypes.bat will throw an error.

            ==========

            Let us be naive/positive and try to build:

            PS C:\UA-ModelCompiler\Bin\Release> .\Opc.Ua.ModelCompiler.exe -d2 C:\opcua-modeling-tutorial\FooFltModel.xml -cg C:\opcua-modeling-tutorial\FooFltModel.csv -o2 C:\opcua-modeling-tutorial\FooFltModel -console
            Could not load resource ‘ModelCompiler.Design.BuiltInTypes.xml’.
            at Opc.Ua.Schema.SchemaValidator.LoadResource(Type type, String path, Assembly assembly) in C:\UA-ModelCompiler\Stack\Stack\Opc.Ua.Core\Types\Schemas\SchemaValidator.cs:line 276
            at ModelCompiler.ModelCompilerValidator.LoadBuiltInModel() in C:\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 802
            at ModelCompiler.ModelCompilerValidator.LoadBuiltInTypes() in C:\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 103
            at ModelCompiler.ModelCompilerValidator.Validate2(IList`1 designFilePaths, String identifierFilePath, Boolean generateIds) in C:\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 974
            at ModelCompiler.ModelGenerator2.ValidateAndUpdateIds(IList`1 designFilePaths, String identifierFilePath, UInt32 startId, String specificationVersion) in C:\UA-ModelCompiler\ModelCompiler\ModelGenerator2.cs:line 95
            at ModelCompiler.Program.ProcessCommandLine2(List`1 tokens) in C:\UA-ModelCompiler\ModelCompiler\Program.cs:line 424

            This error is known and discussed in this post at “Recommended: Make UA-ModelCompiler master branch work to compile AnalogItemType”

            BUT: Instead of applying the fix, I discoverd the new “-version” flag of Opc.Ua.ModelCompiler.exe (that flag did not exist when i wrote this guide)!
            Lets try those first.

            ==========

            using -version v104 fails

            PS C:\UA-ModelCompiler\Bin\Release> .\Opc.Ua.ModelCompiler.exe -d2 C:\opcua-modeling-tutorial\FooFltModel.xml -cg C:\opcua-modeling-tutorial\FooFltModel.csv -o2 C:\opcua-modeling-tutorial\FooFltModel -console -version v104
            Could not find a part of the path ‘C:\opcua-modeling-tutorial\FooFltModel\FooFlt.Constants.cs’.
            at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
            at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
            at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
            at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
            at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
            at System.IO.StreamWriter..ctor(String path, Boolean append)
            at ModelCompiler.ModelGenerator2.WriteTemplate_ConstantsSingleFile(String filePath, List`1 nodes) in C:\UA-ModelCompiler\ModelCompiler\ModelGenerator2.cs:line 1871
            at ModelCompiler.ModelGenerator2.GenerateMultipleFiles(String filePath, Boolean useXmlInitializers, String[] excludedCategories, Boolean includeDisplayNames) in C:\UA-ModelCompiler\ModelCompiler\ModelGenerator2.cs:line 129
            at ModelCompiler.Program.ProcessCommandLine2(List`1 tokens) in C:\UA-ModelCompiler\ModelCompiler\Program.cs:line 449

            ==========

            using -version v103 (for the sake of completeness) fails

            PS C:\UA-ModelCompiler\Bin\Release> .\Opc.Ua.ModelCompiler.exe -d2 C:\opcua-modeling-tutorial\FooFltModel.xml -cg C:\opcua-modeling-tutorial\FooFltModel.csv -o2 C:\opcua-modeling-tutorial\FooFltModel -console -version v103
            The TypeDefinition reference for node ApeType_MyVariable3 is not valid: AnalogUnitRangeType.
            at ModelCompiler.ModelCompilerValidator.FindNode(XmlQualifiedName symbolicId, Type requiredType, String sourceName, String referenceName) in C:\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 3639
            at ModelCompiler.ModelCompilerValidator.ValidateInstance(InstanceDesign instance) in C:\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 3480
            at ModelCompiler.ModelCompilerValidator.Validate(NodeDesign node) in C:\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 3218
            at ModelCompiler.ModelCompilerValidator.Validate(NodeDesign node) in C:\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 3222
            at ModelCompiler.ModelCompilerValidator.ValidateDictionary(ModelDesign dictionary) in C:\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 857
            at ModelCompiler.ModelCompilerValidator.Validate2(IList`1 designFilePaths, String identifierFilePath, Boolean generateIds) in C:\UA-ModelCompiler\ModelCompiler\ModelDesignerValidator.cs:line 1110
            at ModelCompiler.ModelGenerator2.ValidateAndUpdateIds(IList`1 designFilePaths, String identifierFilePath, UInt32 startId, String specificationVersion) in C:\UA-ModelCompiler\ModelCompiler\ModelGenerator2.cs:line 95
            at ModelCompiler.Program.ProcessCommandLine2(List`1 tokens) in C:\UA-ModelCompiler\ModelCompiler\Program.cs:line 424

            Oh! That is the same error message as yours! i recommend you investigate the versions / commit IDs you are using.

            ==========

            I decide to apply the fix
            EmbeddedResourcePath = “Opc.Ua.ModelCompiler.Design.v104”;
            recompile Opc.Ua.ModelCompiler.exe and try again (without version flag)

            PS C:\UA-ModelCompiler\Bin\Release> .\Opc.Ua.ModelCompiler.exe -d2 C:\opcua-modeling-tutorial\FooFltModel.xml -cg C:\opcua-modeling-tutorial\FooFltModel.csv -o2 C:\opcua-modeling-tutorial\FooFltModel -console
            Could not find a part of the path ‘C:\opcua-modeling-tutorial\FooFltModel\FooFlt.Constants.cs’.
            at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
            at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
            at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
            at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
            at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
            at System.IO.StreamWriter..ctor(String path, Boolean append)
            at ModelCompiler.ModelGenerator2.WriteTemplate_ConstantsSingleFile(String filePath, List`1 nodes) in C:\UA-ModelCompiler\ModelCompiler\ModelGenerator2.cs:line 1871
            at ModelCompiler.ModelGenerator2.GenerateMultipleFiles(String filePath, Boolean useXmlInitializers, String[] excludedCategories, Boolean includeDisplayNames) in C:\UA-ModelCompiler\ModelCompiler\ModelGenerator2.cs:line 129
            at ModelCompiler.Program.ProcessCommandLine2(List`1 tokens) in C:\UA-ModelCompiler\ModelCompiler\Program.cs:line 449

            So it seems the fix has the same effect as using -version v104

            ==========

            I undo the fix (in order to not taint any future tests) and pause my investigation.

            ==========

            TLDR:
            * Your error messsage looks like you are using v103 somewhere. Consolidate your versions before proceeding.
            * UA-ModelCompiler ‘master’ changed in a way that broke the functioning workflow that was documented here 🙁

            Hopefully you gain any insight from my tests that help you find a solution.

    • Benedict Simlinger Benedict Simlinger

      Hi Fridolin,

      I am replying to your initial commit for visibility.

      I have investigated the issue and decided to pin this tutorial to commit
      8817477c7b481fd6eb6e9cccc05b76e83c7329ba
      of UA-ModelCompiler.

      Using the master branch as reference in this guide is not viable, because the maintainer of UA-ModelCompiler is introducing breaking changes to master without consideration. Referencing master in this tutorial would force us to keep this tutorial up-to-date with master at all time.

      Using branch v.104 of UA-ModelCompiler is not optimal either, because the last commit to branch v1.04 is from 2018. It’s missing a lot of fixes and improvements.

      Therefore I selected the latest commit on master, which is still compatible with this tutorial.

      I updated all articles in this tutorial accordingly.

  2. Kishan Gupta Kishan Gupta

    I am using nodeset compiler to compile nodeset2.xml schema. I am able to generate .c and .h files successfully. But when I am running the executable file of the server it is showing an error….

    kishan@kishan:~/nodeset2_test$ ./nodeset2_server
    [2021-01-12 12:49:09.680 (UTC+0100)] warn/server AccessControl: Unconfigured AccessControl. Users have all permissions.
    [2021-01-12 12:49:09.680 (UTC+0100)] info/server AccessControl: Anonymous login is enabled
    [2021-01-12 12:49:09.680 (UTC+0100)] warn/server Username/Password configured, but no encrypting SecurityPolicy. This can leak credentials on the network.
    [2021-01-12 12:49:09.680 (UTC+0100)] warn/userland AcceptAll Certificate Verification. Any remote certificate will be accepted.
    [2021-01-12 12:49:09.680 (UTC+0100)] info/session SecureChannel 0 | Session g=00000001-0000-0000-0000-000000000000 | AddNode (ns=2;i=6): Parent node not found
    [2021-01-12 12:49:09.680 (UTC+0100)] info/session SecureChannel 0 | Session g=00000001-0000-0000-0000-000000000000 | AddNode (ns=2;i=6): The parent reference for is invalid
    [2021-01-12 12:49:09.680 (UTC+0100)] error/server Could not add the example nodeset.

    How to solve it?

    • Benedict Simlinger Benedict Simlinger

      Hi,

      the last two lines are the relevant ones. I guess that node ns=2;i=6 is the root node of your model.
      The root node of your model must reference a node from the OPC UA server as parent, so that OPC UA clients know where to find it.

      I recommend you revisit the example models on Github [1] reference in step 6 [2].
      More specifically, look at the code snippet, which references the “Objects” folder of the server as parent to the instance of the example’s root node [3]

      Your take away messages should be:

      1) You can’t just instantiate OPC UA variables into “void”. They will will always need a parent reference. For the root node of your models, that should be a variable from the OPC UA server model.

      2) Make sure to test your models at runtime! Successfully compiling a model only proves syntactical correctness but can’t uncover any runtime issues such as the one experienced by you just now.

      Let us know if/how you solved your problem.

      Kind regards

      [1] https://github.com/pro/opcua-modeling-tutorial
      [2] https://opcua.rocks/step-6-writing-a-modeldesign-file/
      [3] https://github.com/Pro/opcua-modeling-tutorial/blob/e4ee828b0971105009be8a98daecb71dca6a3b54/FooFltModel.xml#L168

      • Kishan Gupta Kishan Gupta

        Hello Benedict,
        Even for a simple nodeset2.xml it is showing the same error.
        <UAObjectType NodeId=”ns=1;i=0″ BrowseName=”1:TestServer”>
        <DisplayName>TestServer</DisplayName>
        <References>
        <Reference ReferenceType=”HasSubtype” IsForward=”false”>i=58</Reference>
        <Reference ReferenceType=”HasComponent”>ns=1;i=1</Reference>
        </References>
        </UAObjectType>
        <UAVariable NodeId=”ns=1;i=1″ BrowseName=”1:Device” ParentNodeId=”ns=1;i=0″ DataType=”String”>
        <DisplayName>Device</DisplayName>
        <References>
        <Reference ReferenceType=”HasComponent” IsForward=”false”>ns=1;i=0</Reference>
        <Reference ReferenceType=”HasTypeDefinition”>i=63</Reference>
        <Reference ReferenceType=”HasModellingRule”>i=78</Reference>
        </References>
        </UAVariable>
        Could you help please help me to figure that out?
        Thanks in advance

  3. Stormbringer Stormbringer

    I have a basic question, sorry for my ignorance! 🙂

    What is the main motivation for compiling the model into source code?

    • Benedict Simlinger Benedict Simlinger

      Hi,

      we have to generate/compile the model to C source code, so that it can be used by the open62541 server at runtime. Have a look at “Adding Variables to a Server” from the official open62541 documentation[1] or this resolved github issue [2] if you want to learn how to add variables at runtime. Either way, you will ALWAYS end up with some C code.

      This is the answer to your question. Anything that follows is additional information & context related to your question.

      Coding OPC UA models by hand in C is very cumbersome for more than a few variables. Consequently, the OPC Foundation allows you to describe your model in the NodeSet2.xml format. That’s why there are several NodeSet2.xml editors available [3].

      Now, if you open such a NodeSet2.xml file with a simple text editor and inspect it (I recommend you do that for educational purposes) you will recognize some parts of your model in that file, but it’s quite convoluted and hard to parse as a human. The ModelDesign.xml format solves this problem. It is much more human-readable while holding the same information. [4] Note, that the ModelDesign.xml format is not an official format of the OPC UA standard (only NodeSet2.xml is) but that ModelDesign.xml is used by the OPC Foundation itself to generate the official OCP UA nodesets. [5]

      Why am I adding so much information to your simple question? Because this whole tutorial is exactly about the conversion of ModelDesign -> NodeSet2 -> C code With that in mind, I recommend you revisit the drawings at the very first article of this tutorial.
      Kind regards!

      [1] https://open62541.org/doc/current/tutorial_server_variable.html
      [2] https://github.com/open62541/open62541/issues/2501
      [3] https://opcua.rocks/step-3-opc-ua-nodeset-editor-overview/
      [4] Compare the ModelDesign.xml (180 lines of code) and it’s equivalent NodeSet2.xml (1200 lines of code!) for example.
      [5] https://github.com/OPCFoundation/UA-ModelCompiler#other-repositories

Leave a Reply

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.