Browse Source

特殊字符、pcb出站bug修复

WIN-GH9CEESPLTB\Administrator 1 month ago
parent
commit
618a38fba0
2 changed files with 73 additions and 31 deletions
  1. 1 1
      MainForm/ClassFile/Inovance_EIP.cs
  2. 72 30
      MainForm/FaForm/Form_Home.cs

+ 1 - 1
MainForm/ClassFile/Inovance_EIP.cs

@@ -291,7 +291,7 @@ namespace EIP_Protocol
         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 101)]    //工位零部件条码
         public string strPartBarcode;
 
-        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 101)]    //工位零部件条码
+        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 101)]    //PCB
         public string strPCBBarcode;
     }
 

+ 72 - 30
MainForm/FaForm/Form_Home.cs

@@ -39,6 +39,7 @@ using MathNet.Numerics.RootFinding;
 using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
 using static MainForm.ClassFile.XiaomiClass.MesHelper;
 using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
+using System.Text.RegularExpressions;
 
 /*
  * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
@@ -1937,7 +1938,16 @@ namespace MainForm
                 isCollectingFlagRight = false;
             }
         }
-
+        /// <summary>
+        /// 去除常见特殊字符,如 \r, \n, \t 等
+        /// </summary>
+        /// <param name="format"></param>
+        /// <returns></returns>
+        private static string FormatStrbyPLC(string format) {
+            
+            string cleanedString = Regex.Replace(format, @"[\r\n\t]", "");
+            return cleanedString;
+        }
 
         #endregion
 
@@ -1985,6 +1995,11 @@ namespace MainForm
                         else
                         {
                             //richTextBox1.AppendText("\n" + "读取成功");
+                            stPLC_MesData.BarcodeSet.strProductBarcode=FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
+
                         }
                         #endregion 一次性读取所有数据
                         stopwatch2.Stop();
@@ -2278,6 +2293,10 @@ namespace MainForm
                         else
                         {
                             //richTextBox1.AppendText("\n" + "读取成功");
+                            stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
                         }
                         #endregion 一次性读取所有数据
                         stopwatch2.Stop();
@@ -2613,7 +2632,16 @@ namespace MainForm
                         }
                         else
                         {
-                            //richTextBox1.AppendText("\n" + "读取成功");
+                            #region 去除扫码产生的特殊字符
+                            stPLC_MesData.Left.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.Left.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.Left.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
+                            stPLC_MesData.Right.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.Right.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.Right.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.Right.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
+                            #endregion
                         }
                         #endregion 一次性读取所有数据
                         stopwatch2.Stop();
@@ -2982,7 +3010,11 @@ namespace MainForm
                         }
                         else
                         {
-                            //richTextBox1.AppendText("\n" + "读取成功");
+                            //去除扫码产生的特殊字符
+                            stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
                         }
                         #endregion 一次性读取所有数据
                         stopwatch2.Stop();
@@ -3268,24 +3300,14 @@ namespace MainForm
                         }
                         else
                         {
-                            #region PCB出站
-                            stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
-                            stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
-
-                            //pcbBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
-                            //if (pcbBarcode!= pcbBarcodeOld)
-                            //{
-                            //    isPCBStation = true;
-                            //}
-                            //if (isPCBStation)
-                            //{
-                            //    var r = S5_PCB进出站(stPLC_MesData, plcNo, stationNameStr, tagBaseName, tagMesCommName);
-                            //    if (r > 0)
-                            //    {
-                            //        isPCBStation = false;
-                            //        pcbBarcodeOld = pcbBarcode;
-                            //    }
-                            //}
+                            stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239\r";
+                            //stPLC_MesData.BarcodeSet.strCarrierBarcode = "A123456";
+
+                            #region 去除扫码产生的特殊字符
+                            stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
                             #endregion
                         }
                         #endregion 一次性读取所有数据
@@ -3300,8 +3322,7 @@ namespace MainForm
                                 {
                                     if (!ProgressState)
                                     {
-                                        string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode.Replace("\r", "");
-                                        stPLC_MesData.BarcodeSet.strPCBBarcode = PCBBarcode;//特殊字符处理
+                                        string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
                                         if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
                                         {
                                             ProgressState = true;
@@ -3460,7 +3481,7 @@ namespace MainForm
                 string batch_num = GlobalContext.BatchNumber;         // 批次号
                 string mtltmrk = GlobalContext.Mtltmrk;               // 产品型号
                 string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;  // 产品条码;
-                string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode;  // 产品条码;
+                string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode;  // 部件条码;
                 string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode;  // 载具条码;
                 string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
 
@@ -3483,6 +3504,7 @@ namespace MainForm
                     WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
                     return;
                 }
+                stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
                 sn = strProductBarcode;
                 //数据库绑定载具和PCB
                 ResponseMessage message = new ResponseMessage();
@@ -3571,8 +3593,7 @@ namespace MainForm
             ProgressState = false;
         }
         private int S5_PCB进出站(OP50_MesData_t stPLC_MesData,int plcNo,string stationNameStr,string tagBaseName,string tagMesCommName) {
-            string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode.Replace("\r", "");
-            stPLC_MesData.BarcodeSet.strPCBBarcode = PCBBarcode;//特殊字符处理
+            string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
             if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
             {
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
@@ -3671,7 +3692,11 @@ namespace MainForm
                         }
                         else
                         {
-                            //richTextBox1.AppendText("\n" + "读取成功");
+                            //去除扫码产生的特殊字符
+                            stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
                         }
                         #endregion 一次性读取所有数据
                         stopwatch2.Stop();
@@ -3974,7 +3999,16 @@ namespace MainForm
                         }
                         else
                         {
-                            //richTextBox1.AppendText("\n" + "读取成功");
+                            #region 去除扫码产生的特殊字符
+                            stPLC_MesData.Left.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.Left.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.Left.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.Left.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Left.BarcodeSet.strPCBBarcode);
+                            stPLC_MesData.Right.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.Right.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.Right.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.Right.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.Right.BarcodeSet.strPCBBarcode);
+                            #endregion
                         }
                         #endregion 一次性读取所有数据
 
@@ -4389,7 +4423,11 @@ namespace MainForm
                         }
                         else
                         {
-                            //richTextBox1.AppendText("\n" + "读取成功");
+                            //去除扫码产生的特殊字符
+                            stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
                         }
                         #endregion 一次性读取所有数据
                         stopwatch2.Stop();
@@ -4668,7 +4706,11 @@ namespace MainForm
                         }
                         else
                         {
-                            //richTextBox1.AppendText("\n" + "读取成功");
+                            //去除扫码产生的特殊字符
+                            stPLC_MesData.BarcodeSet.strProductBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strProductBarcode);
+                            stPLC_MesData.BarcodeSet.strPartBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPartBarcode);
+                            stPLC_MesData.BarcodeSet.strCarrierBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strCarrierBarcode);
+                            stPLC_MesData.BarcodeSet.strPCBBarcode = FormatStrbyPLC(stPLC_MesData.BarcodeSet.strPCBBarcode);
                         }
                         #endregion 一次性读取所有数据
                         stopwatch2.Stop();