From 9211ec11c112e18cd99e77f889a01110a70031ce Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 24 十一月 2025 17:47:15 +0800
Subject: [PATCH] 优化项目结构

---
 HMI.AlermInfoManage/AlarmInfoManage.xaml.cs |   59 +++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/HMI.AlermInfoManage/AlarmInfoManage.xaml.cs b/HMI.AlermInfoManage/AlarmInfoManage.xaml.cs
index 1cf4db1..4a3ae83 100644
--- a/HMI.AlermInfoManage/AlarmInfoManage.xaml.cs
+++ b/HMI.AlermInfoManage/AlarmInfoManage.xaml.cs
@@ -1,5 +1,4 @@
-锘縰sing ConnectionUtil;
-using HMI.AlarmInfoManage.Entity;
+锘縰sing HMI.AlarmInfoManage.Entity;
 using HMI.Base;
 using HMI.Core.Api;
 using HMI.Core.Setting;
@@ -7,9 +6,7 @@
 using HMI.UI.Util;
 using HMI.Util;
 using Microsoft.Win32;
-using OPCConnection;
-using Sharp7;
-using SimensDriver;
+using S7Driver;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
@@ -31,14 +28,11 @@
         private string markPath;
         private string alarmTextPath;
 
-        private string opcIP = "127.0.0.1";
-        private int opcPort = 6543;
-        private int localPort = 18888;
+        
         private volatile bool isClosing = false;
 
 
         private string dbPath;
-        private Simens plc = new Simens();
 
         private bool isHaveAlarm;
         private bool isNewAlarm;
@@ -71,7 +65,12 @@
         /// </summary>
         private MSMQHelper alarmRefershToMain = new MSMQHelper("LTHMI_Alarm_Rrfresh");
 
-        private SCADAApi lTSCADAApi = new OPCClient();
+        //private string opcIP = "127.0.0.1";
+        //private int opcPort = 6543;
+        //private int localPort = 18888;
+        //private SCADAApi lTSCADAApi = new OPCClient();
+
+        private PLCS7Driver pLCS7Driver;
 
         /// <summary>
         /// 鎶ヨ
@@ -187,6 +186,7 @@
         {
             DataContext = this;
             systemSetting = SystemSetting.Instance;
+            pLCS7Driver = new PLCS7Driver(systemSetting.PlcIp, systemSetting.PlcPort);
             InitializeComponent();
         }
 
@@ -222,13 +222,21 @@
                 Interval = 1000,
             };
             MonitorTimer.Elapsed += MonitorTimer_Elapsed;
-            if (!lTSCADAApi.Connect2(opcIP, opcPort, localPort, out string errMsg))
+            //if (!lTSCADAApi.Connect2(opcIP, opcPort, localPort, out string errMsg))
+            //{
+            //}
+            //else
+            //{
+            //    this.MonitorTimer.Start();
+            //}
+
+            if (pLCS7Driver.Connect(out string errMSg))
             {
-                //MsgBoxHelper.Error(this, errMsg);
+                this.MonitorTimer.Start();
             }
             else
             {
-                this.MonitorTimer.Start();
+                log.Error($"PLC Driver Connect Error. {errMSg}");
             }
 
             PcTimer = new Timer
@@ -641,15 +649,16 @@
             {
                 this.MonitorTimer.Enabled = false;
 
-                if (!lTSCADAApi.IsConnected(out string errMsg))
-                {
-                    log.Warn($"OPCServer Connection Error. {errMsg}");
-                    if (!lTSCADAApi.Connect2(opcIP, opcPort, localPort, out errMsg))
-                    {
-                        log.Warn($"OPCServer Try ReConnection Error. {errMsg}");
-                        return;
-                    }
-                }
+                /// 妫�鏌ヨ繛鎺�
+                //if (!lTSCADAApi.IsConnected(out string errMsg))
+                //{
+                //    log.Warn($"OPCServer Connection Error. {errMsg}");
+                //    if (!lTSCADAApi.Connect2(opcIP, opcPort, localPort, out errMsg))
+                //    {
+                //        log.Warn($"OPCServer Try ReConnection Error. {errMsg}");
+                //        return;
+                //    }
+                //}
 
                 isHaveAlarm = false;
                 List<AlarmText> cache = new List<AlarmText>();
@@ -681,9 +690,10 @@
 
                 foreach (var key in BlockMap.Keys)
                 {
-                    if (lTSCADAApi.DoFctReadSingle(key, out string alarmCode, out errMsg) && BlockMap[key].ContainsKey(alarmCode))
+                    if (pLCS7Driver.ReadShort(key, out short alarmVal, out string errMsg) && BlockMap[key].ContainsKey(alarmVal.ToString()))
                     {
                         //if(BlockReadCache.ContainsKey(key) && alarmCode)
+                        var alarmCode = alarmVal.ToString();
                         isHaveAlarm = true;
                         var text = BlockMap[key][alarmCode];
                         var newAlarm = new AlarmText
@@ -707,8 +717,9 @@
                 foreach (var item in markAlarmSetting)
                 {
                     var name = $"{item.DBAddress}.{item.StartAddress}";
-                    if (lTSCADAApi.DoFctReadSingle(name, out string alarmCode, out errMsg) && alarmCode != "0")
+                    if (pLCS7Driver.ReadShort(name, out short alarmVal, out string errMsg) && alarmVal != 0)
                     {
+                        var alarmCode = alarmVal.ToString();
                         isHaveAlarm = true;
                         var newAlarm = new AlarmText
                         {

--
Gitblit v1.9.1