public AssemblyStation Create(string name, Directory directory) { var settings = new CreateObjectSettings() { ParentNodeId = directory.NodeId, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes, RequestedNodeId = new NodeId(name, _nodeManager.InstanceNamespaceIndex), BrowseName = new QualifiedName(name, _nodeManager.InstanceNamespaceIndex), TypeDefinitionId = new NodeId(PolslMacrocourse.DcsLab.ObjectTypes.AssemblyStationType, _nodeManager.TypeNamespaceIndex) }; var node = _nodeManager.CreateObject(_nodeManager.Server.DefaultRequestContext, settings); var station = new AssemblyStation(node, _nodeManager); var setters = makeSetters(station); var getters = makeGetters(station); foreach (var variableName in variables) { _nodeManager.SetVariableConfiguration( node.NodeId, new QualifiedName(variableName, _nodeManager.TypeNamespaceIndex), NodeHandleType.ExternalPolled, new Tuple <Func <object>, Action <object> >(getters[variableName], setters[variableName]) ); } return(station); }
void AddRootNode(NodeId rootNode, string baseName, int[] tNodes, int[] tProps, int currDepth) { currDepth = currDepth + 1; if (currDepth <= tNodes.Length) { int nodesAtCurrentDepth = tNodes[currDepth - 1]; for (int i = 1; i <= nodesAtCurrentDepth; i++) { string nName = baseName + "_" + currDepth.ToString() + "_" + i.ToString(); newNodeId++; CreateObjectSettings settings = new CreateObjectSettings() { ParentNodeId = rootNode, ReferenceTypeId = ReferenceTypeIds.HasComponent, RequestedNodeId = new NodeId(newNodeId, InstanceNamespaceIndex), BrowseName = new QualifiedName(nName, InstanceNamespaceIndex), TypeDefinitionId = ObjectTypeIds.BaseObjectType }; var pN = CreateObject(Server.DefaultRequestContext, settings); totNodes++; AddVariables(pN.NodeId, tProps[currDepth - 1]); AddRootNode(pN.NodeId, baseName, tNodes, tProps, currDepth); } } }
public AssemblyStationViewModel CreateAssemblyStation(string name, ObjectNode parent) { var settings = new CreateObjectSettings() { ParentNodeId = parent.NodeId, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes, RequestedNodeId = new NodeId(name, DefaultNamespaceIndex), BrowseName = new QualifiedName(name, DefaultNamespaceIndex), TypeDefinitionId = new NodeId(Polsl.DcsLab.ObjectTypes.AssemblyStationType, DefaultNamespaceIndex), }; var node = CreateObject(Server.DefaultRequestContext, settings); var vm = new AssemblyStationViewModel(node); var getters = getGetters(vm); var setters = getSetters(vm); foreach (var variable in variables) { SetVariableConfiguration( node.NodeId, new QualifiedName(variable, DefaultNamespaceIndex), NodeHandleType.ExternalPolled, new Tuple <Func <object>, Action <object> >(getters[variable], setters[variable])); } return(vm); }
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); } }
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); } }
public override void Startup() { Console.WriteLine("Starting Lesson2NodeManager."); // New Code Begin // Assign namespaces for type and instance nodes to this NodeManager // Get namespace index for the namespaces InstanceNamespaceIndex = AddNamespaceUri("http://namespaceuri/"); TypeNamespaceIndex = AddNamespaceUri("http://namespaceuri/"); // New Code End Console.WriteLine("Loading the Controller Model."); var xml = new XmlGeneric().getXml(); ImportUaNodeset(new FileStream(xml, FileMode.Open)); // 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 }; var root = CreateObject(Server.DefaultRequestContext, settings); // Create an Air Conditioner Controller settings = new CreateObjectSettings() { ParentNodeId = root.NodeId, ReferenceTypeId = ReferenceTypeIds.Organizes, RequestedNodeId = new NodeId("Jemima", InstanceNamespaceIndex), BrowseName = new QualifiedName("Jemima", InstanceNamespaceIndex), TypeDefinitionId = new NodeId(1001, TypeNamespaceIndex) }; CreateObject(Server.DefaultRequestContext, settings); //var vsettings = new CreateVariableSettings() //{ // ParentNodeId = new NodeId("Jemima", InstanceNamespaceIndex), // ReferenceTypeId = ReferenceTypeIds.HasComponent, // BrowseName = new QualifiedName("newone", InstanceNamespaceIndex), // DisplayName = new LocalizedText("newone" ), // DataType = DataTypeIds.Byte, // AccessLevel = 3, //}; //CreateVariable(Server.DefaultRequestContext, vsettings); // 这里的node名字一定要是xml加载的节点 VariableNode variable = SetVariableConfiguration( new NodeId("Jemima", InstanceNamespaceIndex), new QualifiedName("J_Int32", TypeNamespaceIndex), NodeHandleType.ExternalPolled, null ); variable.AccessLevel = AccessLevels.CurrentReadOrWrite; // SetVariableDefaultValue(variable.NodeId, new QualifiedName(BrowseNames.EURange), new Variant()); }
public override void Startup() { try { Console.WriteLine("Starting OpcNodeManager."); DefaultNamespaceIndex = AddNamespaceUri("OPCServer"); TypenamespaceIndex = AddNamespaceUri(OPCServer.Namespaces.OPCServer); Console.WriteLine("Loading the OPCServer model."); ImportUaNodeset(System.Reflection.Assembly.GetEntryAssembly(), "opcserver.xml"); Console.WriteLine("Create WeatherStation Node."); NodeId rootId = new NodeId("WeatherStation", DefaultNamespaceIndex); QualifiedName rootName = new QualifiedName("WeatherStation", DefaultNamespaceIndex); CreateObjectSettings settings = new CreateObjectSettings() { ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder, ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes, RequestedNodeId = rootId, BrowseName = rootName, TypeDefinitionId = new NodeId(OPCServer.ObjectTypes.WeatherStationType, TypenamespaceIndex) }; CreateObject(Server.DefaultRequestContext, settings); WeatherStation = new OPCServer.WeatherStationModel(); Weather.City = "Krakow"; Weather.getCurrentConditions(); Weather.getForecast(); Weather.conditionsPrintToFile(); Weather.forecastPrintToFile(); WeatherStation.Conditions = Weather.Conditions; WeatherStation.Forecast = Weather.Forecast; LinkModelToNode(rootId, WeatherStation, null, null, 500); Console.WriteLine("Make the OpcNodeManager the implementator of Methods defined on the Object."); WeatherStation.WeatherStationMethods = this; Timer t = new Timer(TimeSpan.FromMinutes(15).TotalMilliseconds); // set the time t.AutoReset = true; t.Elapsed += new System.Timers.ElapsedEventHandler(update); t.Start(); } catch (Exception e) { Console.WriteLine("Failed to start OpcNodeManager " + e.Message); } }