0

I can dynamically create a node through method node calls, but cannot see it in UAExpert without manually looking for it (Createcustomnode with same nodeId shows the node in 'data access view'). Restarting UAExpert after node creation doesn't fix this issue. How can I solve this problem?

Thanks

public ServiceResult AddNodeMethod(ISystemContext context, MethodState method, IList<object> inputArgs, IList<object> outputArgs0)
    {

        BaseDataVariableState variable = new BaseDataVariableState(opcUaServer);

        variable.SymbolicName = "THISISATEST";
        variable.ReferenceTypeId = ReferenceTypes.Organizes;
        variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType;
        variable.NodeId = new NodeId((uint)2099, NamespaceIndex);
        variable.BrowseName = new QualifiedName("TEST2");
        variable.DisplayName = new LocalizedText("en", "Thisisatest");
        variable.WriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
        variable.UserWriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
        variable.DataType = DataTypeIds.Int32;
        variable.ValueRank = ValueRanks.Scalar;
        variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
        variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
        variable.Historizing = false;
        variable.Value = 0;
        variable.StatusCode = StatusCodes.Good;
        variable.Timestamp = DateTime.UtcNow;

        if (opcUaServer != null)
        {
            AddPredefinedNode(SystemContext, variable);
        }

        if(FindNodeInAddressSpace(variable.NodeId) != null){
            Console.WriteLine("Node succesfully created");
            return ServiceResult.Good;
        }
        return new ServiceResult(2);
    }
oiergoiergh
  • 115
  • 7

1 Answers1

0

You need add a parent to your node.

For example, if you are creating a root folder, your parent would be

ParentNodeId = ObjectIds.ObjectsFolder,
ParentAsOwner = true,

This will allow your OPC UA Client like UaExpert to browse to your node from the parent object.

Note: If you have ParentAsOwner = true, deleting the parent would delete the child node but if your child is a large and complex object, this could take time.

eglease
  • 2,445
  • 11
  • 18
  • 28
  • I am using the OPCFoundation library, not the Unified Automation; the BaseDataVariableState class doesn't have these attributes. However I specify the parent node in the constructor of 'variable'. Could this mismatch btwn OPCFoundation and UA be the reason for this issue? – oiergoiergh Mar 01 '23 at 10:53
  • I don't have any experience with the OPC Foundation libraries but they do have a ParentNodeId according to https://reference.opcfoundation.org/v104/Core/docs/Part6/F.7/ – eglease Mar 01 '23 at 19:39
  • You can also try to add your variable as a child to a parent node like this: `if (parent != null) { parent.AddChild(variable); }` – eglease Mar 01 '23 at 19:39
  • See https://github.com/OPCFoundation/UA-.NETStandard/issues/303 – eglease Mar 01 '23 at 19:41
  • My code successfully adds the to-be-created node as a child of my folder node. (I can successfully consolewrite the child's parent's nodeId after node creation). However UAExpert still doesn't show it in the 'address space' view. I used the same code to create a child node before the parent node is created, and then UAExpert can visualize this. – oiergoiergh Mar 02 '23 at 14:31