using System.Collections.Generic;
namespace YourCompany.GettingStarted
{
internal class Lesson02NodeManager : BaseNodeManager
{
public ushort InstanceNamespaceIndex { get; set; }
public ushort TypeNamespaceIndex { get; set; }
public override void Startup()
{
try
{
base.Startup();
Console.WriteLine("Starting Lesson02NodeManager.");
TypeNamespaceIndex = AddNamespaceUri(yourorganisation.BA.Namespaces.BA);
InstanceNamespaceIndex = AddNamespaceUri("http://yourorganisation.com/lesson02/");
Console.WriteLine("Loading the Controller Model.");
ImportUaNodeset(Assembly.GetEntryAssembly(), "buildingautomation.xml");
CreateObjectSettings settings = new CreateObjectSettings()
{
ParentNodeId = ObjectIds.ObjectsFolder,
RequestedNodeId =
new NodeId(
"Controllers", InstanceNamespaceIndex),
TypeDefinitionId = ObjectTypeIds.FolderType
};
ObjectNode controllersNode = CreateObject(
Server.DefaultRequestContext, settings);
settings = new CreateObjectSettings()
{
ParentNodeId = controllersNode.NodeId,
RequestedNodeId =
new NodeId(
"AirConditioner1", InstanceNamespaceIndex),
TypeDefinitionId =
new NodeId(yourorganisation.BA.ObjectTypes.AirConditionerControllerType, TypeNamespaceIndex)
};
CreateObject(
Server.DefaultRequestContext, settings);
settings = new CreateObjectSettings()
{
ParentNodeId = controllersNode.NodeId,
RequestedNodeId =
new NodeId(
"Furnace1", InstanceNamespaceIndex),
TypeDefinitionId =
new NodeId(yourorganisation.BA.ObjectTypes.FurnaceControllerType, TypeNamespaceIndex)
};
CreateObject(
Server.DefaultRequestContext, settings);
}
catch (Exception e)
{
Console.WriteLine("Failed to start Lesson02NodeManager. " + e.Message);
}
}
{
try
{
Console.WriteLine("Stopping Lesson02NodeManager.");
base.Shutdown();
}
catch (Exception e)
{
Console.WriteLine("Failed to stop Lesson02NodeManager. " + e.Message);
}
}
#region Constructor
public Lesson02NodeManager(ServerManager server) : base(server)
{
}
#endregion
#region IDisposable
protected override void Dispose(bool disposing)
{
if (disposing)
{
}
}
#endregion
#region Private Methods
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);
variableSettings = new CreateVariableSettings()
{
ParentNodeId = controllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.ControllerType_State, TypeNamespaceIndex)
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
methodSettings = new CreateMethodSettings()
{
ParentNodeId = controllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Methods.ControllerType_Stop, TypeNamespaceIndex)
};
CreateMethod(
Server.DefaultRequestContext, methodSettings);
variableSettings = new CreateVariableSettings()
{
ParentNodeId = controllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.ControllerType_Temperature, TypeNamespaceIndex)
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
variableSettings = new CreateVariableSettings()
{
ParentNodeId = controllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.ControllerType_TemperatureSetPoint, TypeNamespaceIndex)
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
objectTypeSettings = new CreateObjectTypeSettings()
{
SuperTypeId = controllerType.NodeId,
RequestedNodeId =
new NodeId(yourorganisation.BA.ObjectTypes.AirConditionerControllerType, TypeNamespaceIndex)
};
ObjectTypeNode airConditionerControllerType = CreateObjectTypeNode(
Server.DefaultRequestContext, objectTypeSettings);
variableSettings = new CreateVariableSettings()
{
ParentNodeId = airConditionerControllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.AirConditionerControllerType_Humidity, TypeNamespaceIndex)
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
variableSettings = new CreateVariableSettings()
{
ParentNodeId = airConditionerControllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.AirConditionerControllerType_HumiditySetPoint, TypeNamespaceIndex)
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
methodSettings = new CreateMethodSettings()
{
ParentNodeId = airConditionerControllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Methods.AirConditionerControllerType_StartWithSetPoint, TypeNamespaceIndex)
};
MethodNode startWithSetpointNode = CreateMethod(
Server.DefaultRequestContext, methodSettings);
IList<Argument> arguments = new List<Argument>();
arguments.Add(new Argument()
{
Name = "Temperature",
});
arguments.Add(new Argument()
{
Name = "Humidity",
});
variableSettings = new CreateVariableSettings()
{
ParentNodeId = startWithSetpointNode.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.AirConditionerControllerType_StartWithSetPoint_InputArguments, TypeNamespaceIndex),
Value =
new Variant(arguments.ToArray())
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
objectTypeSettings = new CreateObjectTypeSettings()
{
SuperTypeId = controllerType.NodeId,
RequestedNodeId =
new NodeId(yourorganisation.BA.ObjectTypes.FurnaceControllerType, TypeNamespaceIndex)
};
ObjectTypeNode furnanceControllerType = CreateObjectTypeNode(
Server.DefaultRequestContext, objectTypeSettings);
variableSettings = new CreateVariableSettings()
{
ParentNodeId = furnanceControllerType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.FurnaceControllerType_GasFlow, TypeNamespaceIndex)
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
objectTypeSettings = new CreateObjectTypeSettings()
{
RequestedNodeId =
new NodeId(yourorganisation.BA.ObjectTypes.ControllerEventType, TypeNamespaceIndex)
};
ObjectTypeNode controllerEventType = CreateObjectTypeNode(
Server.DefaultRequestContext, objectTypeSettings);
variableSettings = new CreateVariableSettings()
{
ParentNodeId = controllerEventType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.ControllerEventType_Temperature, TypeNamespaceIndex)
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
variableSettings = new CreateVariableSettings()
{
ParentNodeId = controllerEventType.NodeId,
ParentAsOwner = true,
RequestedNodeId =
new NodeId(yourorganisation.BA.Variables.ControllerEventType_State, TypeNamespaceIndex)
};
CreateVariable(
Server.DefaultRequestContext, variableSettings);
}
#endregion
#region Private Fields
#endregion
}
}