02/04/2016
![sp_UserOfflineSmall](https://opcfoundation.org/wp-content/sp-resources/forum-themes/reboot/images/darkpack/sp_UserOfflineSmall.png)
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 ?
1 Guest(s)