OPCFoundation / UA-ModelCompiler

ModelCompiler converts XML files into C# and ANSI C
MIT License
151 stars 94 forks source link

different NodeIds but with the same BrowseName #188

Open Fabolo64 opened 2 months ago

Fabolo64 commented 2 months ago

I'm trying to compile an UANodeSet file exported from SIEMENS interface inside TIA Portal:

image

it seems it should be possible:

image

it contains several array UAVariables with different NodeId, problem is SIEMENS creates an UAVariable for each element of an array, but gives them the same BrowseName across different arrays, i.e. all first elements of an array have this kind of BrowseName="2:[0]"

image

this get rejected by compiler:

[ArgumentException] An item with the same key has already been added. Key: x0_

======================== at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at ModelCompiler.ModelGenerator2.WriteIdentifiers( etc.

I'm using compile command v104

Is it possible to have different NodeIds but with the same BrowseName?

opcfoundation-org commented 2 months ago

The tool automatically creates a symbolic name by replacing invalid characters with x or . So [0] => x0, [1] => x1_, etc.

Are there multiple places in the NodeSet where [0] browse name exists? If so please ensure uniqueness by specifying a ParentNodeId

Fabolo64 commented 2 months ago

Thanks for your answer, yes, there are multiple places with same BrowseName, all NodeIds are indeed unique, parent and children, but relationship is done via a reference in references collection in the parentNode:


<Reference ReferenceType="HasComponent">ns=2;i=855</Reference>>

so no ParentNodeId is present in the "offending" child.


<UAVariable NodeId="ns=2;i=855" BrowseName="2:[0]" DataType="BOOL" AccessLevel="3">

This is an xml file exported by TIA Portal=>OPC interfaces functionality, as is. I guess I'll need to automate some editing, to inject a ParentNodeId in my Component nodes...

opcfoundation-org commented 2 months ago

You need to set the ParentNodeId attribute on the UAVariable representing the child. You can also set the SymbolicName attribute to something that is unique in the file and better than 'x0_'.