public CodeGenObjectTypeBase CreateObject( Dictionary <CodeGenNodeID, CodeGenNodeID> childrenIDMap, NodeState parent, string fileNoExtension, string name, string typeId, ushort typeNamespaceIndex, IdType typeNodeIdType, string nodeId, ushort namespaceIndex, IdType nodeIdType, string parentNodeId, ushort parentNamespaceIndex, IdType parentNodeIdType) { BaseObjectState obj = new BaseObjectState(parent); obj.SymbolicName = name; obj.TypeDefinitionId = Helper.CreateID(typeId, typeNamespaceIndex, typeNodeIdType); obj.NodeId = Helper.CreateID(childrenIDMap, this, nodeId, namespaceIndex, nodeIdType); obj.BrowseName = new QualifiedName(name, NamespaceIndex); obj.DisplayName = obj.BrowseName.Name; obj.UserWriteMask = AttributeWriteMask.None; obj.EventNotifier = EventNotifiers.None; if (parent != null) { parent.AddChild(obj); } CodeGenObjectTypeBase newNode = CodeGenNodeFactory.CreateObject(name, fileNoExtension, typeId, typeNamespaceIndex, typeNodeIdType, nodeId, namespaceIndex, nodeIdType, parentNodeId, parentNamespaceIndex, parentNodeIdType); newNode.SetNode(obj); newNode.Initialize(childrenIDMap, this); return(newNode); }
/// <summary> /// Returns the next child. /// </summary> private NodeStateReference NextChild(Stage stage) { // fetch children. if (stage == Stage.Children) { if (m_browser == null) { return(null); } BaseObjectState node = m_browser.Next(SystemContext, m_namespaceIndex); if (node != null) { return(new NodeStateReference(ReferenceTypeIds.HasNotifier, false, node.NodeId)); } // all done. return(null); } // fetch child parents. if (stage == Stage.Parents) { return(null); } return(null); }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { base.CreateAddressSpace(externalReferences); #region Task #A1 - Create Root Folder // create the root folder. BaseObjectState root = CreateFolderNode("x:\\Work"); // ensure root can be found via the server object. IList <IReference> references = null; if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>(); } root.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder); references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, root.NodeId)); // save the node for later lookup. AddPredefinedNode(SystemContext, root); #endregion } }
/// <summary> /// Does the simulation. /// </summary> /// <param name="state">The state.</param> private void DoSimulation(object state) { try { { DataRow row = m_generator.GenerateFluidLevelTestReport(); BaseObjectState well = (BaseObjectState)FindPredefinedNode(new NodeId((string)row[BrowseNames.UidWell], NamespaceIndex), typeof(BaseObjectState)); if (well != null && well.AreEventsMonitored) { BaseEventState e = m_generator.GetFluidLevelTestReport(SystemContext, NamespaceIndex, row); well.ReportEvent(SystemContext, e); } } { DataRow row = m_generator.GenerateInjectionTestReport(); BaseObjectState well = (BaseObjectState)FindPredefinedNode(new NodeId((string)row[BrowseNames.UidWell], NamespaceIndex), typeof(BaseObjectState)); if (well != null && well.AreEventsMonitored) { BaseEventState e = m_generator.GetInjectionTestReport(SystemContext, NamespaceIndex, row); well.ReportEvent(SystemContext, e); } } } catch (Exception e) { Utils.Trace(e, "Unexpected error during simulation."); } }
/// <summary> /// Bind each TCD_Interface node to separate TCDSimulator. /// </summary> protected override NodeState AddBehaviourToPredefinedNode(ISystemContext context, NodeState predefinedNode) { BaseObjectState passiveNode = predefinedNode as BaseObjectState; if (passiveNode != null) { NodeId typeId = passiveNode.TypeDefinitionId; if (IsNodeIdInNamespace(typeId) && typeId.IdType == IdType.Numeric && (uint)typeId.Identifier == ObjectTypes.TCD_Interface) { // Found a TCD_Interface. If it is not already an active node, then replace it with one. TCD_InterfaceState activeNode = passiveNode as TCD_InterfaceState; if (activeNode == null) { activeNode = new TCD_InterfaceState(passiveNode.Parent); activeNode.Create(context, passiveNode); if (passiveNode.Parent != null) { passiveNode.Parent.ReplaceChild(context, activeNode); } } // Now that we have an active node, bind it to a simulator. TCDSimulator simulator = CreateSimulatorForNode(activeNode); if (simulator != null) { simulator.AddListener(activeNode); simulator.SetLogger(m_Logger); simulator.StartSimulation(); m_Simulators.Add(simulator); // Prevent it from being disposed } return(activeNode); } } return(predefinedNode); }
private PropertyState BuildPropertyState(BaseObjectState trigger, string targetName, string targetSimpleName, NodeId dataTypeId) { PropertyState property = new PropertyState(trigger); property.NodeId = new NodeId(targetName, NamespaceIndex); property.BrowseName = new QualifiedName(targetSimpleName, NamespaceIndex); property.DisplayName = property.BrowseName.Name; property.TypeDefinitionId = VariableTypeIds.PropertyType; property.ReferenceTypeId = ReferenceTypeIds.HasProperty; property.WriteMask = AttributeWriteMask.None; property.UserWriteMask = AccessLevels.None; property.AccessLevel = (byte)AccessLevels.CurrentReadOrWrite; property.UserAccessLevel = (byte)AccessLevels.CurrentReadOrWrite; property.MinimumSamplingInterval = MinimumSamplingIntervals.Continuous; property.Historizing = false; property.AccessRestrictions = AccessRestrictionType.None; property.ValueRank = ValueRanks.Scalar; property.DataType = dataTypeId; property.OnWriteValue = Property_NodeValueEventHandler; //object value = DataSource.ParseTargetValue(dataTypeId, manager.GetTargetValue(string.Format("ns=2;s={0}", targetName))); //if (value != null) property.Value = value; return(property); }
/// <summary> /// Replaces the generic node with a node specific to the model. /// </summary> protected override NodeState AddBehaviourToPredefinedNode(ISystemContext context, NodeState predefinedNode) { BaseObjectState passiveNode = predefinedNode as BaseObjectState; if (passiveNode == null) { return(predefinedNode); } NodeId typeId = passiveNode.TypeDefinitionId; if (!IsNodeIdInNamespace(typeId) || typeId.IdType != IdType.Numeric) { return(predefinedNode); } switch ((uint)typeId.Identifier) { // Write cases in same way for all defined ObjectTypes case ObjectTypes.ChatLogsType: { if (passiveNode is ChatLogsState) { break; } ChatLogsState activeNode = new ChatLogsState(passiveNode.Parent); activeNode.Create(context, passiveNode); if (passiveNode.Parent != null) { passiveNode.Parent.ReplaceChild(context, activeNode); } return(activeNode); } case ObjectTypes.ChatLogEventType: { if (passiveNode is ChatLogEventState) { break; } ChatLogEventState activeNode = new ChatLogEventState(passiveNode.Parent); activeNode.Create(context, passiveNode); if (passiveNode.Parent != null) { passiveNode.Parent.ReplaceChild(context, activeNode); } return(activeNode); } } return(predefinedNode); }
public static WrappedBaseObjectState Create (ISystemContext context, BaseObjectState source, InstanceConfiguration dataSourceConfiguration) { WrappedBaseObjectState ret = new WrappedBaseObjectState(source.Parent); ret.Initialize(context, source); return(ret); }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { BaseObjectState trigger = new BaseObjectState(null); trigger.NodeId = new NodeId(1, NamespaceIndex); trigger.BrowseName = new QualifiedName("Trigger", NamespaceIndex); trigger.DisplayName = trigger.BrowseName.Name; trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType; // ensure trigger can be found via the server object. IList <IReference> references = null; if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>(); } trigger.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder); references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, trigger.NodeId)); PropertyState property = new PropertyState(trigger); property.NodeId = new NodeId(2, NamespaceIndex); property.BrowseName = new QualifiedName("Matrix", NamespaceIndex); property.DisplayName = property.BrowseName.Name; property.TypeDefinitionId = VariableTypeIds.PropertyType; property.ReferenceTypeId = ReferenceTypeIds.HasProperty; property.DataType = DataTypeIds.Int32; property.ValueRank = ValueRanks.TwoDimensions; property.ArrayDimensions = new ReadOnlyList <uint>(new uint[] { 2, 2 }); trigger.AddChild(property); // save in dictionary. AddPredefinedNode(SystemContext, trigger); ReferenceTypeState referenceType = new ReferenceTypeState(); referenceType.NodeId = new NodeId(3, NamespaceIndex); referenceType.BrowseName = new QualifiedName("IsTriggerSource", NamespaceIndex); referenceType.DisplayName = referenceType.BrowseName.Name; referenceType.InverseName = new LocalizedText("IsSourceOfTrigger"); referenceType.SuperTypeId = ReferenceTypeIds.NonHierarchicalReferences; if (!externalReferences.TryGetValue(ObjectIds.Server, out references)) { externalReferences[ObjectIds.Server] = references = new List <IReference>(); } trigger.AddReference(referenceType.NodeId, false, ObjectIds.Server); references.Add(new NodeStateReference(referenceType.NodeId, true, trigger.NodeId)); // save in dictionary. AddPredefinedNode(SystemContext, referenceType); } }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { LoadPredefinedNodes(SystemContext, externalReferences); //// find the untyped Boiler1 node that was created when the model was loaded. //BaseObjectState passiveNode = (BaseObjectState)FindPredefinedNode(new NodeId(Objects.Boiler1, NamespaceIndexes[0]), typeof(BaseObjectState)); //// convert the untyped node to a typed node that can be manipulated within the server. //m_boiler1 = new BoilerState(null); //m_boiler1.Create(SystemContext, passiveNode); //// replaces the untyped predefined nodes with their strongly typed versions. //AddPredefinedNode(SystemContext, m_boiler1); //// create a boiler node. //m_boiler2 = new BoilerState(null); //// initialize it from the type model and assign unique node ids. //m_boiler2.Create( // SystemContext, // null, // new QualifiedName("Boiler #2", NamespaceIndexes[1]), // null, // true); //// link root to objects folder. //IList<IReference> references = null; //if (!externalReferences.TryGetValue(Opc.Ua.ObjectIds.ObjectsFolder, out references)) //{ // externalReferences[Opc.Ua.ObjectIds.ObjectsFolder] = references = new List<IReference>(); //} //references.Add(new NodeStateReference(Opc.Ua.ReferenceTypeIds.Organizes, false, m_boiler2.NodeId)); //// store it and all of its children in the pre-defined nodes dictionary for easy look up. //AddPredefinedNode(SystemContext, m_boiler2); // find the untyped Boiler1 node that was created when the model was loaded. BaseObjectState passiveNode = (BaseObjectState)FindPredefinedNode(new NodeId(Objects.Rpi, NamespaceIndexes[0]), typeof(BaseObjectState)); // convert the untyped node to a typed node that can be manipulated within the server. m_Rpi = new RpiState(null); m_Rpi.Create(SystemContext, passiveNode); // replaces the untyped predefined nodes with their strongly typed versions. AddPredefinedNode(SystemContext, m_Rpi); // start a simulation that changes the values of the nodes. m_refreshTimer = new Timer(DoRefresh, null, 5000, 5000); } }
/// <summary> /// Recusively finds the branch. /// </summary> private BaseObjectState FindBranch(ISystemContext context, string parentId, string itemId, ushort namespaceIndex) { // remove the enumerator. if (m_enumerator != null) { m_enumerator.Dispose(); m_enumerator = null; } // find item at current level. m_enumerator = CreateEnumerator(true); List <string> children = new List <string>(); do { // fetch the next name. string name = m_enumerator.Next(); // a null indicates the end of list. if (name == null) { break; } // create the node. string targetId = GetBranchPosition(parentId, name); if (itemId == targetId) { return(new HdaBranchState(itemId, name, namespaceIndex)); } children.Add(targetId); }while (true); // recursively search for item ids. for (int ii = 0; ii < children.Count; ii++) { if (!ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_DIRECT, children[ii])) { continue; } BaseObjectState node = FindBranch(context, children[ii], itemId, namespaceIndex); if (node != null) { return(node); } } m_completed = true; return(null); }
/// <summary> /// Replaces the generic node with a node specific to the model. /// </summary> protected override NodeState AddBehaviourToPredefinedNode(ISystemContext context, NodeState predefinedNode) { BaseObjectState passiveNode = predefinedNode as BaseObjectState; if (passiveNode == null) { return(predefinedNode); } NodeId typeId = passiveNode.TypeDefinitionId; if (!IsNodeIdInNamespace(typeId) || typeId.IdType != IdType.Numeric) { return(predefinedNode); } switch ((uint)typeId.Identifier) { case ObjectTypes.BoilerType: { if (passiveNode is BoilerState) { break; } BoilerState activeNode = new BoilerState(passiveNode.Parent); activeNode.Create(context, passiveNode); // replace the node in the parent. if (passiveNode.Parent != null) { passiveNode.Parent.ReplaceChild(context, activeNode); } // Autostart boiler simulation state machine MethodState start = (MethodState)activeNode.Simulation.FindChild(context, Opc.Ua.BrowseNames.Start); if (start != null) { IList <Variant> inputArguments = new List <Variant>(); IList <Variant> outputArguments = new List <Variant>(); List <ServiceResult> errors = new List <ServiceResult>(); start.Call(context, activeNode.NodeId, inputArguments, errors, outputArguments); } return(activeNode); } } return(predefinedNode); }
/// <summary> /// Verifies that the specified node exists. /// </summary> protected override NodeState ValidateNode( ServerSystemContext context, NodeHandle handle, IDictionary <NodeId, NodeState> cache) { // not valid if no root. if (handle == null) { return(null); } // check if previously validated. if (handle.Validated) { return(handle.Node); } // lookup in operation cache. NodeState target = FindNodeInCache(context, handle, cache); if (target != null) { handle.Node = target; handle.Validated = true; return(handle.Node); } #region Task #A5 - Add Support for External Nodes ParsedNodeId nodeId = (ParsedNodeId)handle.ParsedNodeId; BaseObjectState node = CreateFolderNode(nodeId.RootId); if (node == null) { return(null); } target = node; #endregion // put root into operation cache. if (cache != null) { cache[handle.NodeId] = target; } handle.Node = target; handle.Validated = true; return(handle.Node); }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { LogHelper.Instance.Info(string.Format("CreateAddressSpace {0} start.", channel.Name)); BaseObjectState trigger = new BaseObjectState(null); trigger.NodeId = new NodeId(1, NamespaceIndex); trigger.BrowseName = new QualifiedName(channel.Name, NamespaceIndex); trigger.DisplayName = trigger.BrowseName.Name; trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType; // ensure trigger can be found via the server object. IList <IReference> references = null; if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>(); } trigger.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder); references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, trigger.NodeId)); LoadNodeList(trigger); // save in dictionary. AddPredefinedNode(SystemContext, trigger); ReferenceTypeState referenceType = new ReferenceTypeState(); referenceType.NodeId = new NodeId(3, NamespaceIndex); referenceType.BrowseName = new QualifiedName("IsTriggerSource", NamespaceIndex); referenceType.DisplayName = referenceType.BrowseName.Name; referenceType.InverseName = new LocalizedText("IsSourceOfTrigger"); referenceType.SuperTypeId = ReferenceTypeIds.NonHierarchicalReferences; if (!externalReferences.TryGetValue(ObjectIds.Server, out references)) { externalReferences[ObjectIds.Server] = references = new List <IReference>(); } trigger.AddReference(referenceType.NodeId, false, ObjectIds.Server); references.Add(new NodeStateReference(referenceType.NodeId, true, trigger.NodeId)); // save in dictionary. AddPredefinedNode(SystemContext, referenceType); LogHelper.Instance.Info("CreateAddressSpace."); } }
/// <summary> /// Creates a new well. /// </summary> private void CreateWell(SystemContext context, BaseObjectState area, string wellId, string wellName) { WellState well = new WellState(null); well.NodeId = new NodeId(wellId, NamespaceIndex); well.BrowseName = new QualifiedName(wellName, NamespaceIndex); well.DisplayName = wellName; well.EventNotifier = EventNotifiers.SubscribeToEvents | EventNotifiers.HistoryRead | EventNotifiers.HistoryWrite; well.TypeDefinitionId = new NodeId(ObjectTypes.WellType, NamespaceIndex); area.AddNotifier(SystemContext, Opc.Ua.ReferenceTypeIds.HasNotifier, false, well); well.AddNotifier(SystemContext, Opc.Ua.ReferenceTypeIds.HasNotifier, true, area); AddPredefinedNode(SystemContext, well); }
public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences) { lock (Lock) { LoadPredefinedNodes(SystemContext, externalReferences); BaseObjectState passiveNode = (BaseObjectState)FindPredefinedNode(new NodeId( Objects.Machine, NamespaceIndexes[0]), typeof(BaseObjectState)); machineState = new MachineState(null); machineState.Create(SystemContext, passiveNode); AddPredefinedNode(SystemContext, machineState); machineState.RegistPublishers(SystemContext); m_refreshTimer = new Timer(DoRefresh, null, 10, 10); } }
private void addSelectedNodeAsChild(BaseInstanceState parentNode) { ReferenceDescription selectedNode = this.BrowseCTRL.SelectedNode; if (selectedNode.NodeClass == NodeClass.Variable) { ReadValueId nodeToRead = new ReadValueId(); nodeToRead.NodeId = (NodeId)selectedNode.NodeId; nodeToRead.AttributeId = Attributes.Value; nodeToRead.Handle = selectedNode; ReadValueIdCollection nodesToRead = new ReadValueIdCollection(); nodesToRead.Add(nodeToRead); DataValueCollection results = null; DiagnosticInfoCollection diagnosticInfos = null; this.connectServerCtrl1.Session.Read(null, 0, TimestampsToReturn.Neither, nodesToRead, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, nodesToRead); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead); TypeInfo varInfo = TypeInfo.Construct(results[0].Value); BaseVariableState varNode = new BaseDataVariableState(parentNode); varNode.ValueRank = varInfo.ValueRank; varNode.WrappedValue = results[0].WrappedValue; varNode.NodeId = (NodeId)selectedNode.NodeId; varNode.BrowseName = new QualifiedName(selectedNode.DisplayName.Text, (ushort)m_server.getNamespaceIndex(this.connectServerCtrl1.Session.NamespaceUris.GetString(selectedNode.BrowseName.NamespaceIndex))); varNode.DisplayName = varNode.BrowseName.Name; m_server.addNode(varNode, parentNode.NodeId); m_server.addVariableConnection(varNode, selectedNode, this.connectServerCtrl1.ServerUrl); } else { BaseObjectState child = new BaseObjectState(parentNode); uint nodeid_ident; if (UInt32.TryParse(selectedNode.NodeId.Identifier.ToString(), out nodeid_ident)) { child.NodeId = new NodeId(nodeid_ident); } else { child.NodeId = new NodeId(selectedNode.NodeId.Identifier.ToString()); } child.BrowseName = selectedNode.BrowseName; child.DisplayName = child.BrowseName.Name; this.m_server.addNode(child, parentNode.NodeId); } }
private void LoadNodeList(BaseObjectState trigger) { LogHelper.Instance.Info(string.Format("Nodes number:{0}.", channel.Nodes.Values.Count)); foreach (var node in channel.Nodes.Values) { node.SystemContext = this.SystemContext; node.NamespaceIndex = NamespaceIndex; node.Trigger = trigger; PropertyState property = BuildPropertyState(trigger, node.Key, node.Name, DataTypeHelper.GetDataTypeId(node.OpcNodeType)); node.OpcNode = property; trigger.AddChild(property); //LogHelper.Instance.Info(string.Format("Node:{0} is OK.",node.Key)); } }
/// <summary> /// Creates a new area. /// </summary> private BaseObjectState CreateArea(SystemContext context, BaseObjectState platforms, string areaName) { FolderState area = new FolderState(null); area.NodeId = new NodeId(areaName, NamespaceIndex); area.BrowseName = new QualifiedName(areaName, NamespaceIndex); area.DisplayName = area.BrowseName.Name; area.EventNotifier = EventNotifiers.SubscribeToEvents | EventNotifiers.HistoryRead | EventNotifiers.HistoryWrite; area.TypeDefinitionId = Opc.Ua.ObjectTypeIds.FolderType; platforms.AddNotifier(SystemContext, Opc.Ua.ReferenceTypeIds.HasNotifier, false, area); area.AddNotifier(SystemContext, Opc.Ua.ReferenceTypeIds.HasNotifier, true, platforms); AddPredefinedNode(SystemContext, area); return(area); }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { // create a object to represent the process being controlled. BaseObjectState process = new BaseObjectState(null); process.NodeId = new NodeId(1, NamespaceIndex); process.BrowseName = new QualifiedName("My Process", NamespaceIndex); process.DisplayName = process.BrowseName.Name; process.TypeDefinitionId = ObjectTypeIds.BaseObjectType; // ensure the process object can be found via the server object. IList <IReference> references = null; if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>(); } process.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder); references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, process.NodeId)); // a property to report the process state. PropertyState <string> state = new PropertyState <string>(process); state.NodeId = new NodeId(2, NamespaceIndex); state.BrowseName = new QualifiedName("LogFilePath", NamespaceIndex); state.DisplayName = state.BrowseName.Name; state.TypeDefinitionId = VariableTypeIds.PropertyType; state.ReferenceTypeId = ReferenceTypeIds.HasProperty; state.DataType = DataTypeIds.String; state.ValueRank = ValueRanks.Scalar; state.AccessLevel = AccessLevels.CurrentReadOrWrite; state.UserAccessLevel = AccessLevels.CurrentRead; state.Value = ".\\Log.txt"; process.AddChild(state); state.OnReadUserAccessLevel = OnReadUserAccessLevel; state.OnSimpleWriteValue = OnWriteValue; // save in dictionary. AddPredefinedNode(SystemContext, process); } }
/// <summary> /// Creates a new well. /// </summary> private void CreateWell(SystemContext context, BaseObjectState area, string wellId, string wellName) { System.Diagnostics.Contracts.Contract.Assume(context != null); var well = new WellState(null) { NodeId = new NodeId(wellId, NamespaceIndex), BrowseName = new QualifiedName(wellName, NamespaceIndex), DisplayName = wellName, EventNotifier = EventNotifiers.SubscribeToEvents | EventNotifiers.HistoryRead | EventNotifiers.HistoryWrite, TypeDefinitionId = new NodeId(ObjectTypes.WellType, NamespaceIndex) }; area.AddNotifier(SystemContext, ReferenceTypeIds.HasNotifier, false, well); well.AddNotifier(SystemContext, ReferenceTypeIds.HasNotifier, true, area); AddPredefinedNode(SystemContext, well); }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { //----------------- A few examples of hard coded nodes in the Address Space ------------------- //counter for the NodeId identifier: uint id = 1; //a first node: BaseObjectState testObjectNode = new BaseObjectState(null); // Set the attributes: testObjectNode.NodeId = new NodeId(id++, NamespaceIndex); testObjectNode.BrowseName = new QualifiedName("test_ObjectNode", NamespaceIndex); testObjectNode.DisplayName = testObjectNode.BrowseName.Name; testObjectNode.TypeDefinitionId = ObjectTypeIds.BaseObjectType; // ensure testObjectNode can be found via the server object: add references to/from it! IList <IReference> references = null; if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>(); } testObjectNode.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder); references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, testObjectNode.NodeId)); //a second node: PropertyState testPropertyNode = new PropertyState(testObjectNode); // Set the attributes: testPropertyNode.NodeId = new NodeId(id++, NamespaceIndex); testPropertyNode.BrowseName = new QualifiedName("test_PropertyNode", NamespaceIndex); testPropertyNode.DisplayName = testPropertyNode.BrowseName.Name; testPropertyNode.TypeDefinitionId = VariableTypeIds.PropertyType; testPropertyNode.ReferenceTypeId = ReferenceTypeIds.HasProperty; testPropertyNode.DataType = DataTypeIds.Int32; testPropertyNode.ValueRank = ValueRanks.OneDimension; testPropertyNode.ArrayDimensions = new ReadOnlyList <uint>(new uint[] { 5 }); testPropertyNode.Value = new int[] { 7, -18, 56, 0, 3 }; //add this node as a child of the previous node: testObjectNode.AddChild(testPropertyNode); // save in dictionary. AddPredefinedNode(SystemContext, testObjectNode); //--------------------------------------------------------------------------------------------- } }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { LoadPredefinedNodes(SystemContext, externalReferences); // find the untyped Rig node that was created when the model was loaded. BaseObjectState passiveNode = (BaseObjectState)FindPredefinedNode(new NodeId(DsatsDemo.Objects.Rig, NamespaceIndex), typeof(BaseObjectState)); // convert the untyped node to a typed node that can be manipulated within the server. m_rig = new RigState(null); m_rig.Create(SystemContext, passiveNode); m_rig.ChangePhase.OnCall = OnChangePhase; m_rig.ChangePhaseWithString.OnWriteValue = OnChangePhaseByWrite; m_rig.ChangePhaseWithString.OnSimpleReadValue = OnReadPhase; // replaces the untyped predefined nodes with their strongly typed versions. AddPredefinedNode(SystemContext, m_rig); // need to refresh the root notifier now that the object has changed. AddRootNotifier(m_rig); // load the info for the datasources. LoadDataSource(SystemContext); // connect to server (only one active server supported at this time). if (m_remoteNodes != null) { foreach (RemoteNode node in m_remoteNodes.Values) { m_source.Connect(node.ServerUrl, m_configuration.UseSecurity); break; } } // update the lock ids for the default phase. if (m_currentPhase != null) { m_rig.CurrentPhase.Value = m_currentPhase; ChangePhase(SystemContext, m_currentPhase); } } }
/// <summary> /// Converts a ReferenceDescription to an IReference. /// </summary> private IReference ToReference(ReferenceDescription reference) { if (reference.NodeId.IsAbsolute || reference.TypeDefinition.IsAbsolute) { return(new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, reference.NodeId)); } if (m_source != null && (reference.NodeId == ObjectIds.ObjectsFolder || reference.NodeId == ObjectIds.Server)) { return(new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, m_rootId)); } NodeState target = null; switch (reference.NodeClass) { case NodeClass.DataType: { target = new DataTypeState(); break; } case NodeClass.Method: { target = new MethodState(null); break; } case NodeClass.Object: { target = new BaseObjectState(null); break; } case NodeClass.ObjectType: { target = new BaseObjectTypeState(); break; } case NodeClass.ReferenceType: { target = new ReferenceTypeState(); break; } case NodeClass.Variable: { target = new BaseDataVariableState(null); break; } case NodeClass.VariableType: { target = new BaseDataVariableTypeState(); break; } case NodeClass.View: { target = new ViewState(); break; } } target.NodeId = m_mapper.ToLocalId((NodeId)reference.NodeId); target.BrowseName = m_mapper.ToLocalName(reference.BrowseName); target.DisplayName = reference.DisplayName; if (target is BaseInstanceState) { ((BaseInstanceState)target).TypeDefinitionId = m_mapper.ToLocalId((NodeId)reference.TypeDefinition); } return(new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, target)); }
/// <summary> /// Finds the child with the specified browse name. /// </summary> protected override BaseInstanceState FindChild( ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement) { if (QualifiedName.IsNull(browseName)) { return(null); } BaseInstanceState instance = null; switch (browseName.Name) { case Opc.Ua.Di.BrowseNames.ParameterSet: { if (createOrReplace) { if (ParameterSet == null) { if (replacement == null) { ParameterSet = new BaseObjectState(this); } else { ParameterSet = (BaseObjectState)replacement; } } } instance = ParameterSet; break; } } if (instance != null) { return(instance); } return(base.FindChild(context, browseName, createOrReplace, replacement)); }
/// <summary> /// Create object /// </summary> /// <param name="parent"></param> /// <param name="sourceObject"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public BaseObjectState CreateObject(BaseObjectState parent, ReferenceDescription sourceObject) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (sourceObject == null) { throw new ArgumentNullException(nameof(sourceObject)); } this.VerifyNodeManagerCreated(); var path = sourceObject.NodeId.Identifier.ToString(); var name = sourceObject.DisplayName.Text; var baseObject = new BaseObjectState(parent: parent) { SymbolicName = name, ReferenceTypeId = ReferenceTypes.Organizes, TypeDefinitionId = ObjectTypeIds.BaseObjectType, NodeId = new NodeId(value: path, namespaceIndex: this.NodeManager.NamespaceIndex), BrowseName = new QualifiedName(name, this.NodeManager.NamespaceIndex), WriteMask = AttributeWriteMask.None, UserWriteMask = AttributeWriteMask.None, EventNotifier = EventNotifiers.None, Description = new LocalizedText(string.Empty, string.Empty), RolePermissions = new RolePermissionTypeCollection(), UserRolePermissions = new RolePermissionTypeCollection(), }; baseObject.DisplayName = baseObject.BrowseName.Name; if (parent != null) { parent.AddChild(child: baseObject); } return(baseObject); }
public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { LoadPredefinedNodes(SystemContext, externalReferences); // find the untyped Batch Plant 1 node that was created when the model was loaded. BaseObjectState passiveNode = (BaseObjectState)FindPredefinedNode(new NodeId(Objects.Bike, NamespaceIndexes[0]), typeof(BaseObjectState)); // convert the untyped node to a typed node that can be manipulated within the server. opcUaServer = new BikeState(null); opcUaServer.Create(SystemContext, passiveNode); // replaces the untyped predefined nodes with their strongly typed versions. AddPredefinedNode(SystemContext, opcUaServer); simulationTimer = new Timer(DoSimulation, null, 1000, 1000); } }
internal BaseObjectState CreateObject(NodeState parent, string path, string name, ushort namespaceIndex) { BaseObjectState folder = new BaseObjectState(parent); folder.SymbolicName = name; folder.ReferenceTypeId = ReferenceTypes.Organizes; folder.TypeDefinitionId = ObjectTypeIds.BaseObjectType; folder.NodeId = new NodeId(path, namespaceIndex); folder.BrowseName = new QualifiedName(name, namespaceIndex); folder.DisplayName = folder.BrowseName.Name; folder.WriteMask = AttributeWriteMask.None; folder.UserWriteMask = AttributeWriteMask.None; folder.EventNotifier = EventNotifiers.None; if (parent != null) { parent.AddChild(folder); } return(folder); }
protected override NodeState AddBehaviourToPredefinedNode(ISystemContext context, NodeState predefinedNode) { BaseObjectState passiveNode = predefinedNode as BaseObjectState; if (passiveNode == null) { return(predefinedNode); } NodeId typeId = passiveNode.TypeDefinitionId; if (!IsNodeIdInNamespace(typeId) || typeId.IdType != IdType.Numeric) { return(predefinedNode); } switch ((uint)typeId.Identifier) { case ObjectTypes.StationType: { if (passiveNode is StationState) { break; } StationState activeNode = new StationState(passiveNode.Parent); activeNode.Create(context, passiveNode); // replace the node in the parent. if (passiveNode.Parent != null) { passiveNode.Parent.ReplaceChild(context, activeNode); } return(activeNode); } } return(predefinedNode); }
void LoadDataSourcePhases(ISystemContext context, DsatsDemo.DataSource.DataSource datasource) { if (datasource == null || datasource.Phase == null) { return; } foreach (DsatsDemo.DataSource.PhaseType phase in datasource.Phase) { BaseObjectState node = datasource.ReadPhase(context, phase); node.AddReference(Opc.Ua.ReferenceTypeIds.Organizes, true, m_rig.Phases.NodeId); m_rig.Phases.AddReference(Opc.Ua.ReferenceTypeIds.Organizes, false, node.NodeId); AddPredefinedNode(context, node); m_rig.SetPhase(node.NodeId); if (m_currentPhase == null) { m_currentPhase = node.NodeId; } } }
/// <summary> /// Imports a node from the set. /// </summary> private NodeState Import(ISystemContext context, UANode node) { NodeState importedNode = null; NodeClass nodeClass = NodeClass.Unspecified; if (node is UAObject) nodeClass = NodeClass.Object; else if (node is UAVariable) nodeClass = NodeClass.Variable; else if (node is UAMethod) nodeClass = NodeClass.Method; else if (node is UAObjectType) nodeClass = NodeClass.ObjectType; else if (node is UAVariableType) nodeClass = NodeClass.VariableType; else if (node is UADataType) nodeClass = NodeClass.DataType; else if (node is UAReferenceType) nodeClass = NodeClass.ReferenceType; else if (node is UAView) nodeClass = NodeClass.View; switch (nodeClass) { case NodeClass.Object: { UAObject o = (UAObject)node; BaseObjectState value = new BaseObjectState(null); value.EventNotifier = o.EventNotifier; importedNode = value; break; } case NodeClass.Variable: { UAVariable o = (UAVariable)node; NodeId typeDefinitionId = null; if (node.References != null) { for (int ii = 0; ii < node.References.Length; ii++) { Opc.Ua.NodeId referenceTypeId = ImportNodeId(node.References[ii].ReferenceType, context.NamespaceUris, true); bool isInverse = !node.References[ii].IsForward; Opc.Ua.ExpandedNodeId targetId = ImportExpandedNodeId(node.References[ii].Value, context.NamespaceUris, context.ServerUris); if (referenceTypeId == ReferenceTypeIds.HasTypeDefinition && !isInverse) { typeDefinitionId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris); break; } } } BaseVariableState value = null; if (typeDefinitionId == Opc.Ua.VariableTypeIds.PropertyType) { value = new PropertyState(null); } else { value = new BaseDataVariableState(null); } value.DataType = ImportNodeId(o.DataType, context.NamespaceUris, true); value.ValueRank = o.ValueRank; value.ArrayDimensions = ImportArrayDimensions(o.ArrayDimensions); value.AccessLevel = o.AccessLevel; value.UserAccessLevel = o.UserAccessLevel; value.MinimumSamplingInterval = o.MinimumSamplingInterval; value.Historizing = o.Historizing; if (o.Value != null) { XmlDecoder decoder = CreateDecoder(context, o.Value); TypeInfo typeInfo = null; value.Value = decoder.ReadVariantContents(out typeInfo); decoder.Close(); } importedNode = value; break; } case NodeClass.Method: { UAMethod o = (UAMethod)node; MethodState value = new MethodState(null); value.Executable = o.Executable; value.UserExecutable = o.UserExecutable; importedNode = value; break; } case NodeClass.View: { UAView o = (UAView)node; ViewState value = new ViewState(); value.ContainsNoLoops = o.ContainsNoLoops; importedNode = value; break; } case NodeClass.ObjectType: { UAObjectType o = (UAObjectType)node; BaseObjectTypeState value = new BaseObjectTypeState(); value.IsAbstract = o.IsAbstract; importedNode = value; break; } case NodeClass.VariableType: { UAVariableType o = (UAVariableType)node; BaseVariableTypeState value = new BaseDataVariableTypeState(); value.IsAbstract = o.IsAbstract; value.DataType = ImportNodeId(o.DataType, context.NamespaceUris, true); value.ValueRank = o.ValueRank; value.ArrayDimensions = ImportArrayDimensions(o.ArrayDimensions); if (o.Value != null) { XmlDecoder decoder = CreateDecoder(context, o.Value); TypeInfo typeInfo = null; value.Value = decoder.ReadVariantContents(out typeInfo); decoder.Close(); } importedNode = value; break; } case NodeClass.DataType: { UADataType o = (UADataType)node; DataTypeState value = new DataTypeState(); value.IsAbstract = o.IsAbstract; value.Definition = Import(o.Definition, context.NamespaceUris); importedNode = value; break; } case NodeClass.ReferenceType: { UAReferenceType o = (UAReferenceType)node; ReferenceTypeState value = new ReferenceTypeState(); value.IsAbstract = o.IsAbstract; value.InverseName = Import(o.InverseName); value.Symmetric = o.Symmetric; importedNode = value; break; } } importedNode.NodeId = ImportNodeId(node.NodeId, context.NamespaceUris, false); importedNode.BrowseName = ImportQualifiedName(node.BrowseName, context.NamespaceUris); importedNode.DisplayName = Import(node.DisplayName); importedNode.Description = Import(node.Description); importedNode.WriteMask = (AttributeWriteMask)node.WriteMask; importedNode.UserWriteMask = (AttributeWriteMask)node.UserWriteMask; if (!String.IsNullOrEmpty(node.SymbolicName)) { importedNode.SymbolicName = node.SymbolicName; } if (node.References != null) { BaseInstanceState instance = importedNode as BaseInstanceState; BaseTypeState type = importedNode as BaseTypeState; for (int ii = 0; ii < node.References.Length; ii++) { Opc.Ua.NodeId referenceTypeId = ImportNodeId(node.References[ii].ReferenceType, context.NamespaceUris, true); bool isInverse = !node.References[ii].IsForward; Opc.Ua.ExpandedNodeId targetId = ImportExpandedNodeId(node.References[ii].Value, context.NamespaceUris, context.ServerUris); if (instance != null) { if (referenceTypeId == ReferenceTypeIds.HasModellingRule && !isInverse) { instance.ModellingRuleId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris); continue; } if (referenceTypeId == ReferenceTypeIds.HasTypeDefinition && !isInverse) { instance.TypeDefinitionId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris); continue; } } if (type != null) { if (referenceTypeId == ReferenceTypeIds.HasSubtype && isInverse) { type.SuperTypeId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris); continue; } } importedNode.AddReference(referenceTypeId, isInverse, targetId); } } return importedNode; }