C# Add Node to Server|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
C# Add Node to Server
Avatar
John Curry
Member
Members
Forum Posts: 5
Member Since:
12/16/2019
sp_UserOfflineSmall Offline
1
12/15/2020 - 12:56
sp_Permalink sp_Print

I’m looking for some sample code that shows me how to create and add a node to the Server.

Avatar
Randy Armstrong
Admin
Forum Posts: 1580
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
Avatar
John Curry
Member
Members
Forum Posts: 5
Member Since:
12/16/2019
sp_UserOfflineSmall Offline
3
12/16/2020 - 05:58
sp_Permalink sp_Print

Yeah I spent considerable time looking at CreateAddressSpace in the Node Managers derived from CustomNodeManager2.  From looking at the Boiler Server in Quickstarts, it appears the folder and objects are created using modeling.  I was hoping to find an example that:

–  Created a folder 

–  Created a simple tag in that folder

I suppose the answer is there in one of the samples, but I’ve not found it yet. 

Avatar
Randy Armstrong
Admin
Forum Posts: 1580
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
12/16/2020 - 09:37
sp_Permalink sp_Print

This code creates a new Node from a predefined class. If you don’t have you own model you can use one of the built in Nodes such as FolderState. The MemoryBuffer show how to create Nodes from arbitrary structures.

        /// <summary>
        /// Creates a boiler and adds it to the address space.
        /// </summary>
        /// <param name="context">The context to use.</param>
        /// <param name="unitNumber">The unit number for the boiler.</param>
        private void CreateBoiler(SystemContext context, int unitNumber)
        {
            BoilerState boiler = new BoilerState(null);

            string name = Utils.Format("Boiler #{0}", unitNumber);

            boiler.Create(
                context,
                null, 
                new QualifiedName(name, m_namespaceIndex),
                null, 
                true);

            NodeState folder = (NodeState)FindPredefinedNode(
                ExpandedNodeId.ToNodeId(ObjectIds.Boilers, Server.NamespaceUris),
                typeof(NodeState));

            folder.AddReference(Opc.Ua.ReferenceTypeIds.Organizes, false, boiler.NodeId);
            boiler.AddReference(Opc.Ua.ReferenceTypeIds.Organizes, true, folder.NodeId);

            string unitLabel = Utils.Format("{0}0", unitNumber);

            UpdateDisplayName(boiler.InputPipe, unitLabel);
            UpdateDisplayName(boiler.Drum, unitLabel);
            UpdateDisplayName(boiler.OutputPipe, unitLabel);
            UpdateDisplayName(boiler.LevelController, unitLabel);
            UpdateDisplayName(boiler.FlowController, unitLabel);
            UpdateDisplayName(boiler.CustomController, unitLabel);

            m_boilers.Add(boiler);

            AddPredefinedNode(context, boiler);

            // Autostart boiler simulation state machine
            MethodState start = boiler.Simulation.Start;
            IList<Variant> inputArguments = new List<Variant>();
            IList<Variant> outputArguments = new List<Variant>();
            List<ServiceResult> errors = new List<ServiceResult>();
            start.Call(context, boiler.NodeId, inputArguments, errors, outputArguments);
        }
Avatar
John Curry
Member
Members
Forum Posts: 5
Member Since:
12/16/2019
sp_UserOfflineSmall Offline
5
12/23/2020 - 05:28
sp_Permalink sp_Print

I’ve had some success in adding both folders and points, using the “UA Sample Applications” and some of the Workshop projects, specifically, the “Empty Server” workshop, and interpolating the code in the “EmptyNodeManager”, inherited  from “CustomNodeManager2”.

My ultimate goal is to replicate the contents of some other Customer UA server.  I first extract the configuration from the Customer server, and re-create it using the same Node ID’s in my server.

What has me puzzled at the moment is that one of the Customer UA servers I am trying to replicate has a Folder with a Node ID that has NameSpaceIndex of 1, and I can’t seem to create anything with a NameSpaceIndex of 1 that will appear when I connect a Client to the Server I created.  What am I doing wrong?

Thanks..

Avatar
Randy Armstrong
Admin
Forum Posts: 1580
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
12/27/2020 - 12:41
sp_Permalink sp_Print

NamespaceIndexes is reserved for internal use by the SDK.

You can add nodes to it by adding Nodes to the DiagnosticsNodeManager but that might require extending the code in the Opc.Ua.Server DLL.

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