Browse Source

1.修改退rt报未处理异常
2.退出rt资源监控终止
3.修改plc重连

JET-YDB\JET-YANGDB 6 months ago
parent
commit
4582582fe3

+ 9 - 4
FrameworkLocal/Common/Log/LOG.cs

@@ -22,10 +22,15 @@ namespace Aitex.Core.RT.Log
 
 
         static string GetFormatStackFrameInfo(int traceLevel)
         static string GetFormatStackFrameInfo(int traceLevel)
         {
         {
-            StackFrame sf = new StackTrace(true).GetFrame(traceLevel+1);
-            string pathFile = sf.GetFileName();
-            string file = string.IsNullOrEmpty(pathFile) ? "" : pathFile.Substring(pathFile.LastIndexOf('\\') + 1);
-            return $"{file}\tLine {sf.GetFileLineNumber()}\t{sf.GetMethod().Name}()";
+            try
+            {
+                StackFrame sf = new StackTrace(true).GetFrame(traceLevel + 1);
+                string pathFile = sf.GetFileName();
+                string file = string.IsNullOrEmpty(pathFile) ? "" : pathFile.Substring(pathFile.LastIndexOf('\\') + 1);
+                return $"{file}\tLine {sf.GetFileLineNumber()}\t{sf.GetMethod().Name}()";
+            }
+            catch (Exception) { }
+            return string.Empty;
         }
         }
 
 
         public static void Warning(string message, int traceLevel = 2, [CallerFilePath] string file = "",
         public static void Warning(string message, int traceLevel = 2, [CallerFilePath] string file = "",

+ 12 - 2
FrameworkLocal/Common/PLC/FinsPlc.cs

@@ -456,7 +456,8 @@ namespace MECF.Framework.Common.PLC
                     LOG.Write(ex, String.Format("Communication failed with PLC {0}:{1}", _ip, _port));
                     LOG.Write(ex, String.Format("Communication failed with PLC {0}:{1}", _ip, _port));
                     EV.PostMessage("System", EventEnum.DefaultWarning, String.Format("Communication failed with PLC {0}:{1}", _ip, _port));
                     EV.PostMessage("System", EventEnum.DefaultWarning, String.Format("Communication failed with PLC {0}:{1}", _ip, _port));
                 }
                 }
-
+                _isOpened = false;
+                SetState(IoProviderStateEnum.Uninitialized);
                 return;
                 return;
             }
             }
 
 
@@ -474,7 +475,6 @@ namespace MECF.Framework.Common.PLC
                 if (_isOpened)
                 if (_isOpened)
                 {
                 {
                     _isOpened = false;
                     _isOpened = false;
-                    SetState(IoProviderStateEnum.Uninitialized);
                     msender.Close();
                     msender.Close();
                 }
                 }
 
 
@@ -515,6 +515,8 @@ namespace MECF.Framework.Common.PLC
                 LOG.Error($"PLC ({_ip}) Read DI exception{detail}.", ex);
                 LOG.Error($"PLC ({_ip}) Read DI exception{detail}.", ex);
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Read DI exception");
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Read DI exception");
                 Close();
                 Close();
+                if (State != IoProviderStateEnum.Closing)
+                    SetState(IoProviderStateEnum.Uninitialized);
             }
             }
             return null;
             return null;
         }
         }
@@ -544,6 +546,8 @@ namespace MECF.Framework.Common.PLC
                 LOG.Error($"PLC ({_ip}) Read DO exception{detail}.", ex);
                 LOG.Error($"PLC ({_ip}) Read DO exception{detail}.", ex);
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Read DO exception");
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Read DO exception");
                 Close();
                 Close();
+                if (State != IoProviderStateEnum.Closing)
+                    SetState(IoProviderStateEnum.Uninitialized);
             }
             }
             return null;
             return null;
         }
         }
@@ -574,6 +578,8 @@ namespace MECF.Framework.Common.PLC
                 LOG.Error($"PLC ({_ip}) Read AI exception{detail}.", ex);
                 LOG.Error($"PLC ({_ip}) Read AI exception{detail}.", ex);
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Read AI exception");
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Read AI exception");
                 Close();
                 Close();
+                if (State != IoProviderStateEnum.Closing)
+                    SetState(IoProviderStateEnum.Uninitialized);
             }
             }
             return null;
             return null;
         }
         }
@@ -603,6 +609,8 @@ namespace MECF.Framework.Common.PLC
                 LOG.Error($"PLC ({_ip}) Write DO exception{detail}.", ex);
                 LOG.Error($"PLC ({_ip}) Write DO exception{detail}.", ex);
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Write DO exception");
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Write DO exception");
                 Close();
                 Close();
+                if (State != IoProviderStateEnum.Closing)
+                    SetState(IoProviderStateEnum.Uninitialized);
                 return;
                 return;
             }
             }
         }
         }
@@ -633,6 +641,8 @@ namespace MECF.Framework.Common.PLC
                 LOG.Error($"PLC ({_ip}) Write AO exception{detail}.", ex);
                 LOG.Error($"PLC ({_ip}) Write AO exception{detail}.", ex);
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Write AO exception");
                 EV.PostMessage("System", EventEnum.DefaultWarning, "PLC Write AO exception");
                 Close();
                 Close();
+                if (State != IoProviderStateEnum.Closing)
+                    SetState(IoProviderStateEnum.Uninitialized);
                 return;
                 return;
             }
             }
         }
         }

+ 1 - 0
Mars/EfemDualRT/Instances/ToolLoader.cs

@@ -105,6 +105,7 @@ namespace EfemDualRT.Instances
 
 
         public void Terminate()
         public void Terminate()
         {
         {
+            Singleton<ResourceMonitor>.Instance.Terminate();
             Singleton<EfemDualEquipment>.Instance.Terminate();
             Singleton<EfemDualEquipment>.Instance.Terminate();
 
 
             DEVICE.Managers.ForEach(p=>p.Terminate());
             DEVICE.Managers.ForEach(p=>p.Terminate());

+ 4 - 0
Mars/EfemDualRT/Resources/ResourceMonitor.cs

@@ -13,6 +13,7 @@ using System.Net.NetworkInformation;
 using System.Reflection;
 using System.Reflection;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Channels;
 using System.Text;
 using System.Text;
+using System.Threading;
 using System.Timers;
 using System.Timers;
 using System.Windows;
 using System.Windows;
 
 
@@ -51,6 +52,7 @@ namespace EfemDualRT.Resources
         private PerformanceCounter _writeDisk;
         private PerformanceCounter _writeDisk;
         private PerformanceCounter _transferDisk;
         private PerformanceCounter _transferDisk;
         private PeriodicJob _thread;
         private PeriodicJob _thread;
+        private bool _isTerminate;
         public ResourceMonitor()
         public ResourceMonitor()
         {
         {
 
 
@@ -102,6 +104,7 @@ namespace EfemDualRT.Resources
         {
         {
             if (_thread != null)
             if (_thread != null)
             {
             {
+                _isTerminate = true;
                 _thread.Stop();
                 _thread.Stop();
                 _thread = null;
                 _thread = null;
             }
             }
@@ -129,6 +132,7 @@ namespace EfemDualRT.Resources
         {
         {
             try
             try
             {
             {
+                if (_isTerminate) return true;
                 string rtmonoitor = process_use(processRTname);
                 string rtmonoitor = process_use(processRTname);
                 string uimonoitor = process_use(processUIname);
                 string uimonoitor = process_use(processUIname);