public override void SetValue(string message = "")
        {
            ExclusiveLimitAlarmState alarm = GetAlarm();
            int newSeverity     = GetSeverity();
            int currentSeverity = alarm.Severity.Value;

            if (newSeverity != currentSeverity)
            {
                LimitAlarmStates state = LimitAlarmStates.Inactive;

                if (newSeverity == AlarmDefines.HIGHHIGH_SEVERITY)
                {
                    state = LimitAlarmStates.HighHigh;
                }
                else if (newSeverity == AlarmDefines.HIGH_SEVERITY)
                {
                    state = LimitAlarmStates.High;
                }
                else if (newSeverity == AlarmDefines.LOW_SEVERITY)
                {
                    state = LimitAlarmStates.Low;
                }
                else if (newSeverity == AlarmDefines.LOWLOW_SEVERITY)
                {
                    state = LimitAlarmStates.LowLow;
                }

                alarm.SetLimitState(SystemContext, state);
            }

            base.SetValue(message);
        }
        public new void Initialize(
            uint alarmTypeIdentifier,
            string name,
            double maxTimeShelved = AlarmDefines.NORMAL_MAX_TIME_SHELVED)
        {
            // Create an alarm and trigger name - Create a base method for creating the trigger, just provide the name

            if (m_alarm == null)
            {
                m_alarm = new ExclusiveLimitAlarmState(m_parent);
            }

            ExclusiveLimitAlarmState alarm = GetAlarm();

            // Call the base class to set parameters
            base.Initialize(alarmTypeIdentifier, name, maxTimeShelved);

            alarm.SetLimitState(SystemContext, LimitAlarmStates.Inactive);
        }
Пример #3
0
        /// <summary>
        /// Updates the exclusive limit alarm event.
        /// </summary>
        private void UpdateExclusiveLimitAlarm(ExclusiveLimitAlarmState instance, EventType eventType, ONEVENTSTRUCT e)
        {
            NodeId state = null;
            string text  = null;

            if (AeTypeCache.IsKnownName(e.szSubconditionName, "HI HI"))
            {
                state = Opc.Ua.ObjectIds.ExclusiveLimitStateMachineType_HighHigh;
                text  = ConditionStateNames.HighHighActive;
            }

            if (AeTypeCache.IsKnownName(e.szSubconditionName, "HI"))
            {
                state = Opc.Ua.ObjectIds.ExclusiveLimitStateMachineType_High;
                text  = ConditionStateNames.HighActive;
            }

            if (AeTypeCache.IsKnownName(e.szSubconditionName, "LO"))
            {
                state = Opc.Ua.ObjectIds.ExclusiveLimitStateMachineType_Low;
                text  = ConditionStateNames.LowActive;
            }

            if (AeTypeCache.IsKnownName(e.szSubconditionName, "LO LO"))
            {
                state = Opc.Ua.ObjectIds.ExclusiveLimitStateMachineType_LowLow;
                text  = ConditionStateNames.LowLowActive;
            }

            instance.LimitState                         = new ExclusiveLimitStateMachineState(instance);
            instance.LimitState.BrowseName              = Opc.Ua.BrowseNames.LimitState;
            instance.LimitState.CurrentState            = new FiniteStateVariableState(instance.LimitState);
            instance.LimitState.CurrentState.BrowseName = Opc.Ua.BrowseNames.CurrentState;
            instance.LimitState.CurrentState.Value      = text;

            instance.LimitState.CurrentState.SetChildValue(m_defaultContext, Opc.Ua.BrowseNames.Id, state, false);
        }
Пример #4
0
        /// <summary>
        /// Updates the alarm with a new state.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="alarm">The alarm.</param>
        private void UpdateAlarm(AlarmConditionState node, UnderlyingSystemAlarm alarm)
        {
            ISystemContext context = m_nodeManager.SystemContext;

            // remove old event.
            if (node.EventId.Value != null)
            {
                m_events.Remove(Utils.ToHexString(node.EventId.Value));
            }

            // update the basic event information (include generating a unique id for the event).
            node.EventId.Value     = Guid.NewGuid().ToByteArray();
            node.Time.Value        = DateTime.UtcNow;
            node.ReceiveTime.Value = node.Time.Value;

            // save the event for later lookup.
            m_events[Utils.ToHexString(node.EventId.Value)] = node;

            // determine the retain state.
            node.Retain.Value = true;

            if (alarm != null)
            {
                node.Time.Value    = alarm.Time;
                node.Message.Value = new LocalizedText(alarm.Reason);

                // update the states.
                node.SetEnableState(context, (alarm.State & UnderlyingSystemAlarmStates.Enabled) != 0);
                node.SetAcknowledgedState(context, (alarm.State & UnderlyingSystemAlarmStates.Acknowledged) != 0);
                node.SetConfirmedState(context, (alarm.State & UnderlyingSystemAlarmStates.Confirmed) != 0);
                node.SetActiveState(context, (alarm.State & UnderlyingSystemAlarmStates.Active) != 0);
                node.SetSuppressedState(context, (alarm.State & UnderlyingSystemAlarmStates.Suppressed) != 0);

                // update other information.
                node.SetComment(context, alarm.Comment, alarm.UserName);
                node.SetSeverity(context, alarm.Severity);

                node.EnabledState.TransitionTime.Value = alarm.EnableTime;
                node.ActiveState.TransitionTime.Value  = alarm.ActiveTime;

                // check for deleted items.
                if ((alarm.State & UnderlyingSystemAlarmStates.Deleted) != 0)
                {
                    node.Retain.Value = false;
                }

                // handle high alarms.
                ExclusiveLimitAlarmState highAlarm = node as ExclusiveLimitAlarmState;

                if (highAlarm != null)
                {
                    highAlarm.HighLimit.Value = alarm.Limits[0];

                    if ((alarm.State & UnderlyingSystemAlarmStates.High) != 0)
                    {
                        highAlarm.SetLimitState(context, LimitAlarmStates.High);
                    }
                }

                // handle high-low alarms.
                NonExclusiveLimitAlarmState highLowAlarm = node as NonExclusiveLimitAlarmState;

                if (highLowAlarm != null)
                {
                    highLowAlarm.HighHighLimit.Value = alarm.Limits[0];
                    highLowAlarm.HighLimit.Value     = alarm.Limits[1];
                    highLowAlarm.LowLimit.Value      = alarm.Limits[2];
                    highLowAlarm.LowLowLimit.Value   = alarm.Limits[3];

                    LimitAlarmStates limit = LimitAlarmStates.Inactive;

                    if ((alarm.State & UnderlyingSystemAlarmStates.HighHigh) != 0)
                    {
                        limit |= LimitAlarmStates.HighHigh;
                    }

                    if ((alarm.State & UnderlyingSystemAlarmStates.High) != 0)
                    {
                        limit |= LimitAlarmStates.High;
                    }

                    if ((alarm.State & UnderlyingSystemAlarmStates.Low) != 0)
                    {
                        limit |= LimitAlarmStates.Low;
                    }

                    if ((alarm.State & UnderlyingSystemAlarmStates.LowLow) != 0)
                    {
                        limit |= LimitAlarmStates.LowLow;
                    }

                    highLowAlarm.SetLimitState(context, limit);
                }
            }

            // not interested in disabled or inactive alarms.
            if (!node.EnabledState.Id.Value || !node.ActiveState.Id.Value)
            {
                node.Retain.Value = false;
            }
        }
Пример #5
0
        /// <summary>
        /// Constructs an event object from a notification.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="monitoredItem">The monitored item that produced the notification.</param>
        /// <param name="notification">The notification.</param>
        /// <param name="eventTypeMappings">Mapping between event types and known event types.</param>
        /// <returns>
        /// The event object. Null if the notification is not a valid event type.
        /// </returns>
        public static BaseEventState ConstructEvent(
            Session session,
            MonitoredItem monitoredItem,
            EventFieldList notification,
            Dictionary <NodeId, NodeId> eventTypeMappings)
        {
            // find the event type.
            NodeId eventTypeId = FindEventType(monitoredItem, notification);

            if (eventTypeId == null)
            {
                return(null);
            }

            // look up the known event type.
            NodeId knownTypeId = null;

            if (!eventTypeMappings.TryGetValue(eventTypeId, out knownTypeId))
            {
                // check for a known type
                for (int jj = 0; jj < KnownEventTypes.Length; jj++)
                {
                    if (KnownEventTypes[jj] == eventTypeId)
                    {
                        knownTypeId = eventTypeId;
                        eventTypeMappings.Add(eventTypeId, eventTypeId);
                        break;
                    }
                }

                // browse for the supertypes of the event type.
                if (knownTypeId == null)
                {
                    ReferenceDescriptionCollection supertypes = FormUtils.BrowseSuperTypes(session, eventTypeId, false);

                    // can't do anything with unknown types.
                    if (supertypes == null)
                    {
                        return(null);
                    }

                    // find the first supertype that matches a known event type.
                    for (int ii = 0; ii < supertypes.Count; ii++)
                    {
                        for (int jj = 0; jj < KnownEventTypes.Length; jj++)
                        {
                            if (KnownEventTypes[jj] == supertypes[ii].NodeId)
                            {
                                knownTypeId = KnownEventTypes[jj];
                                eventTypeMappings.Add(eventTypeId, knownTypeId);
                                break;
                            }
                        }

                        if (knownTypeId != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (knownTypeId == null)
            {
                return(null);
            }

            // all of the known event types have a UInt32 as identifier.
            uint?id = knownTypeId.Identifier as uint?;

            if (id == null)
            {
                return(null);
            }

            // construct the event based on the known event type.
            BaseEventState e = null;

            switch (id.Value)
            {
            case ObjectTypes.ConditionType: { e = new ConditionState(null); break; }

            case ObjectTypes.DialogConditionType: { e = new DialogConditionState(null); break; }

            case ObjectTypes.AlarmConditionType: { e = new AlarmConditionState(null); break; }

            case ObjectTypes.ExclusiveLimitAlarmType: { e = new ExclusiveLimitAlarmState(null); break; }

            case ObjectTypes.NonExclusiveLimitAlarmType: { e = new NonExclusiveLimitAlarmState(null); break; }

            case ObjectTypes.AuditEventType: { e = new AuditEventState(null); break; }

            case ObjectTypes.AuditUpdateMethodEventType: { e = new AuditUpdateMethodEventState(null); break; }

            default:
            {
                e = new BaseEventState(null);
                break;
            }
            }

            // get the filter which defines the contents of the notification.
            EventFilter filter = monitoredItem.Status.Filter as EventFilter;

            // initialize the event with the values in the notification.
            if (session is null)
            {
                return(null);
            }
            e.Update(session.SystemContext, filter.SelectClauses, notification);

            // save the orginal notification.
            e.Handle = notification;

            return(e);
        }
Пример #6
0
        /// <summary>
        /// Constructs an event object from a notification.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="monitoredItem">The monitored item that produced the notification.</param>
        /// <param name="notification">The notification.</param>
        /// <param name="eventTypeMappings">Mapping between event types and known event types.</param>
        /// <returns>
        /// The event object. Null if the notification is not a valid event type.
        /// </returns>
        public static BaseEventState ConstructEvent(
            Session session,
            MonitoredItem monitoredItem,
            EventFieldList notification,
            Dictionary <NodeId, NodeId> eventTypeMappings)
        {
            // find the event type.
            var eventTypeId = FindEventType(monitoredItem, notification);

            if (eventTypeId == null)
            {
                return(null);
            }

            // look up the known event type.
            NodeId knownTypeId;

            if (!eventTypeMappings.TryGetValue(eventTypeId, out knownTypeId))
            {
                // check for a known type
                if (KnownEventTypes.Any(t => t == eventTypeId))
                {
                    knownTypeId = eventTypeId;
                    eventTypeMappings.Add(eventTypeId, eventTypeId);
                }

                // browse for the supertypes of the event type.
                if (knownTypeId == null)
                {
                    var supertypes = BrowseSuperTypes(session, eventTypeId, false);

                    // can't do anything with unknown types.
                    if (supertypes == null)
                    {
                        return(null);
                    }

                    // find the first supertype that matches a known event type.
                    foreach (var t in supertypes)
                    {
                        foreach (var nodeId in KnownEventTypes)
                        {
                            if (nodeId == t.NodeId)
                            {
                                knownTypeId = nodeId;
                                eventTypeMappings.Add(eventTypeId, knownTypeId);
                                break;
                            }
                        }

                        if (knownTypeId != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (knownTypeId == null)
            {
                return(null);
            }

            // all of the known event types have a UInt32 as identifier.
            var id = knownTypeId.Identifier as uint?;

            if (id == null)
            {
                return(null);
            }

            // construct the event based on the known event type.
            BaseEventState e;

            switch (id.Value)
            {
            case ObjectTypes.ConditionType: { e = new ConditionState(null); break; }

            case ObjectTypes.DialogConditionType: { e = new DialogConditionState(null); break; }

            case ObjectTypes.AlarmConditionType: { e = new AlarmConditionState(null); break; }

            case ObjectTypes.ExclusiveLimitAlarmType: { e = new ExclusiveLimitAlarmState(null); break; }

            case ObjectTypes.NonExclusiveLimitAlarmType: { e = new NonExclusiveLimitAlarmState(null); break; }

            case ObjectTypes.AuditEventType: { e = new AuditEventState(null); break; }

            case ObjectTypes.AuditUpdateMethodEventType: { e = new AuditUpdateMethodEventState(null); break; }

            default:
            {
                e = new BaseEventState(null);
                break;
            }
            }

            // get the filter which defines the contents of the notification.
            var filter = monitoredItem.Status.Filter as EventFilter;

            // initialize the event with the values in the notification.
            if (filter != null)
            {
                e.Update(session.SystemContext, filter.SelectClauses, notification);
            }

            // save the orginal notification.
            e.Handle = notification;
            return(e);
        }
Пример #7
0
        private void MonitorMethodUpdateNotification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
        {
            try
            {
                if (!(e.NotificationValue is EventFieldList notification))
                {
                    return;
                }
                NodeId eventTypeId = null;
                if (!(monitoredItem.Status.Filter is EventFilter filter))
                {
                    return;
                }
                for (int index = 0; index < filter.SelectClauses.Count; index++)
                {
                    SimpleAttributeOperand simpleAttributeOperand = filter.SelectClauses[index];
                    if (simpleAttributeOperand.BrowsePath.Count != 1 ||
                        simpleAttributeOperand.BrowsePath[0] != BrowseNames.EventType)
                    {
                        continue;
                    }
                    eventTypeId = notification.EventFields[index].Value as NodeId;
                }

                // look up the known event type.
                Dictionary <NodeId, NodeId> eventTypeMappings = new Dictionary <NodeId, NodeId>();
                if (eventTypeId == null || NodeId.IsNull(eventTypeId))
                {
                    return;
                }
                if (!eventTypeMappings.TryGetValue(eventTypeId, out NodeId knownTypeId))
                {
                    // check for a known type
                    if (KnownEventTypes.Any(nodeId => nodeId == eventTypeId))
                    {
                        knownTypeId = eventTypeId;
                        eventTypeMappings.Add(eventTypeId, eventTypeId);
                    }

                    // browse for the supertypes of the event type.
                    if (knownTypeId == null)
                    {
                        ReferenceDescriptionCollection supertypes = new ReferenceDescriptionCollection();
                        // find all of the children of the field.
                        BrowseDescription nodeToBrowse = new BrowseDescription
                        {
                            NodeId          = eventTypeId,
                            BrowseDirection = BrowseDirection.Inverse,
                            ReferenceTypeId = ReferenceTypeIds.HasSubtype,
                            IncludeSubtypes = false, // more efficient to use IncludeSubtypes=False when possible.
                            NodeClassMask   = 0,     // the HasSubtype reference already restricts the targets to Types.
                            ResultMask      = (uint)BrowseResultMask.All
                        };

                        ReferenceDescriptionCollection
                            references = _applicationInstanceManager.Browse(nodeToBrowse);
                        while (references != null && references.Count > 0)
                        {
                            // should never be more than one supertype.
                            supertypes.Add(references[0]);
                            // only follow references within this server.
                            if (references[0].NodeId.IsAbsolute)
                            {
                                break;
                            }

                            // get the references for the next level up.
                            nodeToBrowse.NodeId = (NodeId)references[0].NodeId;
                            references          = _applicationInstanceManager.Browse(nodeToBrowse);
                        }

                        // find the first super type that matches a known event type.
                        foreach (ReferenceDescription referenceDescription in supertypes)
                        {
                            foreach (NodeId nodeId in KnownEventTypes)
                            {
                                if (nodeId != referenceDescription.NodeId)
                                {
                                    continue;
                                }
                                knownTypeId = nodeId;
                                eventTypeMappings.Add(eventTypeId, knownTypeId);
                                break;
                            }

                            if (knownTypeId != null)
                            {
                                break;
                            }
                        }
                    }
                }

                if (knownTypeId == null)
                {
                    return;
                }
                // all of the known event types have a UInt32 as identifier.
                uint?id = knownTypeId.Identifier as uint?;
                if (id == null)
                {
                    return;
                }
                // construct the event based on the known event type.
                BaseEventState baseEventState = null;

                switch (id.Value)
                {
                case ObjectTypes.ConditionType:
                {
                    baseEventState = new ConditionState(null);
                    break;
                }

                case ObjectTypes.DialogConditionType:
                {
                    baseEventState = new DialogConditionState(null);
                    break;
                }

                case ObjectTypes.AlarmConditionType:
                {
                    baseEventState = new AlarmConditionState(null);
                    break;
                }

                case ObjectTypes.ExclusiveLimitAlarmType:
                {
                    baseEventState = new ExclusiveLimitAlarmState(null);
                    break;
                }

                case ObjectTypes.NonExclusiveLimitAlarmType:
                {
                    baseEventState = new NonExclusiveLimitAlarmState(null);
                    break;
                }

                case ObjectTypes.AuditEventType:
                {
                    baseEventState = new AuditEventState(null);
                    break;
                }

                case ObjectTypes.AuditUpdateMethodEventType:
                {
                    baseEventState = new AuditUpdateMethodEventState(null);
                    break;
                }

                default:
                {
                    baseEventState = new BaseEventState(null);
                    break;
                }
                }

                // get the filter which defines the contents of the notification.
                filter = monitoredItem.Status.Filter as EventFilter;
                // initialize the event with the values in the notification.
                baseEventState.Update(_applicationInstanceManager.Session.SystemContext, filter.SelectClauses,
                                      notification);
                // save the original notification.
                baseEventState.Handle = notification;
                // construct the audit object.
                if (baseEventState is AuditUpdateMethodEventState audit)
                {
                    // look up the condition type metadata in the local cache.
                    string sourceName = "";
                    if (audit.SourceName.Value != null)
                    {
                        sourceName = Utils.Format("{0}", audit.SourceName.Value);
                    }
                    string type = "";
                    if (audit.TypeDefinitionId != null)
                    {
                        type = Utils.Format("{0}",
                                            _applicationInstanceManager.Session.NodeCache.Find(audit.TypeDefinitionId));
                    }

                    string method = "";
                    if (audit.MethodId != null)
                    {
                        method = Utils.Format("{0}",
                                              _applicationInstanceManager.Session.NodeCache.Find(
                                                  BaseVariableState.GetValue(audit.MethodId)));
                    }

                    string status = "";
                    if (audit.Status != null)
                    {
                        status = Utils.Format("{0}", audit.Status.Value);
                    }

                    string time = "";
                    if (audit.Time != null)
                    {
                        time = Utils.Format("{0:HH:mm:ss.fff}", audit.Time.Value.ToLocalTime());
                    }

                    string message = "";
                    if (audit.Message != null)
                    {
                        message = Utils.Format("{0}", audit.Message.Value);
                    }

                    string inputArguments = "";
                    if (audit.InputArguments != null)
                    {
                        inputArguments = Utils.Format("{0}", new Variant(audit.InputArguments.Value));
                    }


                    InformationDisplay(
                        $"sourceName: {sourceName}, type:{type}, method:{method}, status:{status}, time:{time}, message:{message}, inputArguments:{inputArguments}");
                }
            }
            catch (Exception ex)
            {
                InformationDisplay($"Monitored Item Notification exception: {ex.StackTrace}");
            }
        }