Modify structure of derivied object type at runtime

Unified Architecture topics related to OPC UA Specification, compliant behavior and any technical issues of OPC UA, like Security, Information Model, Companion Specs DI, PLCopen, ADI, ...

Moderator: Support Team

Post Reply
milublues
Sr. Member
Sr. Member
Posts: 13
Joined: 12 Mar 2014, 10:50

Modify structure of derivied object type at runtime

Post by milublues »

Hello,
I have a derived object type.

The object has two object of base object type, namely config and structure.
The config object has some variables under it but the structure object is blank. It does not have any node under itself.
Now, I add this node in my object tree and when the variables of config object are assigned some value, depending upon the value of the variables, we add few variable to structure object while the server is running. T

When I add the nodes, the codes does not show any error and the nodes are added, but they newly added nodes are not displayed in object tree.
Code I wrote to add the variable :

CreateVariableSettings settings = new CreateVariableSettings()
{
ParentNodeId = new NodeId(Objects.MyObject_Structure, DefaultNamespaceIndex),
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasProperty,
RequestedNodeId = new NodeId("Column1" , DefaultNamespaceIndex),
BrowseName = new QualifiedName("Column1", DefaultNamespaceIndex),
DisplayName = "Column1",
TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.PropertyType,
DataType = UnifiedAutomation.UaBase.DataTypeIds.String,
ValueRank = ValueRanks.Scalar,
AccessLevel = AccessLevels.CurrentReadOrWrite,
Value = "TestColumn"
};
CreateVariable(Server.DefaultRequestContext, settings);

Extra code to how the changes in Object tree
protected override void AfterAddReference(RequestContext context, Node node, NodeId referenceTypeId, bool isInverse, ExpandedNodeId targetId)
{
if (!UpdateNodeVersion(context, node, ModelChangeStructureVerbMask.ReferenceAdded))
{
base.AfterAddReference(context, node, referenceTypeId, isInverse, targetId);
}
}
private bool UpdateNodeVersion(RequestContext context, Node node, ModelChangeStructureVerbMask verb)
{
InstanceNode instance = node as InstanceNode;
GenericEvent e = new GenericEvent(Server.FilterManager);
e.Initialize(
null,
UnifiedAutomation.UaBase.ObjectTypeIds.GeneralModelChangeEventType,
UnifiedAutomation.UaBase.ObjectIds.Server,
UnifiedAutomation.UaBase.BrowseNames.Server,
EventSeverity.Low,
"The address space has changed.");
ModelChangeStructureDataType[] changes = new ModelChangeStructureDataType[1];
changes[0] = new ModelChangeStructureDataType();
changes[0].Affected = node.NodeId;
changes[0].AffectedType = node.NodeId;
changes[0].AffectedType = (instance != null) ? instance.TypeDefinitionId : null;
changes[0].Verb = (byte)verb;
e.Set(UnifiedAutomation.UaBase.BrowseNames.Changes, new Variant(changes));
Server.ReportEvent(e);
return true;
}

User avatar
Support Team
Hero Member
Hero Member
Posts: 3068
Joined: 18 Mar 2011, 15:09

Re: Modify structure of derivied object type at runtime

Post by Support Team »

Hello,

There are three potential issues:
1. The new nodes are not added.
You can test this with UaExpert. Call rebrowse at the Structure node. If the new node is not visible, adding the node failed.
2. Something went wrong with the ModelChangeEvent.
Here it is important that the parent node of the new nodes (e.g. the Structure node) has Property with the BrowseName (0:NodeVersion) and with DataType String. The value of this Property has to be updated when sending the event. Please see the example in the DemoNodeManager.
3. The client does not subscribe for ModelChangeEvents and update the addressspace automatically.

Best regards
Support Team

Post Reply