Best way to animate or replace existing Predefined Nodes in server 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
Best way to animate or replace existing Predefined Nodes in server address space
Avatar
Julien BENNET
Member
Members
Forum Posts: 6
Member Since:
02/04/2016
sp_UserOfflineSmall Offline
1
03/05/2020 - 03:00
sp_Permalink sp_Print

I was attempting to customize values of some of the existing well-known nodes in the predefined address space.

Others UA implementations offer "re-binding" solution where you just re-map a node-id with your callbacks and/or data.

Is there an easy way, with existing sample code, to easily re-bind a predefined node ? (Could only find documentation about creating own custom address space, not modifying existing nodes)

 

I was a bit puzzled by the classes CoreNodeManager and ConfigurationNodeManager, with their different public interfaces, and came up with a solution. But it looks way too complicated !

To add a node,  linked to existing system structure :

// Create a new NodeState :
var myNewNodeState = new BaseDataVariableState<string>(existingparent) //or new PropertyState()
// Link it with parent : 
existingparent.AddChild(myNewNodeState)
// Import the node into the CoreNodeManager and AddReference within the CoreNodeManager 
server.CoreNodeManager.ImportNodes(server.DefaultSystemContext, new NodeState[] { myNewNodeState });
server.CoreNodeManager.AddReference(existingparent.NodeId, ReferenceTypeIds.HasProperty, false, myNewNodeState.NodeId, false);

To replace a node in predefined system structure :

// Create a new NodeState :
var myNewNodeState = new BaseDataVariableState<string>(existingparent) //or new PropertyState()
// REPLACE it with parent : 
existingparent.ReplaceChild(myNewNodeState)

// HACK : Get ConfigurationNodeManager (my node is handled by this manager)
INodeManager myNodeMgr;
Opc.Ua.Server.NodeHandle objectX = (Opc.Ua.Server.NodeHandle)server.NodeManager.GetManagerHandle(myNewNodeState.NodeId, out myNodeMgr);
var cfgManager = myNodeMgr as ConfigurationNodeManager;
// DELETE THE NODE REFERENCE FROM ConfigManager AND CoreManager
cfgManager.DeleteNode(server.DefaultSystemContext, myNewNodeState.NodeId);
server.CoreNodeManager.DeleteNode(myNewNodeState.NodeId, deleteChildren: true, silent: true);

// Import the node into the CoreNodeManager and AddReference within the CoreNodeManager  (can't re-import in ConfigManager without screwing the NodeId!)
server.CoreNodeManager.ImportNodes(server.DefaultSystemContext, new NodeState[] { myNewNodeState });
server.CoreNodeManager.AddReference(existingparent.NodeId, ReferenceTypeIds.HasProperty, false, myNewNodeState.NodeId, false);

 

Maybe there is a less convoluted way to do this ?

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOnlineSmall Online
2
03/05/2020 - 10:41
sp_Permalink sp_Print sp_EditHistory

You are doing it the way it needs to be done.

Some of the APIs in the code base are more complex than they need to be but fixing them would be a lot of effort and there is a shortage of volunteers.

Avatar
Julien BENNET
Member
Members
Forum Posts: 6
Member Since:
02/04/2016
sp_UserOfflineSmall Offline
3
03/06/2020 - 00:55
sp_Permalink sp_Print

Ok thanks Randy.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online: Randy Armstrong
Guest(s) 18
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1349
Posts: 4579