.NET Based OPC UA Client/Server SDK  3.3.3.537
Creating the Type Nodes in Code

The example delivered with the SDK also shows how to create the type nodes without using UaModeler.

Creating the Nodes

Lesson 2 includes the method CreateObjectTypesInCode() which is an example for creating the type nodes in code. Note that the following snippet only contains the code to create the Controller type, see the file Lesson02Nodemanager.cs for the complete source code.

private void CreateObjectTypesInCode()
{
CreateVariableSettings variableSettings;
CreateObjectTypeSettings objectTypeSettings;
CreateMethodSettings methodSettings;
/* ***************************************** */
/* ControllerType */
/* ***************************************** */
objectTypeSettings = new CreateObjectTypeSettings()
{
BrowseName = new QualifiedName("ControllerType", TypeNamespaceIndex),
DisplayName = new LocalizedText("ControllerType"),
RequestedNodeId = new NodeId(yourorganisation.BA.ObjectTypes.ControllerType, TypeNamespaceIndex)
};
ObjectTypeNode controllerType = CreateObjectTypeNode(Server.DefaultRequestContext, objectTypeSettings);
variableSettings = new CreateVariableSettings()
{
BrowseName = new QualifiedName("PowerConsumption", TypeNamespaceIndex),
DisplayName = new LocalizedText("PowerConsomtion"),
ParentNodeId = controllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId = new NodeId(yourorganisation.BA.Variables.ControllerType_PowerConsumption, TypeNamespaceIndex)
};
CreateVariable(Server.DefaultRequestContext, variableSettings);
methodSettings = new CreateMethodSettings()
{
BrowseName = new QualifiedName("Start", TypeNamespaceIndex),
DisplayName = new LocalizedText("Start"),
ParentNodeId = controllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId = new NodeId(yourorganisation.BA.Methods.ControllerType_Start, TypeNamespaceIndex)
};
CreateMethod(Server.DefaultRequestContext, methodSettings);

Integrating the Nodes into an Empty Server

To integrate the model into the server from Lesson 1: Setting up a Basic OPC UA Server Console Application, we just call the method in

public override void Startup()
{
Console.WriteLine("Loading the Controller Model.");
CreateObjectTypesInCode();

When using the Visual Studio Solution that comes with the SDK, remove the line

ImportUaNodeset(Assembly.GetEntryAssembly(), "buildingautomation.xml");

Next step: Preparing Instance Creation