public SourceController(BaseDataVariableState source, AlarmController controller) { m_source = source; m_controller = controller; }
/// <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) { #region Setup IList <IReference> references = null; if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>(); } #endregion try { #region Initialize string alarmsName = "Alarms"; string alarmsNodeName = alarmsName; Type alarmControllerType = Type.GetType("Alarms.AlarmController"); int interval = 1000; string intervalString = interval.ToString(); int conditionTypeIndex = 0; #endregion #region Create Alarm Folder FolderState alarmsFolder = CreateFolder(null, alarmsNodeName, alarmsName); alarmsFolder.AddReference(ReferenceTypes.Organizes, true, ObjectIds.ObjectsFolder); references.Add(new NodeStateReference(ReferenceTypes.Organizes, false, alarmsFolder.NodeId)); alarmsFolder.EventNotifier = EventNotifiers.SubscribeToEvents; AddRootNotifier(alarmsFolder); #endregion #region Create Methods string startMethodName = "Start"; string startMethodNodeName = alarmsNodeName + "." + startMethodName; MethodState startMethod = AlarmHelpers.CreateMethod(alarmsFolder, NamespaceIndex, startMethodNodeName, startMethodName); AlarmHelpers.AddStartInputParameters(startMethod, NamespaceIndex); startMethod.OnCallMethod = new GenericMethodCalledEventHandler(OnStart); string startBranchMethodName = "StartBranch"; string startBranchMethodNodeName = alarmsNodeName + "." + startBranchMethodName; MethodState startBranchMethod = AlarmHelpers.CreateMethod(alarmsFolder, NamespaceIndex, startBranchMethodNodeName, startBranchMethodName); AlarmHelpers.AddStartInputParameters(startBranchMethod, NamespaceIndex); startBranchMethod.OnCallMethod = new GenericMethodCalledEventHandler(OnStartBranch); string endMethodName = "End"; string endMethodNodeName = alarmsNodeName + "." + endMethodName; MethodState endMethod = AlarmHelpers.CreateMethod(alarmsFolder, NamespaceIndex, endMethodNodeName, endMethodName); endMethod.OnCallMethod = new GenericMethodCalledEventHandler(OnEnd); #endregion #region Create Variables string analogTriggerName = "AnalogSource"; string analogTriggerNodeName = alarmsNodeName + "." + analogTriggerName; BaseDataVariableState analogTrigger = AlarmHelpers.CreateVariable(alarmsFolder, NamespaceIndex, analogTriggerNodeName, analogTriggerName); analogTrigger.OnWriteValue = OnWriteAlarmTrigger; AlarmController analogAlarmController = (AlarmController)Activator.CreateInstance(alarmControllerType, analogTrigger, interval, false); SourceController analogSourceController = new SourceController(analogTrigger, analogAlarmController); m_triggerMap.Add("Analog", analogSourceController); string booleanTriggerName = "BooleanSource"; string booleanTriggerNodeName = alarmsNodeName + "." + booleanTriggerName; BaseDataVariableState booleanTrigger = AlarmHelpers.CreateVariable(alarmsFolder, NamespaceIndex, booleanTriggerNodeName, booleanTriggerName, boolValue: true); booleanTrigger.OnWriteValue = OnWriteAlarmTrigger; AlarmController booleanAlarmController = (AlarmController)Activator.CreateInstance(alarmControllerType, booleanTrigger, interval, true); SourceController booleanSourceController = new SourceController(booleanTrigger, booleanAlarmController); m_triggerMap.Add("Boolean", booleanSourceController); #endregion #region Create Alarms AlarmHolder mandatoryExclusiveLevel = new ExclusiveLevelHolder( this, alarmsFolder, analogSourceController, intervalString, GetSupportedAlarmConditionType(ref conditionTypeIndex), alarmControllerType, interval, optional: false); m_alarms.Add(mandatoryExclusiveLevel.AlarmNodeName, mandatoryExclusiveLevel); AlarmHolder mandatoryNonExclusiveLevel = new NonExclusiveLevelHolder( this, alarmsFolder, analogSourceController, intervalString, GetSupportedAlarmConditionType(ref conditionTypeIndex), alarmControllerType, interval, optional: false); m_alarms.Add(mandatoryNonExclusiveLevel.AlarmNodeName, mandatoryNonExclusiveLevel); AlarmHolder offNormal = new OffNormalAlarmTypeHolder( this, alarmsFolder, booleanSourceController, intervalString, GetSupportedAlarmConditionType(ref conditionTypeIndex), alarmControllerType, interval, optional: false); m_alarms.Add(offNormal.AlarmNodeName, offNormal); #endregion AddPredefinedNode(SystemContext, alarmsFolder); StartTimer(); m_allowEntry = true; } catch (Exception e) { Utils.LogError(e, "Error creating the AlarmNodeManager address space."); } } }