From 2bc7d729da06ebe31e94a727cb7e7b53a77add79 Mon Sep 17 00:00:00 2001
From: kingno <30263@KINGNO>
Date: 星期三, 27 八月 2025 13:06:48 +0800
Subject: [PATCH] 合并

---
 src/Bro.M141.Process/M141Process.cs |  137 ++++++++++++++++++++++++---------------------
 1 files changed, 72 insertions(+), 65 deletions(-)

diff --git a/src/Bro.M141.Process/M141Process.cs b/src/Bro.M141.Process/M141Process.cs
index 06fb55d..be2c952 100644
--- a/src/Bro.M141.Process/M141Process.cs
+++ b/src/Bro.M141.Process/M141Process.cs
@@ -22,6 +22,7 @@
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Drawing.Imaging;
 using System.IO;
 using System.Linq;
@@ -137,10 +138,10 @@
                 mqtt.Connect(M141Config.MESchannel);
             }
 
-            InitialContinuousNGAlarm();         
+            InitialContinuousNGAlarm();
         }
 
-        
+
         public override void Close()
         {
             devicestate = false;
@@ -219,24 +220,30 @@
                             }
                         }
                     }
-
-                    lock (StatisticRecordsFull)
+                    if (numsum > 20)
                     {
-                        if (numsum > 20)
-                        {
-                            numsum = 0;
-                            using (FileStream fileStream = new FileStream(_statisticFilePath, FileMode.OpenOrCreate, FileAccess.Write))
-                            {
-                                fileStream.Seek(0L, SeekOrigin.Begin);
-                                string s = JsonConvert.SerializeObject(StatisticRecordsFull);
-                                byte[] bytes = Encoding.UTF8.GetBytes(s);
-                                fileStream.Write(bytes, 0, bytes.Length);
-                                fileStream.SetLength(bytes.Length);
-                                fileStream.Flush();
-                                fileStream.Close();
-                            }
-                        }
+                        numsum = 0;
+                        StatisticRecordsFull.SaveSummaryRecord();
                     }
+                    //lock (StatisticRecordsFull)
+                    //{
+                    //    if (numsum > 20)
+                    //    {
+                    //        numsum = 0;
+
+
+                        //        using (FileStream fileStream = new FileStream(_statisticFilePath, FileMode.OpenOrCreate, FileAccess.Write))
+                        //        {
+                        //            fileStream.Seek(0L, SeekOrigin.Begin);
+                        //            string s = JsonConvert.SerializeObject(StatisticRecordsFull);
+                        //            byte[] bytes = Encoding.UTF8.GetBytes(s);
+                        //            fileStream.Write(bytes, 0, bytes.Length);
+                        //            fileStream.SetLength(bytes.Length);
+                        //            fileStream.Flush();
+                        //            fileStream.Close();
+                        //        }
+                        //    }
+                        //}
                 }
                 catch (Exception ex)
                 {
@@ -942,6 +949,7 @@
         #region plc
         public ResponseMessage RunImageCheck_plc(IOperationConfig config)
         {
+
             ResponseMessage msg = new ResponseMessage();
             msg.Result = 1;
             List<MeasureBind> measureBinds = new List<MeasureBind>();
@@ -1014,7 +1022,10 @@
             }
 
             CheckPositionDoneAsync_plc(measureBinds[0].WorkPosition, inputSequence, config, cameraIds);
+
+         
             return msg;
+
         }
 
 
@@ -1150,11 +1161,13 @@
 
         public async Task<List<ProductModel>> CheckPositionDoneAsync_plc(string positionName, string inputSequence, IOperationConfig config, List<string> cameraIds)
         {
+           
             string triggerSource = config.TriggerSource;
             return await _taskFactory.StartNew(() =>
             {
                 try
                 {
+                    
                     string index = config.TriggerStr.Split(',')[1];
                     var positionSet = M141Config.WorkPositionCollection.FirstOrDefault(u => u.PositionName == positionName);
 
@@ -1242,19 +1255,17 @@
 
                         mysqlhelper.UpdateProduct(p);
 
-                      
+
 
                         if (positionSet.IsLastPosition)
                         {
-   
-                            
                             //鐝缁熻鏃堕棿鍒掑垎
                             if (M141Config.WorkShiftList.Count == 0)
                             {
                                 //鐢熸垚涓�涓姤琛�
                                 string name = $"ProductRecord_{DateTime.Now.ToString("yyyyMMdd")}.csv";
                                 LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鍒涘缓{name}鏁版嵁鎶ヨ〃");
-                                UpdateProductResultAsync(p, name);    
+                                UpdateProductResultAsync(p, name);
                             }
                             else
                             {
@@ -1274,7 +1285,7 @@
                                     }
                                     else
                                     {
-                                        if (now.TimeOfDay >= item.ShiftTime_Start.TimeOfDay )
+                                        if (now.TimeOfDay >= item.ShiftTime_Start.TimeOfDay)
                                         {
                                             //鐢熸垚涓�涓姤琛�
                                             string name = $"ProductRecord_{DateTime.Now.ToString("yyyyMMdd")}_{item.ShiftName}.csv";
@@ -1291,16 +1302,12 @@
                                     }
                                 }
                             }
-
                             //UpdateProductResultAsync(p);
-
                             mysqlhelper.NewForAll(p, M141Config.StationCode, M141Config.defectname);
 
                             if (M141Config.IsfinDevice)
                             {
-
                                 SummaryAllprodata(p);
-
                             }
                         }
                     });
@@ -1460,7 +1467,7 @@
                                             newp.BasketCode = plist[0].BasketCode;
                                             newp.Result = "NG";
                                             newp.SN = plist[0].SN;
-                                            if(M141Config.IsfinDevice)
+                                            if (M141Config.IsfinDevice)
                                             {
                                                 SummaryAllprodata(newp);
                                                 LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鎻愬墠NG鍔犲叆姹囨�绘暟鎹姤琛ㄧ粺璁�");
@@ -1557,7 +1564,7 @@
 
         public void SummaryAllprodata(ProductModel p)
         {
-            
+
             _taskFactory.StartNew(() =>
             {
                 try
@@ -1572,7 +1579,7 @@
 
                     Thread.Sleep(500);
                     var plist = mysqlhelper.GetProductList(p.SEQUENCE);
-                    
+
                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"浜у搧{p.PID}妫�娴嬬粨鏋滀负{p.Result}浠庢暟鎹簱涓幏鍙栫殑鏁版嵁涓轰骇鍝亄plist[0].PID}妫�娴嬬粨鏋滀负{plist[0].Result}");
                     if (plist != null)
                     {
@@ -1594,7 +1601,7 @@
                     string data = "";
 
                     string Head = "鏃堕棿,PID,鏍忓叿鐮�,鐗╂枡鐮�,鏉$爜,姹囨�绘娴嬬粨鏋�,S2_P1妫�娴嬫槑缁�,S2_P2妫�娴嬫槑缁�,S2_P3妫�娴嬫槑缁�,S3_P1妫�娴嬫槑缁�,S3_P2妫�娴嬫槑缁�,S4_P1妫�娴嬫槑缁�,S4_P2妫�娴嬫槑缁�,S5_P1妫�娴嬫槑缁�,S5_P2妫�娴嬫槑缁�,S5_P3妫�娴嬫槑缁�,Barcode,SPC_A,SPC_BF_A1,SPC_BF_A2,SPC_BF_A3,SPC_BF_A4,SPC_BF_A5,SPC_BF_A6,SPC_BF_A7,SPC_BF_A8,SPC_BF_A9,SPC_BS_A1,SPC_BS_A2,SPC_BS_A3,SPC_BS_A4,SPC_BS_A5,SPC_BS_A6,SPC_BS_A7,SPC_BS_A8,SPC_BS_A9,SPC_BT_A100RES,SPC_BT_A101RES,SPC_BT_A102RES,SPC_BT_A103RES,SPC_BT_A104RES,SPC_BT_A105RES,SPC_BT_A106RES,SPC_BT_A107RES,SPC_BT_A108RES,SPC_BT_A109RES,SPC_BT_A10RES,SPC_BT_A110RES,SPC_BT_A111RES,SPC_BT_A112RES,SPC_BT_A113RES,SPC_BT_A11RES,SPC_BT_A12RES,SPC_BT_A13RES,SPC_BT_A14RES,SPC_BT_A15RES,SPC_BT_A16RES,SPC_BT_A17RES,SPC_BT_A18RES,SPC_BT_A19RES,SPC_BT_A1RES,SPC_BT_A20RES,SPC_BT_A21RES,SPC_BT_A22RES,SPC_BT_A23RES,SPC_BT_A24RES,SPC_BT_A25RES,SPC_BT_A26RES,SPC_BT_A27RES,SPC_BT_A28RES,SPC_BT_A29RES,SPC_BT_A2RES,SPC_BT_A30RES,SPC_BT_A31RES,SPC_BT_A32RES,SPC_BT_A33RES,SPC_BT_A34RES,SPC_BT_A35RES,SPC_BT_A36RES,SPC_BT_A37RES,SPC_BT_A38RES,SPC_BT_A39RES,SPC_BT_A3RES,SPC_BT_A40RES,SPC_BT_A41RES,SPC_BT_A42RES,SPC_BT_A43RES,SPC_BT_A44RES,SPC_BT_A45RES,SPC_BT_A46RES,SPC_BT_A47RES,SPC_BT_A48RES,SPC_BT_A49RES,SPC_BT_A4RES,SPC_BT_A50RES,SPC_BT_A51RES,SPC_BT_A52RES,SPC_BT_A53RES,SPC_BT_A54RES,SPC_BT_A55RES,SPC_BT_A56RES,SPC_BT_A57RES,SPC_BT_A58RES,SPC_BT_A59RES,SPC_BT_A5RES,SPC_BT_A60RES,SPC_BT_A61RES,SPC_BT_A62RES,SPC_BT_A63RES,SPC_BT_A64RES,SPC_BT_A65RES,SPC_BT_A66RES,SPC_BT_A67RES,SPC_BT_A68RES,SPC_BT_A69RES,SPC_BT_A6RES,SPC_BT_A70RES,SPC_BT_A71RES,SPC_BT_A72RES,SPC_BT_A73RES,SPC_BT_A74RES,SPC_BT_A75RES,SPC_BT_A76RES,SPC_BT_A77RES,SPC_BT_A78RES,SPC_BT_A79RES,SPC_BT_A7RES,SPC_BT_A80RES,SPC_BT_A81RES,SPC_BT_A82RES,SPC_BT_A83RES,SPC_BT_A84RES,SPC_BT_A85RES,SPC_BT_A86RES,SPC_BT_A87RES,SPC_BT_A88RES,SPC_BT_A89RES,SPC_BT_A8RES,SPC_BT_A90RES,SPC_BT_A91RES,SPC_BT_A92RES,SPC_BT_A93RES,SPC_BT_A94RES,SPC_BT_A95RES,SPC_BT_A96RES,SPC_BT_A97RES,SPC_BT_A98RES,SPC_BT_A99RES,SPC_BT_A9RES,SPC_C";
-                    
+
                     for (int i = 0; i < Head.Split(",").ToList().Count(); i++)
                     {
                         int index = csvHeadforall.Split(",").ToList().IndexOf(Head.Split(",").ToList()[i]);
@@ -1665,35 +1672,35 @@
                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"杩炵画NG鏁版嵁璁板綍");
                     DefectNGRecordList.ForEach(d =>
                     {
-                            string alarmMsg = "";
-                            int alarmTypeTemp = 0;
-                            
-                            if (product.Result == "OK")
+                        string alarmMsg = "";
+                        int alarmTypeTemp = 0;
+
+                        if (product.Result == "OK")
+                        {
+                            if (d.CheckIsAlarmRaised(product.Result == "OK", out alarmMsg, out alarmTypeTemp))
                             {
-                                if (d.CheckIsAlarmRaised(product.Result == "OK", out alarmMsg, out alarmTypeTemp))
+                                allMsg += $"{alarmMsg}\r\n";
+
+                                isAlarmRaised = true;
+                                ngItem = "浜у搧缁撴灉";
+                                alarmType = alarmTypeTemp;
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{product.PID}鏁版嵁缁撴灉涓簕product.Result}鍙備笌杩炵画NG缁熻");
+                            }
+                        }
+                        else
+                        {
+                            if (product.Result.Contains(d.DefectName))
+                            {
+                                if (d.CheckIsAlarmRaised(!product.Result.Contains(d.DefectName), out alarmMsg, out alarmTypeTemp))
                                 {
                                     allMsg += $"{alarmMsg}\r\n";
-
                                     isAlarmRaised = true;
                                     ngItem = "浜у搧缁撴灉";
                                     alarmType = alarmTypeTemp;
                                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{product.PID}鏁版嵁缁撴灉涓簕product.Result}鍙備笌杩炵画NG缁熻");
                                 }
                             }
-                            else
-                            {
-                                if (product.Result.Contains(d.DefectName))
-                                {
-                                    if (d.CheckIsAlarmRaised(!product.Result.Contains(d.DefectName), out alarmMsg, out alarmTypeTemp))
-                                    {
-                                        allMsg += $"{alarmMsg}\r\n";
-                                        isAlarmRaised = true;
-                                        ngItem = "浜у搧缁撴灉";
-                                        alarmType = alarmTypeTemp;
-                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{product.PID}鏁版嵁缁撴灉涓簕product.Result}鍙備笌杩炵画NG缁熻");
-                                    }
-                                }                               
-                            }
+                        }
                     });
                 }
                 catch (Exception ex)
@@ -1701,7 +1708,7 @@
                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Warning, $"杩炵画NG鏁版嵁璁板綍澶辫触");
                 }
                 if (isAlarmRaised)
-                {                     
+                {
                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Warning, $"杩炵画NG鐩戞帶鎶ヨ锛寋allMsg}");
                     if (M141Config.IsOperatorReset)
                     {
@@ -1718,7 +1725,7 @@
                     {
                         Task.Delay(50).Wait();
                         ResetContinuousNGAlarm();
-                    }                 
+                    }
                 }
             });
         }
@@ -1741,14 +1748,14 @@
                                 _continuousNGAlarmFrm = new FrmContinuousNGAlarm();
 
                                 _continuousNGAlarmFrm.TopMost = true;
-                                
+
                                 _continuousNGAlarmFrm.FormClosed += _continuousNGAlarmFrm_FormClosed;
-                               
+
                                 Task.Run(() =>
                                 {
                                     _continuousNGAlarmFrm.ShowDialog();
-                                    
-                                });                               
+
+                                });
                             }
                         }
                     }
@@ -1761,7 +1768,7 @@
                     {
                         _continuousNGAlarmFrm.Close();
                     }
-                
+
                 }
             });
 
@@ -1770,7 +1777,7 @@
         private void _continuousNGAlarmFrm_FormClosed(object? sender, FormClosedEventArgs e)
         {
             ResetContinuousNGAlarm();
-            LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"杩炵画NG鎶ヨ宸插浣�");           
+            LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"杩炵画NG鎶ヨ宸插浣�");
             _continuousNGAlarmFrm = null;
         }
 
@@ -1785,7 +1792,7 @@
                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"杩炵画NG鐩戞帶閫氱煡PLC閲嶇疆鎶ヨ澶辫触锛寋error}");
                 }
             }
-           
+
         }
 
         [ProcessMethod("", "ContinuousNGAlarmTest", "杩炵画NG鎶ヨ娴嬭瘯", InvokeType.TestInvoke)]
@@ -1848,10 +1855,10 @@
                         NGRecords.Add(DateTime.Now);
                     }
                 }
-                
+
                 if (NGRecords.Count >= AlarmSetting.TimePeriodNumThresold && NGRecords.Count > 0)
                 {
-                    
+
                     NGRecords = NGRecords.Skip(NGRecords.Count - AlarmSetting.TimePeriodNumThresold).OrderBy(u => u).ToList();
 
                     int timeInMinute = (int)Math.Ceiling((NGRecords[NGRecords.Count - 1] - NGRecords[0]).TotalMinutes);
@@ -1882,9 +1889,9 @@
             string msg = "";
             lock (_lockObj)
             {
-                IsAlarmRaised = false;                            
+                IsAlarmRaised = false;
                 if (_isContinuousAlarm)
-                {                
+                {
                     _isContinuousAlarm = false;
                     ContinuousNGNum = 0;
                     msg += "杩炵画NG鎶ヨ ";
@@ -1892,7 +1899,7 @@
 
                 if (_timeAlarm)
                 {
-                    
+
                     _timeAlarm = false;
                     NGRecords.Clear();
                     msg += "鏃舵鍐匩G鎶ヨ ";

--
Gitblit v1.8.0