public override void Startup() { try { Console.WriteLine("Starting UANodeServer."); base.Startup(); AddNamespaceUri("http://yourorganisation.com/lesson01/"); // save the namespaces used by this node manager. InstanceNamespaceIndex = AddNamespaceUri("http://kpznet.com/KNodeServer/"); // Create a Folder for Controllers CreateObjectSettings settings = new CreateObjectSettings() { ParentNodeId = ObjectIds.ObjectsFolder, ReferenceTypeId = ReferenceTypeIds.Organizes, RequestedNodeId = new NodeId("GRoot", InstanceNamespaceIndex), BrowseName = new QualifiedName("GRoot", InstanceNamespaceIndex), TypeDefinitionId = ObjectTypeIds.BaseObjectType }; var gRoot = CreateObject(Server.DefaultRequestContext, settings); AddRootNode(gRoot.NodeId, "UANode", tNodes, tVars, 0); totNodes++; string nName = "Total Nodes"; newNodeId++; var variableSettings = new CreateVariableSettings() { BrowseName = nName, DisplayName = nName, ParentNodeId = gRoot.NodeId, ParentAsOwner = true, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasProperty, TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.PropertyType, DataType = UnifiedAutomation.UaBase.DataTypeIds.Argument, ModellingRuleId = UnifiedAutomation.UaBase.ObjectIds.ModellingRule_Mandatory, RequestedNodeId = new NodeId(newNodeId, InstanceNamespaceIndex), Value = new Variant(totNodes) }; CreateVariable(Server.DefaultRequestContext, variableSettings); Console.WriteLine("Total Nodes = " + totNodes); } /// [Set Namespace URI] catch (Exception e) { Console.WriteLine("Failed to start UANodeManager " + e.Message); } }
private void CreateGenericDataTypeVariable(string name, GenericEncodeableObject eo, NodeId parenterID) { CreateVariableSettings settings = new CreateVariableSettings() { RequestedNodeId = new NodeId(name, DefaultNamespaceIndex), BrowseName = new QualifiedName(name, DefaultNamespaceIndex), Description = new LocalizedText("Variable with a structured DataType that is created using the SchameBuilder"), DataType = eo.TypeId.ToNodeId(Server.NamespaceUris), ReferenceTypeId = ReferenceTypeIds.Organizes, ParentNodeId = parenterID, ValueRank = -1, Value = eo }; CreateVariable(Server.DefaultRequestContext, settings); }
public override void Startup() { // m_system.Initialize(); Console.WriteLine("Starting Lesson1NodeManager."); AddNamespaceUri("http://yourorganisation.com/lesson01/"); InstanceNamespaceIndex = AddNamespaceUri("http://yourorganisation.com/lesson01/"); TypeNamespaceIndex = AddNamespaceUri("http://yourorganisation.org/DemoUA/"); Console.WriteLine("Loading the Controller Model."); // ImportUaNodeset(Assembly.GetEntryAssembly(), "buildingautomation.xml"); //ImportUaNodeset(Assembly.GetEntryAssembly(), "demoua.xml"); //NodeId _noid; //AddNode(null, new AddNodeSettings() //{ // ParentNodeId = new NodeId("Controllers", InstanceNamespaceIndex), // ReferenceTypeId = ReferenceTypeIds.Organizes, // RequestedNodeId = new NodeId("AirConditioner1", InstanceNamespaceIndex), // BrowseName = new QualifiedName("AirConditioner1", InstanceNamespaceIndex), // // TypeDefinitionId = new NodeId(yourorganisation.BA.ObjectTypes.AirConditionerControllerType, TypeNamespaceIndex) // TypeDefinitionId = new NodeId(DemoOrganization.BA.ObjectTypes.DemoType, TypeNamespaceIndex) //}, out _noid); // New Code Begin // Create a Folder for Controllers CreateObjectSettings settings = new CreateObjectSettings() { ParentNodeId = ObjectIds.ObjectsFolder, ReferenceTypeId = ReferenceTypeIds.Organizes, RequestedNodeId = new NodeId("Demo", InstanceNamespaceIndex), BrowseName = new QualifiedName("Demo", InstanceNamespaceIndex), TypeDefinitionId = ObjectTypeIds.FolderType }; CreateObject(Server.DefaultRequestContext, settings); // Create an Air Conditioner Controller settings = new CreateObjectSettings() { ParentNodeId = new NodeId("Demo", InstanceNamespaceIndex), ReferenceTypeId = ReferenceTypeIds.Organizes, RequestedNodeId = new NodeId("Jemima", InstanceNamespaceIndex), BrowseName = new QualifiedName("Jemima", InstanceNamespaceIndex), TypeDefinitionId = ObjectTypeIds.FolderType, // TypeDefinitionId = new NodeId(yourorganisation.BA.ObjectTypes.AirConditionerControllerType, TypeNamespaceIndex) // TypeDefinitionId = new NodeId(DemoOrganization.BA.ObjectTypes.DemoType, TypeNamespaceIndex) //TypeDefinitionId = new NodeId(1002, TypeNamespaceIndex), }; var r = CreateObject(Server.DefaultRequestContext, settings); var variableSettings = new CreateVariableSettings() { BrowseName = new QualifiedName("Jay", InstanceNamespaceIndex), DisplayName = new LocalizedText("Jay"), RequestedNodeId = new NodeId("Jay", InstanceNamespaceIndex), ParentNodeId = r.NodeId, ParentAsOwner = true, ReferenceTypeId = ReferenceTypeIds.HasComponent, TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.DataItemType, DataType = DataTypeIds.String, AccessLevel = AccessLevels.CurrentReadOrWrite, ModellingRuleId = UnifiedAutomation.UaBase.ObjectIds.ModellingRule_Mandatory, Value = "Hello World.", }; CreateVariable(Server.DefaultRequestContext, variableSettings); }
/// <summary> /// Called when the node manager is started. /// </summary> public override void Startup() { try { Console.WriteLine("Starting Lesson3bNodeManager."); base.Startup(); // save the namespaces used by this node manager. AddNamespaceUri("http://yourcompany.com/lesson03b/"); // initialize the underlying system. m_system.Initialize(); // create root folder. NodeId rootId = ParsedNodeId.Construct(0, "3b", DefaultNamespaceIndex); CreateObjectSettings settings = new CreateObjectSettings() { ParentNodeId = ObjectIds.ObjectsFolder, ReferenceTypeId = ReferenceTypeIds.Organizes, RequestedNodeId = rootId, BrowseName = new QualifiedName("3b", DefaultNamespaceIndex), TypeDefinitionId = ObjectTypeIds.FolderType }; CreateObject(Server.DefaultRequestContext, settings); // add controllers. foreach (BlockConfiguration block in m_system.GetBlocks()) { NodeId controllerId = ParsedNodeId.Construct(0, block.Name, DefaultNamespaceIndex); // create object. settings = new CreateObjectSettings() { ParentNodeId = rootId, ReferenceTypeId = ReferenceTypeIds.Organizes, RequestedNodeId = controllerId, BrowseName = new QualifiedName(block.Name, DefaultNamespaceIndex), TypeDefinitionId = ObjectTypeIds.BaseObjectType }; CreateObject(Server.DefaultRequestContext, settings); foreach (BlockProperty property in block.Properties) { NodeId variableId = ParsedNodeId.Construct(0, block.Name, DefaultNamespaceIndex, property.Name); // configure the variable so the SDK will automatically poll the system when it is subscribed. // this node manager needs to implement the read/write requests. CreateVariableSettings settings2 = new CreateVariableSettings() { ParentNodeId = controllerId, ReferenceTypeId = ReferenceTypeIds.HasComponent, RequestedNodeId = variableId, BrowseName = new QualifiedName(property.Name, DefaultNamespaceIndex), TypeDefinitionId = (property.Range != null) ? VariableTypeIds.AnalogItemType : VariableTypeIds.DataItemType, DataType = property.DataType, ValueRank = ValueRanks.Scalar, AccessLevel = (property.Writeable) ? AccessLevels.CurrentReadOrWrite : AccessLevels.CurrentRead, ValueType = NodeHandleType.ExternalPolled, ValueData = new SystemAddress() { Address = block.Address, Offset = property.Offset } }; CreateVariable(Server.DefaultRequestContext, settings2); // check if an EURange property needs to be created. // the value is stored internally by the SDK so no additional work to support read is required. //if (property.Range != null) //{ // NodeId propertyId = ParsedNodeId.Construct(0, block.Name, DefaultNamespaceIndex, property.Name, BrowseNames.EURange); // settings2 = new CreateVariableSettings() // { // ParentNodeId = variableId, // ReferenceTypeId = ReferenceTypeIds.HasProperty, // RequestedNodeId = propertyId, // BrowseName = new QualifiedName(BrowseNames.EURange), // TypeDefinitionId = VariableTypeIds.PropertyType, // DataType = DataTypeIds.Range, // ValueRank = ValueRanks.Scalar, // AccessLevel = AccessLevels.CurrentRead, // Value = new Variant(property.Range) // }; // CreateVariable(Server.DefaultRequestContext, settings2); //} } } } catch (Exception e) { Console.WriteLine("Failed to start Lesson3bNodeManager. " + e.Message); } }
public override void Startup() { try { Console.WriteLine("Starting Lesson3bNodeManager."); base.Startup(); // save the namespaces used by this node manager. AddNamespaceUri("http://yourcompany.com/lesson03b/"); // initialize the underlying system. // create root folder. NodeId rootId = ParsedNodeId.Construct(0, "Root", DefaultNamespaceIndex); CreateObjectSettings settings = new CreateObjectSettings() { ParentNodeId = ObjectIds.ObjectsFolder, ReferenceTypeId = ReferenceTypeIds.Organizes, RequestedNodeId = rootId, BrowseName = new QualifiedName("Root", DefaultNamespaceIndex), TypeDefinitionId = ObjectTypeIds.FolderType, NotifierParent = ObjectIds.Server, }; CreateObject(Server.DefaultRequestContext, settings); // add controllers. NodeId controllerId = ParsedNodeId.Construct(0, "Jemima", DefaultNamespaceIndex); // create object. settings = new CreateObjectSettings() { ParentNodeId = rootId, ReferenceTypeId = ReferenceTypeIds.Organizes, RequestedNodeId = controllerId, BrowseName = new QualifiedName("Jemima", DefaultNamespaceIndex), TypeDefinitionId = ObjectTypeIds.BaseObjectType, NotifierParent = new NodeId("Root", DefaultNamespaceIndex), }; CreateObject(Server.DefaultRequestContext, settings); NodeId variableId = ParsedNodeId.Construct(0, "Jemima", DefaultNamespaceIndex, "Jackey"); // configure the variable so the SDK will automatically poll the system when it is subscribed. // this node manager needs to implement the read/write requests. CreateVariableSettings settings2 = new CreateVariableSettings() { ParentNodeId = controllerId, ReferenceTypeId = ReferenceTypeIds.HasComponent, RequestedNodeId = variableId, BrowseName = new QualifiedName("Jackey", DefaultNamespaceIndex), TypeDefinitionId = (true) ? VariableTypeIds.AnalogItemType : VariableTypeIds.DataItemType, DataType = NodeId.Parse("i=12"), ValueRank = ValueRanks.Scalar, AccessLevel = AccessLevels.CurrentReadOrWrite, ValueType = NodeHandleType.ExternalPolled, ValueData = new SystemAddress() { Address = 10, Offset = 100 }, // Value = "Hello World.", }; CreateVariable(Server.DefaultRequestContext, settings2); NodeId methodId = ParsedNodeId.Construct(0, "Jemima", DefaultNamespaceIndex, "WriteValue"); var settings3 = new CreateMethodSettings() { ParentNodeId = controllerId, ReferenceTypeId = ReferenceTypeIds.HasComponent, RequestedNodeId = methodId, BrowseName = new QualifiedName("WriteValue", DefaultNamespaceIndex), NodeData = new SystemFunction() { Address = "Address", Function = "WriteValue" }, InputArguments = new[] { new Argument() { Name = "Value_String", DataType = DataTypeIds.String, ValueRank = ValueRanks.Any }, } }; CreateMethod(Server.DefaultRequestContext, settings3); } catch (Exception e) { Console.WriteLine("Failed to start Lesson3bNodeManager. " + e.Message); } }
void AddVariables(NodeId rootNode, int totVarSets) { for (int i = 1; i <= totVarSets; i++) { totNodes++; string nName = "VariableDbl" + "_" + i.ToString(); newNodeId++; var variableSettings = new CreateVariableSettings() { BrowseName = nName, DisplayName = nName, ParentNodeId = rootNode, ParentAsOwner = true, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasComponent, TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.BaseVariableType, DataType = UnifiedAutomation.UaBase.DataTypeIds.Argument, ModellingRuleId = UnifiedAutomation.UaBase.ObjectIds.ModellingRule_Mandatory, RequestedNodeId = new NodeId(newNodeId, InstanceNamespaceIndex), Value = new Variant(10.1) }; var v = CreateVariable(Server.DefaultRequestContext, variableSettings); totNodes++; nName = "unit"; newNodeId++; variableSettings = new CreateVariableSettings() { BrowseName = nName, DisplayName = nName, ParentNodeId = v.NodeId, ParentAsOwner = true, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasProperty, TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.PropertyType, DataType = UnifiedAutomation.UaBase.DataTypeIds.Argument, ModellingRuleId = UnifiedAutomation.UaBase.ObjectIds.ModellingRule_Mandatory, RequestedNodeId = new NodeId(newNodeId, InstanceNamespaceIndex), Value = new Variant("double") }; CreateVariable(Server.DefaultRequestContext, variableSettings); totNodes++; nName = "VariableInt" + "_" + i.ToString(); newNodeId++; variableSettings = new CreateVariableSettings() { BrowseName = nName, DisplayName = nName, ParentNodeId = rootNode, ParentAsOwner = true, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasComponent, TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.BaseVariableType, DataType = UnifiedAutomation.UaBase.DataTypeIds.Argument, ModellingRuleId = UnifiedAutomation.UaBase.ObjectIds.ModellingRule_Mandatory, RequestedNodeId = new NodeId(newNodeId, InstanceNamespaceIndex), Value = new Variant((int)10) }; v = CreateVariable(Server.DefaultRequestContext, variableSettings); totNodes++; nName = "unit"; newNodeId++; variableSettings = new CreateVariableSettings() { BrowseName = nName, DisplayName = nName, ParentNodeId = v.NodeId, ParentAsOwner = true, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasProperty, TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.PropertyType, DataType = UnifiedAutomation.UaBase.DataTypeIds.Argument, ModellingRuleId = UnifiedAutomation.UaBase.ObjectIds.ModellingRule_Mandatory, RequestedNodeId = new NodeId(newNodeId, InstanceNamespaceIndex), Value = new Variant("int") }; CreateVariable(Server.DefaultRequestContext, variableSettings); totNodes++; nName = "VariableStr" + "_" + i.ToString(); newNodeId++; variableSettings = new CreateVariableSettings() { BrowseName = nName, DisplayName = nName, ParentNodeId = rootNode, ParentAsOwner = true, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasComponent, TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.BaseVariableType, DataType = UnifiedAutomation.UaBase.DataTypeIds.Argument, ModellingRuleId = UnifiedAutomation.UaBase.ObjectIds.ModellingRule_Mandatory, RequestedNodeId = new NodeId(newNodeId, InstanceNamespaceIndex), Value = new Variant("10") }; v = CreateVariable(Server.DefaultRequestContext, variableSettings); totNodes++; nName = "unit"; newNodeId++; variableSettings = new CreateVariableSettings() { BrowseName = nName, DisplayName = nName, ParentNodeId = v.NodeId, ParentAsOwner = true, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasProperty, TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.PropertyType, DataType = UnifiedAutomation.UaBase.DataTypeIds.Argument, ModellingRuleId = UnifiedAutomation.UaBase.ObjectIds.ModellingRule_Mandatory, RequestedNodeId = new NodeId(newNodeId, InstanceNamespaceIndex), Value = new Variant("string") }; CreateVariable(Server.DefaultRequestContext, variableSettings); } }