From f08871fe7d148d667f2f11f80f64de71a0d9504c Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 15 六月 2026 18:19:37 +0800
Subject: [PATCH] 优化标准老化界面

---
 HMI.Util/Alarm/AlarmUtil.cs |   44 +++++++++++++++++++++-----------------------
 1 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/HMI.Util/Alarm/AlarmUtil.cs b/HMI.Util/Alarm/AlarmUtil.cs
index f846bd6..35ad725 100644
--- a/HMI.Util/Alarm/AlarmUtil.cs
+++ b/HMI.Util/Alarm/AlarmUtil.cs
@@ -2,6 +2,8 @@
 using HMI.Core.Entity;
 using HMI.Core.Setting;
 using HMI.Core.Util;
+using HMI.Simple.Util;
+using log4net;
 using S7Driver;
 using System;
 using System.Collections.Generic;
@@ -18,8 +20,11 @@
 
         public event EventHandler<LoadMsg> LoadMessageAppend;
 
+        internal static ILog log = LogManager.GetLogger("AlarmHelper");
+
         internal AlarmHelper()
         {
+
         }
 
         public ObservableCollection<AlarmSetting> BlockSettings { get; private set; }
@@ -178,7 +183,7 @@
             }
             catch (Exception ex)
             {
-                //log.Error("Read OPCServer Data Error.", ex);
+                log.Error("Read PLC Alarm Data Error.", ex);
             }
             finally
             {
@@ -188,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)
@@ -219,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)
                     {
@@ -247,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();
@@ -279,7 +275,7 @@
             }
             catch (Exception ex)
             {
-                //log.Error("PcTimer Execute Failed", ex);
+                log.Error("Read MSMQ Alarm Data Failed", ex);
             }
             finally
             {
@@ -293,7 +289,7 @@
             BlockReadCache.Clear();
             try
             {
-                BlockSettings = XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(blockFilePath);
+                BlockSettings = HMI.Core.Util.XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(blockFilePath);
             }
             catch (Exception ex)
             {
@@ -317,7 +313,7 @@
         {
             try
             {
-                MarkSettings = XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(markFilePath);
+                MarkSettings = HMI.Core.Util.XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(markFilePath);
             }
             catch (Exception ex)
             {
@@ -334,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();
         }
     }
@@ -357,10 +353,12 @@
 
         public static void Init()
         {
+            AlarmHelper.log.Info("AlarmUtil initing...");
             Instance = new AlarmHelper();
             Instance.LoadMessageAppend += Instance_LoadMessageAppend; ;
             Instance.InitInstance();
             Instance.OnAlarm += Instance_OnAlarm;
+            AlarmHelper.log.Info("AlarmUtil inited finished.");
         }
 
         private static void Instance_LoadMessageAppend(object sender, LoadMsg e)

--
Gitblit v1.9.1