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;
objectTypeSettings = new CreateObjectTypeSettings()
{
RequestedNodeId =
new NodeId(yourorganisation.BA.ObjectTypes.ControllerType, TypeNamespaceIndex)
};
ObjectTypeNode controllerType = CreateObjectTypeNode(
Server.DefaultRequestContext, objectTypeSettings);
variableSettings = new CreateVariableSettings()
{
ParentNodeId = controllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.ControllerType_PowerConsumption, TypeNamespaceIndex)
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
methodSettings = new CreateMethodSettings()
{
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