From c9f926d24416de35c19558d2c0a67216693f3510 Mon Sep 17 00:00:00 2001
From: quanzhou <quan.zhou@broconcentric.com>
Date: 星期一, 23 三月 2026 13:46:09 +0800
Subject: [PATCH] 修改篮具上传超时时间,修改产品条码上传逻辑由一次性上传50片产品变成两片单独上传

---
 src/Bro.M141.Process/M141Process.cs |  570 ++++++++++++++++++++++++++++++--------------------------
 1 files changed, 306 insertions(+), 264 deletions(-)

diff --git a/src/Bro.M141.Process/M141Process.cs b/src/Bro.M141.Process/M141Process.cs
index cb5927d..f04b529 100644
--- a/src/Bro.M141.Process/M141Process.cs
+++ b/src/Bro.M141.Process/M141Process.cs
@@ -13,6 +13,7 @@
 using MySql.Data.MySqlClient;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
+using NPOI.SS.Formula.Function;
 using NPOI.SS.Formula.Functions;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Ocsp;
@@ -102,6 +103,7 @@
         public PLCBase Plc1;
         bool devicestate = false;
         PLCBase Plc2;
+        public PLCBase Plc3;
         public Thread ThHeartPlc;
 
         public RabbitMQHelper mqtt;
@@ -144,8 +146,12 @@
                 mqtt = new RabbitMQHelper(M141Config.zIP, M141Config.zport, M141Config.zuser, M141Config.zpassword);
                 mqtt.Connect(M141Config.MESchannel);
             }
+            else
+            {
+                LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"宸插叧闂笂浼爉es");
+            }
 
-            InitialContinuousNGAlarm();
+                InitialContinuousNGAlarm();
         }
 
 
@@ -196,6 +202,9 @@
 
 
             Dictionary<string, List<int>> StateDIC = new Dictionary<string, List<int>>();
+            List<string> AlarmTypeList = new List<string>();
+           
+
             int numplc = 0;
             while (true)
             {
@@ -292,16 +301,13 @@
                                 }
 
                                 var alrams = item1.AlarmDetails;
+
                                 var plcdev = DeviceCollection.FirstOrDefault(u => u.Id == item1.plcname) as PLCBase;
-
-                                if (!StateDIC.ContainsKey(plcdev.Name))
-                                {
-                                    StateDIC[plcdev.Name] = new List<int>();
-                                }
-
+  
                                 foreach (var item in alrams.GroupBy(u => u.address))
                                 {
                                     int add = item.Key;
+
                                     var readres = plcdev.Read(add, 1, out _)[0];
 
                                     var Allbin = Convert.ToString(readres, 2).PadLeft(16, '0').Select(c => c - '0').ToArray();
@@ -311,43 +317,98 @@
                                     foreach (var item2 in item)
                                     {
                                         item2.value = Allbin[item2.address2];
+
+                                        if (!AlarmTypeList.Contains(item2.alarmtype))
+                                        {
+
+                                            AlarmTypeList.Add(item2.alarmtype);
+
+                                       
+                                        }
                                     }
                                 }
+
+                                string StateDICKey = "";
+
+                                foreach (var item in AlarmTypeList)
+                                {
+
+                                    StateDICKey = plcdev.Name +"_"+ item;
+
+                                    if (!StateDIC.ContainsKey(StateDICKey))
+                                    {
+
+                                        StateDIC[StateDICKey] = new List<int>();
+                                       
+
+                                    }
+
+                                }
+                           
                                 List<int> list = new List<int>();
+
+                                Dictionary<string, AlarmTypeData> AlarmType = new Dictionary<string, AlarmTypeData>();
+
                                 foreach (var item in alrams)
                                 {
-                                    csvhead += $",{item.alarmname}";
-                                    csvdata += $",{(item.value == 1 ? "1" : "")}";
-                                    list.Add(item.value);
-                                }
+                                    string key = item.alarmtype;
 
-                                if (!StateDIC[plcdev.Name].SequenceEqual(list))
+                                    if (!AlarmType.TryGetValue(key, out var alarmData))
+                                    {
+                                        // 涓嶅瓨鍦紝鍒涘缓鏂扮殑
+                                        alarmData = new AlarmTypeData()
+                                        {
+                                            CSVhead = csvhead,
+                                            CSVdata = csvdata,
+                                        };
+                                        AlarmType.Add(item.alarmtype, alarmData);
+
+                                    }
+
+                                    alarmData.CSVhead += $",{item.alarmname}";
+                                    alarmData.CSVdata += $",{(item.value == 1 ? "1" : "")}";
+                                    alarmData.AlarmTypeValue.Add(item.value);
+
+                                }
+                                foreach(var item in AlarmType.Keys)
                                 {
-                                    StateDIC[plcdev.Name].Clear();
-                                    StateDIC[plcdev.Name].AddRange(list);
 
-                                    CSVRecordAsync($"PLCstate_{plcdev.Name}.csv", csvdata, csvhead);
+                                    list = AlarmType[item].AlarmTypeValue;
 
-                                    var showdata = alrams.Where(u => u.value == 1).Select(u => u.alarmname).ToList();
+                                    string key = plcdev.Name+"_"+item;
 
-                                    if (showdata == null)
+                                    if (!StateDIC[key].SequenceEqual(list))
                                     {
-                                        showdata = new List<string>();
+                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{plcdev.Name}鎶ヨ绫诲瀷锛歿item}鐨勪俊鍙峰彂鐢熷彉鍖�,淇濆瓨鐨勬暟鎹负{AlarmType[item].CSVdata}");
+
+                                        StateDIC[key].Clear();
+
+                                        StateDIC[key].AddRange(list);
+
+                                        CSVRecordAsync($"PLCstate_{DateTime.Now.ToString("yyyyMMdd")}_{key}.csv", AlarmType[item].CSVdata, AlarmType[item].CSVhead);
+
+                                        var showdata = alrams.Where(u => u.value == 1).Select(u => u.alarmname).ToList();
+
+                                        if (showdata == null)
+                                        {
+                                            showdata = new List<string>();
+                                        }
+
+                                        if (showdata.Count > 0)
+                                        {
+                                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"{plcdev.Name}鎶ヨ 涓暟:{showdata.Count}  {string.Join(',', showdata)}");
+                                        }
+                                        else
+                                        {
+                                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{plcdev.Name}鎶ヨ 涓暟:0");
+                                        }
                                     }
 
-                                    if (showdata.Count > 0)
-                                    {
-                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"{plcdev.Name}鎶ヨ 涓暟:{showdata.Count}  {string.Join(',', showdata)}");
-                                    }
-                                    else
-                                    {
-                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{plcdev.Name}鎶ヨ 涓暟:0");
-                                    }
-                                }
+                                }                                
                             }
-                            catch
+                            catch(Exception EXC)
                             {
-
+                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"PLC鎶ヨ瀛樺偍璁板綍鍙戠敓寮傚父 {EXC.ToString()}");
                             }
                         }
                     }
@@ -357,8 +418,6 @@
                 {
 
                 }
-
-
 
                 try
                 {
@@ -381,6 +440,16 @@
 
                 Thread.Sleep(1000);
             }
+        }
+
+        public class AlarmTypeData
+        {
+            public List <int> AlarmTypeValue = new List<int>();
+
+            public string CSVhead;
+
+            public string CSVdata;
+
         }
 
         /// <summary>
@@ -479,9 +548,7 @@
         Dictionary<string, List<int>> _positionCheckTimeDict = new Dictionary<string, List<int>>();
         Dictionary<string, List<string>> _positionSpecHeads = new Dictionary<string, List<string>>();
 
-
         volatile int uploadId = 0;
-
 
         public void NewProductIntoList(ProductModel p, bool isSaveDB)
         {
@@ -571,6 +638,10 @@
 
                         if (measureBind.WorkPosition == "P1" && M141Config.StationCode == "S5" && detectResults.GetDefectDescList().Count == 0)
                         {
+                            var defecttem1 = detectResults.SelectMany(u => u.AllNetResults).SelectMany(m => m.DetectDetails).Select(detail => detail.ClassName).ToList();
+
+                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Detail, $"{products[0].SN}  S3S5妫�娴� 缂洪櫡鍚嶇О闆嗗悎涓簕string.Join(",", defecttem1)}");
+
                             var defecttem = detectResults.SelectMany(u => u.AllNetResults.SelectMany(m => m.DetectDetails)).Where(u => u.ClassName == M141Config.defectname).ToList();
 
                             List<Netdefectdetail> Netdefectdetails = mysqlhelper.GetNetdefectdetails(products[0].SEQUENCE);
@@ -822,7 +893,6 @@
             });
         }
 
-
         public async Task RunImageCheckAsync(List<ProductModel> products, string triggerText, string triggerSource, MeasureBind measureBind)
         {
             await Task.Run(() =>
@@ -888,19 +958,14 @@
                                 LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"浜у搧{p.PID}_{p.SEQUENCE}宸ヤ綅{measureBind.WorkPosition}鐨勭{measureBind.CheckIndex}妫�娴嬪畬鎴愶紝{msg}");
                             }
                         });
-
-
-
                     }
                     catch (Exception ex)
                     {
                         LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{measureBind.WorkPosition}锛屼骇鍝亄string.Join(",", products.Select(u => u.PID))}鐨凬G鍥剧墖淇濆瓨寮傚父锛寋ex.GetExceptionMessage()}");
                     }
-
                 }
             });
         }
-
 
         private void RunCustomizedMethod(List<ProductModel> products, string triggerText, string triggerSource, IImageSet imgSet, string methodId, List<DetectResult> resultList)
         {
@@ -948,10 +1013,6 @@
                 LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"鑷畾涔夋娴嬭繃绋嬪紓甯革紝{ex.GetExceptionMessage()}");
             }
         }
-
-
-
-
 
         #region plc
         public ResponseMessage RunImageCheck_plc(IOperationConfig config)
@@ -1030,7 +1091,6 @@
 
             CheckPositionDoneAsync_plc(measureBinds[0].WorkPosition, inputSequence, config, cameraIds);
 
-
             return msg;
 
         }
@@ -1081,8 +1141,6 @@
                     LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"鐩告満{camera.Name}妫�娴嬪墠娓呯悊缂撳瓨瀹屾垚");
                 }
             });
-
-
 
             inputSequence = triggerDatas[triggerDatas.Length - 1];
 
@@ -1174,7 +1232,6 @@
             {
                 try
                 {
-
                     string index = config.TriggerStr.Split(',')[1];
                     var positionSet = M141Config.WorkPositionCollection.FirstOrDefault(u => u.PositionName == positionName);
 
@@ -1339,216 +1396,212 @@
                         }
                         _ct = DateTime.Now;
 
-                        if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
-                        {
-                            if (M141Config.numpro >= 50)
-                            {
-                                M141Config.numpro = 0;
-                            }
+                        //if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
+                        //{
+                        //    if (M141Config.numpro >= 50)
+                        //    {
+                        //        M141Config.numpro = 0;
+                        //    }
 
-                            string Msgreceice = null;
+                        //    string Msgreceice = null;
 
-                            if (pList[0].Result == "OK")
-                            {
-                                M141Config.numpro++;
-                                Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(pList[0], M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
-                            }
-                            else
-                            {
-                                if (M141Config.ISupNG)
-                                {
-                                    Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(pList[0], M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
-                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鍚姩NG涓婁紶");
+                        //    if (pList[0].Result == "OK")
+                        //    {
+                        //        //M141Config.numpro++;
+                        //        //Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(pList[0], M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
+                        //        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}姹囨�籓K鏆傛椂涓嶄笂浼�");
+                        //    }
+                        //    else
+                        //    {
+                        //        if (M141Config.ISupNG)
+                        //        {
+                        //            Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(pList[0], M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
+                        //            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鍚姩NG涓婁紶");
 
-                                }
-                                else
-                                {
-                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鍏抽棴NG涓婁紶");
-                                }
-                            }
-                            M141Config.mesnum2++;
-                            if (Msgreceice == null && !M141Config.ISupNG)
-                            {
-                                if (!M141Config.ISupNG)
-                                {
-                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鏁版嵁NG锛屽紑鍚叧闂璑G涓婁紶MES");
-                                }
-                                else
-                                {
-                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES寮傚父 杩斿洖鏁版嵁涓簄ull");
-                                }
-                            }
-                            else
-                            {
-                                try
-                                {
-                                    var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
+                        //        }
+                        //        else
+                        //        {
+                        //            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鍏抽棴NG涓婁紶");
+                        //        }
+                        //    }
+                        //    M141Config.mesnum2++;
+                        //    if (Msgreceice == null && !M141Config.ISupNG)
+                        //    {
+                        //        if (!M141Config.ISupNG)
+                        //        {
+                        //            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鏁版嵁NG锛屽紑鍚叧闂璑G涓婁紶MES");
+                        //        }
+                        //        else
+                        //        {
+                        //            LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES寮傚父 杩斿洖鏁版嵁涓簄ull");
+                        //        }
+                        //    }
+                        //    else
+                        //    {
+                        //        try
+                        //        {
+                        //            var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
 
-                                    if (obj.zstatus == "200")
-                                    {
-                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES鎴愬姛  {Msgreceice}");
+                        //            if (obj.zstatus == "200")
+                        //            {
+                        //                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES鎴愬姛  {Msgreceice}");
 
-                                        if (M141Config.Isprint && !string.IsNullOrEmpty(obj.tary_label))
-                                        {
-                                            StartPrint(obj.tary_label);
-                                        }
+                        //                if (M141Config.Isprint && !string.IsNullOrEmpty(obj.tary_label))
+                        //                {
+                        //                    StartPrint(obj.tary_label, "Honeywell PX240S(300 dpi)");
+                        //                }
+                        //            }
+                        //            else
+                        //            {
+                        //                LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES澶辫触  {Msgreceice}");
+                        //            }
+                        //        }
+                        //        catch
+                        //        {
+                        //            LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES寮傚父  {Msgreceice}");
+                        //        }
+                        //    }
 
+                        //    int numplca = Convert.ToInt32(pList[0].SEQUENCE.Split('_')[0]);
+                        //    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"plc缁欏嚭鐨勪骇鍝佸簭鍙蜂负{numplca}");
 
+                        //    lock (plcnumlock)//1-29999   
+                        //    {
 
-                                    }
-                                    else
-                                    {
-                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES澶辫触  {Msgreceice}");
-                                    }
-                                }
-                                catch
-                                {
-                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{pList[0].PID}鏁版嵁涓婁紶MES寮傚父  {Msgreceice}");
-                                }
-                            }
+                        //        if (PlcNumForAll == -1)
+                        //        {
+                        //            PlcNumForAll = numplca;
+                        //        }
 
+                        //        int differ = numplca - PlcNumForAll;
 
+                        //        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"涓や釜浜у搧涓棿鐨勫樊鍊糳iffer涓簕differ}");
 
-                            int numplca = Convert.ToInt32(pList[0].SEQUENCE.Split('_')[0]);
-                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"plc缁欏嚭鐨勪骇鍝佸簭鍙蜂负{numplca}");
+                        //        if (differ > 1)
+                        //        {
+                        //            for (int i = PlcNumForAll + 1; i < numplca; i++)
+                        //            {
+                        //                try
+                        //                {
+                        //                    var plist = mysqlhelper.GetProductList(i + "_1");
+                        //                    ProductModel newp = new ProductModel();
+                        //                    newp.SEQUENCE = plist[0].SEQUENCE;
+                        //                    newp.PID = plist[0].PID;
+                        //                    newp.BasketCode = plist[0].BasketCode;
+                        //                    newp.Zword = plist[0].Zword;
+                        //                    newp.Result = "NG";
+                        //                    newp.SN = plist[0].SN;
 
-                            lock (plcnumlock)//1-29999   
-                            {
+                        //                    if (M141Config.IsfinDevice)
+                        //                    {
+                        //                        SummaryAllprodata(newp);
+                        //                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鎻愬墠NG鍔犲叆姹囨�绘暟鎹姤琛ㄧ粺璁�");
+                        //                    }
+                        //                    if (M141Config.ISupNG)
+                        //                    {
+                        //                        var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
+                        //                        M141Config.mesnum2++;
+                        //                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍚姩NG涓婁紶");
+                        //                    }
+                        //                    else
+                        //                    {
+                        //                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍏抽棴NG涓婁紶");
+                        //                    }
 
-                                if (PlcNumForAll == -1)
-                                {
-                                    PlcNumForAll = numplca;
-                                }
+                        //                }
+                        //                catch
+                        //                {
+                        //                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{i + "_1"}涓婁紶澶辫触");
+                        //                }
+                        //            }
+                        //        }
+                        //        else if (differ == -29998 && differ == 1 && differ == 0)
+                        //        {
+                        //            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鐢熶骇杩囩▼涓湭澶卞幓浜у搧");
+                        //        }
+                        //        else if (differ < 0 && differ > -29998)
+                        //        {
+                        //            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PlcNumForAll涓簕PlcNumForAll}锛宯umplca涓簕numplca}");
+                        //            //浜у搧浠庢柊璁℃暟鏃�
+                        //            for (int i = PlcNumForAll + 1; i <= 29999; i++)
+                        //            {
+                        //                try
+                        //                {
+                        //                    var plist = mysqlhelper.GetProductList(i + "_1");
+                        //                    ProductModel newp = new ProductModel();
+                        //                    newp.SEQUENCE = plist[0].SEQUENCE;
+                        //                    newp.PID = plist[0].PID;
+                        //                    newp.Zword = plist[0].Zword;
+                        //                    newp.BasketCode = plist[0].BasketCode;
+                        //                    newp.Result = "NG";
+                        //                    newp.SN = plist[0].SN;
+                        //                    if (M141Config.IsfinDevice)
+                        //                    {
+                        //                        SummaryAllprodata(newp);
+                        //                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鎻愬墠NG鍔犲叆姹囨�绘暟鎹姤琛ㄧ粺璁�");
+                        //                    }
+                        //                    if (M141Config.ISupNG)
+                        //                    {
+                        //                        var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
+                        //                        M141Config.mesnum2++;
+                        //                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍚姩NG涓婁紶");
+                        //                    }
+                        //                    else
+                        //                    {
+                        //                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍏抽棴NG涓婁紶");
+                        //                    }
 
-                                int differ = numplca - PlcNumForAll;
+                        //                }
+                        //                catch
+                        //                {
 
-                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"涓や釜浜у搧涓棿鐨勫樊鍊糳iffer涓簕differ}");
+                        //                }
+                        //            }
+                        //            for (int i = 1; i < numplca; i++)
+                        //            {
+                        //                try
+                        //                {
+                        //                    var plist = mysqlhelper.GetProductList(i + "_1");
+                        //                    ProductModel newp = new ProductModel();
+                        //                    newp.SEQUENCE = plist[0].SEQUENCE;
+                        //                    newp.PID = plist[0].PID;
+                        //                    newp.BasketCode = plist[0].BasketCode;
+                        //                    newp.Zword = plist[0].Zword;
+                        //                    newp.Result = "NG";
+                        //                    newp.SN = plist[0].SN;
+                        //                    if (M141Config.IsfinDevice)
+                        //                    {
+                        //                        SummaryAllprodata(newp);
+                        //                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鎻愬墠NG鍔犲叆姹囨�绘暟鎹姤琛ㄧ粺璁�");
+                        //                    }
+                        //                    if (M141Config.ISupNG)
+                        //                    {
+                        //                        var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
+                        //                        M141Config.mesnum2++;
+                        //                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍚姩NG涓婁紶");
+                        //                    }
+                        //                    else
+                        //                    {
+                        //                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍏抽棴NG涓婁紶");
+                        //                    }
 
-                                if (differ > 1)
-                                {
-                                    for (int i = PlcNumForAll + 1; i < numplca; i++)
-                                    {
-                                        try
-                                        {
-                                            var plist = mysqlhelper.GetProductList(i + "_1");
-                                            ProductModel newp = new ProductModel();
-                                            newp.SEQUENCE = plist[0].SEQUENCE;
-                                            newp.PID = plist[0].PID;
-                                            newp.BasketCode = plist[0].BasketCode;
-                                            newp.Zword = plist[0].Zword;
-                                            newp.Result = "NG";
-                                            newp.SN = plist[0].SN;
+                        //                    //var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
+                        //                    //M141Config.mesnum2++;
+                        //                    //LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"numplca锛屽墠绔橬G鎺掓枡涓攑lc瑙﹀彂娓呴浂浜у搧{newp.PID}鏁版嵁涓婁紶,缁撴灉涓簕newp.Result}");
+                        //                }
+                        //                catch
+                        //                {
+                        //                }
+                        //            }
+                        //        }
+                        //        PlcNumForAll = numplca;
+                        //    }
 
-                                            if (M141Config.IsfinDevice)
-                                            {
-                                                SummaryAllprodata(newp);
-                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鎻愬墠NG鍔犲叆姹囨�绘暟鎹姤琛ㄧ粺璁�");
-                                            }
-                                            if (M141Config.ISupNG)
-                                            {
-                                                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
-                                                M141Config.mesnum2++;
-                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍚姩NG涓婁紶");
-                                            }
-                                            else
-                                            {
-                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍏抽棴NG涓婁紶");
-                                            }
-
-                                        }
-                                        catch
-                                        {
-                                            LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{i + "_1"}涓婁紶澶辫触");
-                                        }
-                                    }
-                                }
-                                else if (differ == -29998 && differ == 1 && differ == 0)
-                                {
-                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"鐢熶骇杩囩▼涓湭澶卞幓浜у搧");
-                                }
-                                else if (differ < 0 && differ > -29998)
-                                {
-                                    LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PlcNumForAll涓簕PlcNumForAll}锛宯umplca涓簕numplca}");
-                                    //浜у搧浠庢柊璁℃暟鏃�
-                                    for (int i = PlcNumForAll + 1; i <= 29999; i++)
-                                    {
-                                        try
-                                        {
-                                            var plist = mysqlhelper.GetProductList(i + "_1");
-                                            ProductModel newp = new ProductModel();
-                                            newp.SEQUENCE = plist[0].SEQUENCE;
-                                            newp.PID = plist[0].PID;
-                                            newp.Zword = plist[0].Zword;
-                                            newp.BasketCode = plist[0].BasketCode;
-                                            newp.Result = "NG";
-                                            newp.SN = plist[0].SN;
-                                            if (M141Config.IsfinDevice)
-                                            {
-                                                SummaryAllprodata(newp);
-                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鎻愬墠NG鍔犲叆姹囨�绘暟鎹姤琛ㄧ粺璁�");
-                                            }
-                                            if (M141Config.ISupNG)
-                                            {
-                                                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
-                                                M141Config.mesnum2++;
-                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍚姩NG涓婁紶");
-                                            }
-                                            else
-                                            {
-                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍏抽棴NG涓婁紶");
-                                            }
-                                            //var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
-                                            //M141Config.mesnum2++;
-                                            //LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"PlcNumForAll锛屽墠绔橬G鎺掓枡涓攑lc瑙﹀彂娓呴浂浜у搧{newp.PID}鏁版嵁涓婁紶,缁撴灉涓簕newp.Result}");
-
-                                        }
-                                        catch
-                                        {
-
-                                        }
-                                    }
-                                    for (int i = 1; i < numplca; i++)
-                                    {
-                                        try
-                                        {
-                                            var plist = mysqlhelper.GetProductList(i + "_1");
-                                            ProductModel newp = new ProductModel();
-                                            newp.SEQUENCE = plist[0].SEQUENCE;
-                                            newp.PID = plist[0].PID;
-                                            newp.BasketCode = plist[0].BasketCode;
-                                            newp.Zword = plist[0].Zword;
-                                            newp.Result = "NG";
-                                            newp.SN = plist[0].SN;
-                                            if (M141Config.IsfinDevice)
-                                            {
-                                                SummaryAllprodata(newp);
-                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鎻愬墠NG鍔犲叆姹囨�绘暟鎹姤琛ㄧ粺璁�");
-                                            }
-                                            if (M141Config.ISupNG)
-                                            {
-                                                var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
-                                                M141Config.mesnum2++;
-                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍚姩NG涓婁紶");
-                                            }
-                                            else
-                                            {
-                                                LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{newp.PID}鍏抽棴NG涓婁紶");
-                                            }
-
-                                            //var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.mesnum2.ToString(), M141Config.numpro)).Result;
-                                            //M141Config.mesnum2++;
-                                            //LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"numplca锛屽墠绔橬G鎺掓枡涓攑lc瑙﹀彂娓呴浂浜у搧{newp.PID}鏁版嵁涓婁紶,缁撴灉涓簕newp.Result}");
-                                        }
-                                        catch
-                                        {
-                                        }
-                                    }
-                                }
-                                PlcNumForAll = numplca;
-                            }
-
-                        }
-
+                        //}
+                        //else
+                        //{
+                        //    LogAsync(DateTime.Now, EnumHelper.LogLevel.Information, $"宸插叧闂璵es杩炴帴鎴栬�呮暟鎹笂浼犳帴鍙�");
+                        //}
                     }
 
                     //ReplyPlcData(positionName, config.TriggerValue);
@@ -1564,7 +1617,6 @@
 
             });
         }
-
 
         public void ReplyPlcData(WorkPositionSet p, List<bool> result)
         {
@@ -1629,7 +1681,7 @@
                             data += "NA,";
                         }
                     }
-                    CSVRecordAsync($"AllDeviceProductRecord.csv", data, Head);
+                    CSVRecordAsync($"AllDeviceProductRecord_{DateTime.Now.ToString("yyyyMMdd")}.csv", data, Head);
 
                 }
                 catch (Exception exx)
@@ -1639,9 +1691,6 @@
             });
 
         }
-
-
-
 
         #endregion
 
@@ -1823,35 +1872,33 @@
         }
 
 
-
-
-
-
         #region  鎵撳嵃鏈虹浉鍏�
         PrintDocument printDocument1 = new PrintDocument();
         string Printmessage = "";
 
-        public void StartPrint(string str)
+        public void StartPrint(string str, string PrinterName)
         {
             try
             {
-                int ttwith = 320;
-                int ttheigh = 160;
+                LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"鎵撳嵃鏈烘墦鍗皗str}");
+                int ttwith = 240;
+                int ttheigh = 80;
                 Printmessage = str;
 
-                this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)";
+                this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = PrinterName;
                 this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith, ttheigh);
 
                 this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController();
                 this.printDocument1.Print();
 
             }
-            catch
+            catch(Exception ex)
             {
-
+                LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"鎵撳嵃鏈烘墦鍗板嚭閿�:{ex.ToString()}");
             }
 
         }
+
 
 
         //C229M2508250500002
@@ -1869,14 +1916,14 @@
                 {
                     DisableECI = true,//璁剧疆鍐呭缂栫爜
                     CharacterSet = "UTF-8",  //璁剧疆浜岀淮鐮佺殑瀹藉害鍜岄珮搴�
-                    Width = 123,
-                    Height = 123,
+                    Width = 60,
+                    Height = 60,
                     Margin = 1//璁剧疆浜岀淮鐮佺殑杈硅窛,鍗曚綅涓嶆槸鍥哄畾鍍忕礌
                 };
 
                 writer.Options = options;
                 Bitmap map = writer.Write(Printmessage);
-                e.Graphics.DrawImage(map, new System.Drawing.Point(90, 10));
+                e.Graphics.DrawImage(map, new System.Drawing.Point(90, 4));
 
                 // 鍦ㄤ簩缁寸爜涓嬫柟鐢诲唴瀹规枃瀛�
                 using (Font font = new Font("Arial", 10))
@@ -1885,7 +1932,7 @@
                     // 璁╂枃瀛楀眳涓埌浜岀淮鐮佷笅鏂�
                     SizeF textSize = e.Graphics.MeasureString(Printmessage, font);
                     float textX = 90 + (map.Width - textSize.Width) / 2;
-                    float textY = 10 + map.Height;
+                    float textY = 1 + map.Height;
 
                     e.Graphics.DrawString(Printmessage, font, brush3, textX, textY);
                 }
@@ -1902,11 +1949,6 @@
 
 
         #endregion
-
-
-
-
-
 
     }
 

--
Gitblit v1.8.0