From 771a0e7b6b1276087515bbe94de28358cb92963b Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 04 六月 2026 10:32:27 +0800
Subject: [PATCH] 优化老化;
---
HMI.Util/Alarm/AlarmUtil.cs | 34 +++++++++++++---------------------
1 files changed, 13 insertions(+), 21 deletions(-)
diff --git a/HMI.Util/Alarm/AlarmUtil.cs b/HMI.Util/Alarm/AlarmUtil.cs
index 1044e1e..ea9988f 100644
--- a/HMI.Util/Alarm/AlarmUtil.cs
+++ b/HMI.Util/Alarm/AlarmUtil.cs
@@ -2,6 +2,7 @@
using HMI.Core.Entity;
using HMI.Core.Setting;
using HMI.Core.Util;
+using HMI.Simple.Util;
using log4net;
using S7Driver;
using System;
@@ -192,7 +193,7 @@
private void RefershAlarm()
{
- alarmRefershToMain.Send("AlarmRefersh", string.Empty);
+ alarmRefershToMain.Send("AlarmRefersh", string.Empty, string.Empty, 0);
List<AlarmText> alarms = new List<AlarmText>();
foreach (AlarmText alarm in currentPLCAlarmCache)
@@ -223,8 +224,8 @@
try
{
mqTimer.Enabled = false;
- alarmQueue.Receive(100, out string MessageID, out string MsgStr);
- if (MessageID != string.Empty)
+ alarmQueue.Receive(100, out string MessageID, out MQAlarm alarm);
+ if (MessageID != string.Empty && alarm != null)
{
switch (MessageID)
{
@@ -251,28 +252,19 @@
//}
break;
default:
- string[] arr = MsgStr.Split(',');
- string source = "PC";
- string info = string.Empty;
- if (arr.Length > 1)
- {
- source = arr[0];
- info = arr[1];
- }
- else
- {
- info = MsgStr;
- }
+ string source = string.IsNullOrEmpty(alarm.Source) ? "PC" : alarm.Source;
+ string info = alarm.Content;
+
AlarmText newAlarm = new AlarmText
{
Source = source,
VirtualId = $"{source}:{info}",
AlarmInfo = info,
- Level = 3,
+ Level = alarm.Level,
Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
};
if (currentMQAlarmCache
- .Find(alarm => alarm.Source == newAlarm.Source && alarm.AlarmInfo == newAlarm.AlarmInfo) == null)
+ .Find(a => a.Source == newAlarm.Source && a.AlarmInfo == newAlarm.AlarmInfo) == null)
{
currentMQAlarmCache.Add(newAlarm);
RefershAlarm();
@@ -297,7 +289,7 @@
BlockReadCache.Clear();
try
{
- BlockSettings = XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(blockFilePath);
+ BlockSettings = HMI.Core.Util.XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(blockFilePath);
}
catch (Exception ex)
{
@@ -321,7 +313,7 @@
{
try
{
- MarkSettings = XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(markFilePath);
+ MarkSettings = HMI.Core.Util.XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(markFilePath);
}
catch (Exception ex)
{
@@ -338,13 +330,13 @@
public void UpdateBlockSettings(IEnumerable<AlarmSetting> settings)
{
- XmlHelper.SerializeToXml(blockFilePath, settings);
+ HMI.Core.Util.XmlHelper.SerializeToXml(blockFilePath, settings);
RefreshBlockSettings();
}
public void UpdateMarkSettings(IEnumerable<AlarmSetting> settings)
{
- XmlHelper.SerializeToXml(markFilePath, settings);
+ HMI.Core.Util.XmlHelper.SerializeToXml(markFilePath, settings);
RefreshMarkSettings();
}
}
--
Gitblit v1.9.1