Extending NodeSet2.xml through ModelDesign|OPC UA Implementation: Stacks, Tools, and Samples|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Extending NodeSet2.xml through ModelDesign
Avatar
Bob Judge
Member
Members
Forum Posts: 7
Member Since:
05/06/2020
sp_UserOfflineSmall Offline
1
05/05/2023 - 06:30
sp_Permalink sp_Print

Hi,

is this still relevant https://opcfoundation.org/foru.....eset2-xml/ , given the ModelCompiler now supports NodeSet2.xml natively as input?

I am confronted with the situation that there is a third-party NodeSet2.xml that I'd like to use and extend.

I also was thinking that it would be required to reverse compile the given NodeSet2.xml, edit the resulting ModelDesign.xml and recompile as a whole.

On the other hand, it seems pretty normal to reference a in a ModelDesign.xml external NodeSet2.xml types. But just beginning, I could net get it to work yet at all. Tried to call ModelCompiler with -d2 ModelDesign.xml -d2 GivenNodeSet2.xml with the ModelDesign having an object with TypeDefinition equal to some Type in GivenNodeSet2.xml but it gives an error ( "The TypeDefinition reference for node Cat2 is not valid: CatType." Am am experimenting with the animals example for now.)

 

Best

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
05/05/2023 - 13:04
sp_Permalink sp_Print sp_EditHistory

The model compiler allows you to mix dependencies.

i.e. a ModelDesign can import types from a NodeSet2 and vise versa.

Opc.Ua.ModelCompiler compile -d2 .\Opc.Ua.Machinery.NodeSet2.xml,Opc.Ua.Machinery,Machinery -d2 Opc.Ua.Di.NodeSet2.xml,Opc.Ua.DI,DI -version v105 -exclude Draft -o2 .\output

Where the target is always the first one.

If a reference is not found check your namespace prefixes.

Avatar
Bob Judge
Member
Members
Forum Posts: 7
Member Since:
05/06/2020
sp_UserOfflineSmall Offline
3
05/08/2023 - 02:39
sp_Permalink sp_Print sp_EditHistory

Hi Randy,

thanks for your reply.

I tried to follow your advice and understand the namespace handling better.

In order to do so, I created a very simplistic Model Design and compiled it successfully:

 

<ModelDesign
xmlns:ua="https://opcfoundation.org/UA/"
xmlns:simple="https://simple.com/simple2/"
TargetNamespace="https://simple.com/simple2/"
xmlns="https://opcfoundation.org/UA/ModelDesign.xsd">

https://simple.com/simple2/
https://opcfoundation.org/UA/

Base type for all Simplers

Name of the Simple

 

It compiles by:

Opc.Ua.ModelCompiler.exe compile -d2 .\simple.xml -cg .\simple_gen.csv -o2 ./simple

Then I tried to "include" the resulting simpler.NodeSet2.xml into another Model user.xml (omitted for now, as it seems to not yet matter)

compile -d2 .\user.xml -d2 .\simple\simpler.NodeSet2.xml,Simple -cg .\user_gen.csv -o2 ./user

This results in:

[ArgumentOutOfRangeException] startIndex cannot be larger than length of string. (Parameter 'startIndex')

========================
at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
at System.String.Substring(Int32 startIndex)
at ModelCompiler.NodeSetToModelDesign.CreateNamespace(ModelTableEntry model) in C:\Repositories\UA-ModelCompiler-master\UA-ModelCompiler-master\Opc.Ua.ModelCompiler\NodeSetToModelDesign.cs:line 181
at ModelCompiler.NodeSetToModelDesign.LoadNamespaces(String filePath) in C:\Repositories\UA-ModelCompiler-master\UA-ModelCompiler-master\Opc.Ua.ModelCompiler\NodeSetToModelDesign.cs:line 227
at ModelCompiler.ModelCompilerValidator.GetNamespaceList(IList`1 designFilePaths) in C:\Repositories\UA-ModelCompiler-master\UA-ModelCompiler-master\Opc.Ua.ModelCompiler\ModelDesignerValidator.cs:line 1226
at ModelCompiler.ModelCompilerValidator.ValidateModel(IList`1 designFilePaths, String identifierFilePath, Boolean generateIds) in C:\Repositories\UA-ModelCompiler-master\UA-ModelCompiler-master\Opc.Ua.ModelCompiler\ModelDesignerValidator.cs:line 1307
at ModelCompiler.ModelCompilerValidator.Validate(IList`1 designFilePaths, String identifierFilePath, Boolean generateIds) in C:\Repositories\UA-ModelCompiler-master\UA-ModelCompiler-master\Opc.Ua.ModelCompiler\ModelDesignerValidator.cs:line 1024
at ModelCompiler.ModelGenerator2.ValidateAndUpdateIds(IList`1 designFilePaths, String identifierFilePath, UInt32 startId, String specificationVersion, Boolean useAllowSubtypes, IList`1 exclusions, String modelVersion, String modelPublicationDate, Boolean releaseCandidate, Boolean extractIdentifiers) in C:\Repositories\UA-ModelCompiler-master\UA-ModelCompiler-master\Opc.Ua.ModelCompiler\ModelGenerator2.cs:line 125
at ModelCompiler.ModelCompilerApplication.<>c__DisplayClass13_0.b__0() in C:\Repositories\UA-ModelCompiler-master\UA-ModelCompiler-master\Opc.Ua.ModelCompiler\ModelCompilerApplication.cs:line 480
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass143_0.b__0(CancellationToken _)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at ModelCompiler.ModelCompilerApplication.Run(String[] args) in C:\Repositories\UA-ModelCompiler-master\UA-ModelCompiler-master\Opc.Ua.ModelCompiler\ModelCompilerApplication.cs:line 31
at Program.

$(String[] args) in C:\Repositories\UA-ModelCompiler-master\UA-ModelCompiler-master\Opc.Ua.ModelCompiler\Program.cs:line 27
========================
I thought maybe I could narrow down by simply recompiling the .\simple\simpler.NodeSet2.xml

compile -d2 .\simple\simpler.NodeSet2.xml -cg .\user_gen.csv -o2 ./user

And I get the same error which for me means, I put in a valid ModelDesign simple.xml, but the output of ModelCompiler is not accepted as input itself (I noted from call trace, ModelCompiler internally used the NodeSetToModelDesign functionality as discussed initially).

 

[Just for completeness, the user.xml but it seems not yet being processed:

 

<ModelDesign
xmlns:uax="https://opcfoundation.org/UA/2008/02/Types.xsd"
xmlns:ua="https://opcfoundation.org/UA/"
xmlns:simple="https://simple.com/simpler2/"
xmlns:user="https://simple.com/user/"
TargetNamespace="https://simple.com/user/"
xmlns="https://opcfoundation.org/UA/ModelDesign.xsd">

https://simple.com/user/
https://simple.com/simple2/
https://opcfoundation.org/UA/

A simple object

Simplistic

 

]

Avatar
Bob Judge
Member
Members
Forum Posts: 7
Member Since:
05/06/2020
sp_UserOfflineSmall Offline
4
05/08/2023 - 02:49
sp_Permalink sp_Print

On editing my previous post, the forum software seems to have malformed the xml (if it gets interpreted internally unintentionally, this could be exploited, be aware forum admins).

So again the two files:

simple.xml

<?xml version="1.0" encoding="utf-8"?>

<ModelDesign
xmlns:ua="https://opcfoundation.org/UA/"
xmlns:simple="https://simple.com/simple2/"
TargetNamespace="https://simple.com/simple2/"
xmlns="https://opcfoundation.org/UA/ModelDesign.xsd">

<Namespaces>
<Namespace Name="Simple" Prefix="simpler" XmlNamespace="https://opcua.rocks/UA/simple2/Types.xsd" XmlPrefix="simple">https://simple.com/simple2/&lt.....ce&gt;
<Namespace Name="OpcUa" Version="1.03" PublicationDate="2013-12-02T00:00:00Z" Prefix="Opc.Ua" InternalPrefix="Opc.Ua.Server" XmlNamespace="https://opcfoundation.org/UA/2008/02/Types.xsd" XmlPrefix="OpcUa">https://opcfoundation.org/UA/&l.....ce&gt;
</Namespaces>

<ObjectType SymbolicName="simple:SimpleType" BaseType="ua:BaseObjectType" IsAbstract="true" SupportsEvents="true">
<Description>Base type for all Simplers</Description>
<Children>
<Property SymbolicName="simple:Name" DataType="ua:String" ValueRank="Scalar" ModellingRule="Mandatory">
<Description>Name of the Simple</Description>
</Property>
</Children>
</ObjectType>

</ModelDesign>

user.xml

<?xml version="1.0" encoding="utf-8"?>

<ModelDesign
xmlns:uax="https://opcfoundation.org/UA/2008/02/Types.xsd"
xmlns:ua="https://opcfoundation.org/UA/"
xmlns:simple="https://simple.com/simpler2/"
xmlns:user="https://simple.com/user/"
TargetNamespace="https://simple.com/user/"
xmlns="https://opcfoundation.org/UA/ModelDesign.xsd">

<Namespaces>
<Namespace Prefix="user">https://simple.com/user/</N.....ce&gt;
<Namespace>https://simple.com/simple2/&lt.....ce&gt;
<Namespace Name="OpcUa" Version="1.03" PublicationDate="2013-12-02T00:00:00Z" Prefix="Opc.Ua" InternalPrefix="Opc.Ua.Server" XmlNamespace="https://opcfoundation.org/UA/2008/02/Types.xsd" XmlPrefix="OpcUa">https://opcfoundation.org/UA/&l.....ce&gt;
</Namespaces>

<Object SymbolicName="user:Insta" TypeDefinition="simple:SimpleType">
<Description>A simple object</Description>
<Children>
<Property SymbolicName="user:Name" DataType="ua:String" AccessLevel="Read">
<DefaultValue>
<uax:String>Simplistic</uax:String>
</DefaultValue>
</Property>
</Children>
</Object>

</ModelDesign>

Avatar
Bob Judge
Member
Members
Forum Posts: 7
Member Since:
05/06/2020
sp_UserOfflineSmall Offline
5
05/08/2023 - 02:54
sp_Permalink sp_Print

Hm, again alternated by forum at namespace closure. maybe without the quote function...? :

<?xml version="1.0" encoding="utf-8"?>

<ModelDesign
xmlns:uax="https://opcfoundation.org/UA/2008/02/Types.xsd"
xmlns:ua="https://opcfoundation.org/UA/"
xmlns:simple="https://simple.com/simpler2/"
xmlns:user="https://simple.com/user/"
TargetNamespace="https://simple.com/user/"
xmlns="https://opcfoundation.org/UA/ModelDesign.xsd">

<Namespaces>
<Namespace Prefix="user">https://simple.com/user/</N.....ce&gt;
<Namespace>https://simple.com/simple2/&lt.....ce&gt;
<Namespace Name="OpcUa" Version="1.03" PublicationDate="2013-12-02T00:00:00Z" Prefix="Opc.Ua" InternalPrefix="Opc.Ua.Server" XmlNamespace="https://opcfoundation.org/UA/2008/02/Types.xsd" XmlPrefix="OpcUa">https://opcfoundation.org/UA/&l.....ce&gt;
</Namespaces>

<Object SymbolicName="user:Insta" TypeDefinition="simple:SimpleType">
<Description>A simple object</Description>
<Children>
<Property SymbolicName="user:Name" DataType="ua:String" AccessLevel="Read">
<DefaultValue>
<uax:String>Simplistic</uax:String>
</DefaultValue>
</Property>
</Children>
</Object>

</ModelDesign>

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
05/08/2023 - 03:14
sp_Permalink sp_Print

Do you have access to the member only repo?

https://opcf-members.github.io/Help/

Avatar
Bob Judge
Member
Members
Forum Posts: 7
Member Since:
05/06/2020
sp_UserOfflineSmall Offline
7
05/08/2023 - 05:40
sp_Permalink sp_Print

Hi,

does not seem so. I am currently evaluating OPC UA; technical guy; don't know about corporate level foundation membership stuff. Is it mandatory to solve my challenge?

Best

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
8
05/08/2023 - 06:48
sp_Permalink sp_Print sp_EditHistory

Bug fixes are first pushed to the member-only repo. There are some bugs which have already been fixed there.

Try using a NamespaceUri that starts with https://opcfoundation.org/UA/

A fix for this bug is in progress.

Avatar
Bob Judge
Member
Members
Forum Posts: 7
Member Since:
05/06/2020
sp_UserOfflineSmall Offline
9
05/08/2023 - 07:08
sp_Permalink sp_Print

Ok, with opcfoundation.org it proceeds and the reflexive compile works.

But now I am back at my initial state with the invalid reference:

Opc.Ua.ModelCompiler.exe compile -d2 .\user.xml -d2 .\simple\simpler.NodeSet2.xml -cg .\user_gen.csv -o2 ./user
[InvalidOperationException] The TypeDefinition reference for node Insta is not valid: SimpleType.

user.xml:

<?xml version="1.0" encoding="utf-8"?>

<ModelDesign
xmlns:uax="https://opcfoundation.org/UA/2008/02/Types.xsd"
xmlns:ua="https://opcfoundation.org/UA/"
xmlns:simple="https://opcfoundation.org/UA/simpler2/"
xmlns:user="https://opcfoundation.org/UA/user/"
TargetNamespace="https://opcfoundation.org/UA/user/"
xmlns="https://opcfoundation.org/UA/ModelDesign.xsd">

<Namespaces>
<Namespace Prefix="user">https://opcfoundation.org/UA/user/</Namespace&gt;
<Namespace>https://opcfoundation.org/UA/simple2/</Namespace&gt;
<Namespace Name="OpcUa" Version="1.03" PublicationDate="2013-12-02T00:00:00Z" Prefix="Opc.Ua" InternalPrefix="Opc.Ua.Server" XmlNamespace="https://opcfoundation.org/UA/2008/02/Types.xsd" XmlPrefix="OpcUa">https://opcfoundation.org/UA/</Namespace&gt;
</Namespaces>

<Object SymbolicName="user:Insta" TypeDefinition="simple:SimpleType">
<Description>A simple object</Description>
<Children>
<Property SymbolicName="user:Name" DataType="ua:String" AccessLevel="Read">
<DefaultValue>
<uax:String>Simplistic</uax:String>
</DefaultValue>
</Property>
</Children>
</Object>

</ModelDesign>

 

simple.xml:

<?xml version="1.0" encoding="utf-8"?>

<ModelDesign
xmlns:ua="https://opcfoundation.org/UA/"
xmlns:simple="https://opcfoundation.org/UA/simple2/"
TargetNamespace="https://opcfoundation.org/UA/simple2/"
xmlns="https://opcfoundation.org/UA/ModelDesign.xsd">

<Namespaces>
<Namespace Name="Simple" Prefix="simpler" XmlNamespace="https://opcua.rocks/UA/simple2/Types.xsd" XmlPrefix="simple">https://opcfoundation.org/UA/simple2/</Namespace&gt;
<Namespace Name="OpcUa" Version="1.03" PublicationDate="2013-12-02T00:00:00Z" Prefix="Opc.Ua" InternalPrefix="Opc.Ua.Server" XmlNamespace="https://opcfoundation.org/UA/2008/02/Types.xsd" XmlPrefix="OpcUa">https://opcfoundation.org/UA/</Namespace&gt;
</Namespaces>

<ObjectType SymbolicName="simple:SimpleType" BaseType="ua:BaseObjectType" IsAbstract="true" SupportsEvents="true">
<Description>Base type for all Simplers</Description>
<Children>
<Property SymbolicName="simple:Name" DataType="ua:String" ValueRank="Scalar" ModellingRule="Mandatory">
<Description>Name of the Simple</Description>
</Property>
</Children>
</ObjectType>

</ModelDesign>

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
10
05/08/2023 - 14:27
sp_Permalink sp_Print

In your file you declare simple prefix as:

xmlns:simple="https://opcfoundation.org/UA/simpler2/"

But the URI of the simple model is:

xmlns:simple="https://opcfoundation.org/UA/simple2/"

i.e. a bad namespace URI - the most common explanation for type not found errors.

Avatar
Bob Judge
Member
Members
Forum Posts: 7
Member Since:
05/06/2020
sp_UserOfflineSmall Offline
11
05/08/2023 - 23:58
sp_Permalink sp_Print

It works now! Thanks Randy.

I intentionally alternated the namespaces everywhere to be able to trace its handling. It's a bit unobvious in the beginning what needs to match what.

For this specific case, however, it was a clear mistake on my side during this process.

And yet, there is xmlns for namespace URI and Types.xsd URI,  Attributes: TargetNamespace, Name, Prefix, InternalPrefix, XmlNamespace, XmlPrefix; Actual URI value.

Not all seem really mattering / purpose mostly unclear for me at least 🙂

But anyhow, with this simple setup working, I can proceed Smile

Best

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
12
05/09/2023 - 00:59
sp_Permalink sp_Print

I usually make the target namespace the default for the file and use a prefix like opc: for the ModelDesign schema.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 46
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1435
Posts: 4855