From a0d2f70a2578ad8160bf4c9b983bf6b40c0f4f77 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周一, 26 8月 2024 13:32:22 +0800
Subject: [PATCH] 2

---
 DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DataCaptureHandler_01.cs |  145 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 142 insertions(+), 3 deletions(-)

diff --git a/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DataCaptureHandler_01.cs b/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DataCaptureHandler_01.cs
index 896cc15..1d09c90 100644
--- a/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DataCaptureHandler_01.cs
+++ b/DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DataCaptureHandler_01.cs
@@ -45,7 +45,7 @@
 
         public override void DataCaptureStart()
         {
-            if (SystemValue.isStartedModel)
+            if (SystemValue.isStartedImitateModel)
             {
                 var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig);
 
@@ -119,7 +119,7 @@
                     {
                         if (plcService == null || !plcService.IsConnected)
                         {
-                            threadStatusMonitor.ErrorMsg= $" {RandomHelper.GenerateRandomCode(4)} {_dataCaptureConfig.WorkingProcedure} PLC杩炴帴宸叉柇寮�锛屾鍦ㄥ皾璇曟墦寮�!";
+                            threadStatusMonitor.ErrorMsg = $" {RandomHelper.GenerateRandomCode(4)} {_dataCaptureConfig.WorkingProcedure} PLC杩炴帴宸叉柇寮�锛屾鍦ㄥ皾璇曟墦寮�!";
                             SystemValue.PLCServiceReconnect(plcService);
                             //plcService.Close();
                             //plcService.OpenService();
@@ -148,7 +148,7 @@
                                 wplog.CreatedTime = DateTimeHelper.GetDateTime();
                                 wplog.CreatedUserName = DataCapturePointCode;
                                 wplog.UpdatedTime = DateTimeHelper.GetDateTime();
-                                wplog.UpdatedUserName = Environment.MachineName+"鑷姩"+ Thread.CurrentThread.ManagedThreadId.ToString();
+                                wplog.UpdatedUserName = Environment.MachineName + "鑷姩" + Thread.CurrentThread.ManagedThreadId.ToString();
                                 wplog.OnlineTime = DateTimeHelper.GetDateTime();
                                 wplog.IsDeleted = false;
 
@@ -170,6 +170,15 @@
                                         Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $" {DataCapturePointCode}宸ュ簭鐩戞帶涓婄嚎瀹屾垚鏍囪 瀛楁{col.DataCaptureColumnTabelName}鍔ㄦ�佽祴鍊煎紓甯竰wplog.Id}", setex);
                                     }
                                 }
+
+                                //鐩戞帶娴嬭瘯鏁版嵁锛屾ā鎷燂紝娴嬭瘯
+                                MonitorHelper.MonitorTestForOP3501(_dataCaptureConfig, value, colConfig, wplog);
+
+                                //鐗规畩澶勭悊OP50 銆怑ditby shaocx,2024-08-16銆�
+                                string sideValue = GetSideForOP50(plcService, wplog);
+                                wplog.MonitoringPoint += sideValue;
+                                wplog.CreatedUserName = wplog.MonitoringPoint;
+
                                 //璇诲彇浜岀淮鐮佸悗鏇存柊鏁版嵁搴�
                                 WorkPieceInfoManager.ReadQRcode(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), plcService, _dataCaptureConfig.IsFeedback);
 
@@ -218,5 +227,135 @@
             }
         }
 
+
+        /// <summary>
+        /// 鑾峰彇OP50鐨勬煇涓伐浣嶇殑鍝釜闈�
+        /// </summary>
+        /// <param name="plcService"></param>
+        /// <returns></returns>
+        //private string GetSideForOP50(PLCService plcService, WorkPieceLog wplog)
+        //{
+        //    try
+        //    {
+        //        if (!(DataCapturePointCode.Contains("OP5001A") || DataCapturePointCode.Contains("OP5001B")))
+        //        {
+        //            return "";
+        //        }
+        //        string title = $"璇诲彇 {DataCapturePointCode}宸ュ簭鏃讹紝鑾峰彇OP50鐨勫摢涓潰,宸ヤ欢鍙�:{wplog.WorkPieceID}";
+
+        //        int i_value_M88 = _GetSideForOP50(plcService, wplog, "M87.0");
+        //        if (i_value_M88 == 1)
+        //        {
+        //            title += ",杩斿洖1";
+        //            Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), title);
+        //            return "1";
+        //        }
+
+        //        i_value_M88 = _GetSideForOP50(plcService, wplog, "M87.2");
+        //        if (i_value_M88 == 1)
+        //        {
+        //            title += ",杩斿洖2";
+        //            Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), title);
+        //            return "2";
+        //        }
+
+        //        i_value_M88 = _GetSideForOP50(plcService, wplog, "M87.4");
+        //        if (i_value_M88 == 1)
+        //        {
+        //            title += ",杩斿洖3";
+        //            Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), title);
+        //            return "3";
+        //        }
+
+        //        i_value_M88 = _GetSideForOP50(plcService, wplog, "M87.6");
+        //        if (i_value_M88 == 1)
+        //        {
+        //            title += ",杩斿洖4";
+        //            Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), title);
+        //            return "4";
+        //        }
+
+        //        Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"璇诲彇 {DataCapturePointCode}宸ュ簭鏃讹紝鏃犳晥鏁板��,鑾峰彇OP50鐨勫摢涓潰,i_value_M88:{i_value_M88}锛屽伐浠跺彿:{wplog.WorkPieceID}");
+        //        return "";
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"璇诲彇 {DataCapturePointCode}宸ュ簭鏃跺紓甯�,鑾峰彇OP50鐨勫摢涓潰,宸ヤ欢鍙�:{wplog.WorkPieceID}", ex);
+        //        return "";
+        //    }
+        //}
+        /// <summary>
+        /// 鑾峰彇OP50鐨勬煇涓伐浣嶇殑鍝釜闈�
+        /// </summary>
+        /// <param name="plcService"></param>
+        /// <returns></returns>
+        private string GetSideForOP50(PLCService plcService, WorkPieceLog wplog)
+        {
+            try
+            {
+                if (!(DataCapturePointCode.Contains("OP5001A") || DataCapturePointCode.Contains("OP5001B")))
+                {
+                    return "";
+                }
+
+                object value_M88 = plcService.ReadValuePointV2("M88", PLCManger.GetTypeForString("int"));
+                int i_value_M88 = 0;
+                var isRight = int.TryParse(value_M88.ToString(), out i_value_M88);
+                Log4NetHelper.WriteInfoLog(LogType.MonitorOP50Side, $"璇诲彇 {DataCapturePointCode}宸ュ簭鐩戞帶娴嬮噺鏍囪鏁版嵁,鑾峰彇OP50鐨勫摢涓潰,i_value_M88:{i_value_M88},宸ヤ欢鍙�:{wplog.WorkPieceID}");
+                if (isRight)
+                {
+                    if (i_value_M88 == 64)
+                    {
+                        return "1";
+                    }
+                    else if (i_value_M88 == 16384)
+                    {//鍘熷畾涓�16384涓烘鍦ㄦ棆杞紝鐩戞帶涓嬫潵锛屽彂鐜� 16384搴旇鏄伐浣�1鐨勯棶棰� 銆怑ditby shaocx,2024-06-12銆�
+                        return "1";
+                    }
+                    else if (i_value_M88 == 256)
+                    {
+                        return "2";
+                    }
+                    else if (i_value_M88 == 1024)
+                    {
+                        return "3";
+                    }
+                    else if (i_value_M88 == 4096)
+                    {
+                        return "4";
+                    }
+                }
+                Log4NetHelper.WriteErrorLog(LogType.MonitorOP50Side, $"璇诲彇 {DataCapturePointCode}宸ュ簭鐩戞帶娴嬮噺鏍囪鏁版嵁鏃讹紝鏃犳晥鏁板��,鑾峰彇OP50鐨勫摢涓潰,,i_value_M88:{i_value_M88}锛屽伐浠跺彿:{wplog.WorkPieceID}", null);
+                return "";
+            }
+            catch (Exception ex)
+            {
+                Log4NetHelper.WriteErrorLog(LogType.MonitorOP50Side, $"璇诲彇 {DataCapturePointCode}宸ュ簭鐩戞帶娴嬮噺鏍囪鏁版嵁鏃跺紓甯�,鑾峰彇OP50鐨勫摢涓潰,宸ヤ欢鍙�:{wplog.WorkPieceID}", ex);
+                return "";
+            }
+        }
+
+
+        private int _GetSideForOP50(PLCService plcService, WorkPieceLog wplog, string address)
+        {
+            try
+            {
+                object value_M88 = plcService.ReadValuePointV2(address, PLCManger.GetTypeForString("int"));
+                int i_value_M88 = 0;
+                var isRight = int.TryParse(value_M88.ToString(), out i_value_M88);
+                Log4NetHelper.WriteInfoLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"璇诲彇 {DataCapturePointCode},璇诲彇鍦板潃 {address}锛屽伐搴忕洃鎺ф暟鎹�,鑾峰彇OP50鐨勫摢涓潰,i_value_M88:{i_value_M88},宸ヤ欢鍙�:{wplog.WorkPieceID}");
+                if (isRight)
+                {
+                    return i_value_M88;
+                }
+                Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"璇诲彇 {DataCapturePointCode},璇诲彇鍦板潃 {address}锛屽伐搴忕洃鎺ф祴閲忔爣璁版暟鎹椂锛屾棤鏁堟暟鍊�,鑾峰彇OP50鐨勫摢涓潰,,i_value_M88:{i_value_M88}锛屽伐浠跺彿:{wplog.WorkPieceID}", null);
+                return 0;
+            }
+            catch (Exception ex)
+            {
+                Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"璇诲彇 {DataCapturePointCode},璇诲彇鍦板潃 {address}锛屽伐搴忕洃鎺ф祴閲忔爣璁版暟鎹椂寮傚父,鑾峰彇OP50鐨勫摢涓潰,宸ヤ欢鍙�:{wplog.WorkPieceID}", ex);
+                return 0;
+            }
+        }
     }
 }

--
Gitblit v1.9.3