From a7e645acf2617a0f73afe12f73b896b4f4c78ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Sat, 28 May 2022 10:23:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E6=A3=80=E6=B5=8B=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.Device/AlarmHelper.cs | 14 ++++++++++---- BPASmartClient.Device/BaseDevice.cs | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) 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}"); } } }