How to dynamically add nodes to address space|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
How to dynamically add nodes to address space
Avatar
T Hartnett
Member
Members
Forum Posts: 3
Member Since:
07/13/2021
sp_UserOfflineSmall Offline
1
06/10/2022 - 04:18
sp_Permalink sp_Print

Is there something special I need to do to add a PropertyState<type> as a child to a BaseObjectState while the server is running. In other words dynamically. I have C# code that looks like this

BaseObjectState layer = new BaseObjectState(m_layers);
layer.NodeId = new NodeId(id++, NamespaceIndex);
layer.BrowseName = new QualifiedName(layerName, NamespaceIndex);
layer.DisplayName = layer.BrowseName.Name;
layer.TypeDefinitionId = ObjectTypeIds.FolderType;
m_layers.AddChild(layer);

PropertyState<double> velocityNode = new PropertyState<double>(layer);
velocityNode.NodeId = new NodeId(id++, NamespaceIndex);
velocityNode.BrowseName = new QualifiedName("Velocity", NamespaceIndex);
velocityNode.DisplayName = velocityNode.BrowseName.Name;
velocityNode.TypeDefinitionId = VariableTypeIds.PropertyType;
velocityNode.ReferenceTypeId = ReferenceTypeIds.HasProperty;
velocityNode.DataType = DataTypeIds.Double;
velocityNode.ValueRank = ValueRanks.Scalar;
velocityNode.Value = velocity;
layer.AddChild(velocityNode);

 

The Layer Node shows up correctly in the address space, but whenever I click to expand it and see it's VelocityNode PropertyState I get a BadNodeIdUnknown error. How can this be avoided?

Avatar
T Hartnett
Member
Members
Forum Posts: 3
Member Since:
07/13/2021
sp_UserOfflineSmall Offline
2
06/10/2022 - 06:38
sp_Permalink sp_Print sp_EditHistory

I realized I forgot the AddPredefinedNode(SystemContext, nodeName) call....

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