diff --git a/BPASmartClient.Device/AlarmHelper.cs b/BPASmartClient.Device/AlarmHelper.cs index 4e18d268..dcdfb10d 100644 --- a/BPASmartClient.Device/AlarmHelper.cs +++ b/BPASmartClient.Device/AlarmHelper.cs @@ -15,6 +15,7 @@ namespace BPASmartClient.Device public List Alarms { get; set; } = new List(); public List HistoryAlarms { get; set; } = new List(); ConcurrentDictionary flagbit = new ConcurrentDictionary(); + ConcurrentDictionary delays = new ConcurrentDictionary(); public Action AddAction { get; set; } public Action RemoveAction { get; set; } public Action ChangeAction { get; set; } @@ -25,20 +26,25 @@ namespace BPASmartClient.Device /// 触发变量 /// 报警信息 /// 触发类型,上升沿 或 下降沿 - public void EdgeAlarm(bool Trigger, string text, AlarmLevel alarmLevel = AlarmLevel.一般报警, AlarmTriggerType edgeType = AlarmTriggerType.Rising) + public void EdgeAlarm(bool Trigger, string text, int delay = 2, AlarmLevel alarmLevel = AlarmLevel.一般报警, AlarmTriggerType edgeType = AlarmTriggerType.Rising) { if (!flagbit.ContainsKey(text)) flagbit.TryAdd(text, false); - if (edgeType == AlarmTriggerType.Rising ? Trigger : !Trigger) + if (!delays.ContainsKey(text)) delays.TryAdd(text, Delay.GetInstance(text)); + //if (edgeType == AlarmTriggerType.Rising ? Trigger : !Trigger) + if (edgeType == AlarmTriggerType.Rising ? delays[text].Start(Trigger, delay) : delays[text].Start(!Trigger, delay)) { if (edgeType == AlarmTriggerType.Rising ? !flagbit[text] : flagbit[text]) { - AddAlarm(Trigger, text, alarmLevel); + //AddAlarm(Trigger, text, alarmLevel); + AddAlarm(Trigger, text.Substring(0, text.LastIndexOf("-")), alarmLevel); + flagbit[text] = edgeType == AlarmTriggerType.Rising ? true : false; } } else { - RemoveAlarm(text); + //RemoveAlarm(text); + RemoveAlarm(text.Substring(0, text.LastIndexOf("-"))); } if (edgeType == AlarmTriggerType.Rising ? flagbit[text] : !flagbit[text]) flagbit[text] = Trigger; } diff --git a/BPASmartClient.Device/BaseDevice.cs b/BPASmartClient.Device/BaseDevice.cs index 8055356d..cb873488 100644 --- a/BPASmartClient.Device/BaseDevice.cs +++ b/BPASmartClient.Device/BaseDevice.cs @@ -279,7 +279,7 @@ namespace BPASmartClient.Device if (item.CustomAttributes.Count() > 0 && item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0) { var info = item.GetCustomAttribute().AlarmInfo; - if (info != null) alarmHelper.EdgeAlarm(blen, info.ToString()); + if (info != null) alarmHelper.EdgeAlarm(blen, $"{info.ToString()}-{DeviceId}"); } } }