Quellcode durchsuchen

Merge branch 'master' into dev20250218_IOT开发

# Conflicts:
#	MainForm/FaForm/Form_Home.cs
WIN-GH9CEESPLTB\Administrator vor 1 Monat
Ursprung
Commit
a567ebebf2
2 geänderte Dateien mit 167 neuen und 113 gelöschten Zeilen
  1. 1 1
      MainForm/ClassFile/Inovance_EIP.cs
  2. 166 112
      MainForm/FaForm/Form_Home.cs

+ 1 - 1
MainForm/ClassFile/Inovance_EIP.cs

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

+ 166 - 112
MainForm/FaForm/Form_Home.cs

@@ -53,6 +53,7 @@ using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmME
 using System.Drawing.Imaging;
 using System.Drawing.Imaging;
 using System.Drawing;
 using System.Drawing;
 using ICSharpCode.SharpZipLib.Zip;
 using ICSharpCode.SharpZipLib.Zip;
+using System.Text.RegularExpressions;
 
 
 /*
 /*
  * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
  * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
@@ -3167,6 +3168,16 @@ namespace MainForm
                 stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
                 stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
                 stopwatch2.ElapsedMilliseconds + "ms");
                 stopwatch2.ElapsedMilliseconds + "ms");
         }
         }
+        /// <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
         #endregion
 
 
@@ -3230,6 +3241,11 @@ namespace MainForm
                         else
                         else
                         {
                         {
                             //richTextBox1.AppendText("\n" + "读取成功");
                             //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);
+
                             //设备状态
                             //设备状态
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
@@ -3528,7 +3544,7 @@ namespace MainForm
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
                     ProgressState = false;
                     ProgressState = false;
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                     Thread.Sleep(10000);
                     Thread.Sleep(10000);
                     return;
                     return;
                 }
                 }
@@ -3692,6 +3708,10 @@ namespace MainForm
                         else
                         else
                         {
                         {
                             //richTextBox1.AppendText("\n" + "读取成功");
                             //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);
 
 
                             //设备状态
                             //设备状态
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
@@ -3895,7 +3915,7 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                 }
                 }
 
 
                 //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
                 //这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
@@ -3983,8 +4003,8 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                     ProgressState = false;
                     ProgressState = false;
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
                     Thread.Sleep(10000);
                     Thread.Sleep(10000);
                     return;
                     return;
                 }
                 }
@@ -4138,6 +4158,16 @@ namespace MainForm
                         }
                         }
                         else
                         else
                         {
                         {
+                            #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
                             //richTextBox1.AppendText("\n" + "读取成功");
                             //richTextBox1.AppendText("\n" + "读取成功");
                             //设备状态
                             //设备状态
                             int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
                             int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
@@ -4511,7 +4541,7 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                 }
                 }
 
 
                 sn = strProductBarcode;
                 sn = strProductBarcode;
@@ -4605,8 +4635,8 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                     ProgressState = false;
                     ProgressState = false;
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
                     Thread.Sleep(10000);
                     Thread.Sleep(10000);
                     return;
                     return;
                 }
                 }
@@ -4768,6 +4798,11 @@ namespace MainForm
                         }
                         }
                         else
                         else
                         {
                         {
+                            //去除扫码产生的特殊字符
+                            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);
                             //richTextBox1.AppendText("\n" + "读取成功");
                             //richTextBox1.AppendText("\n" + "读取成功");
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
@@ -4965,8 +5000,8 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                     ProgressState = false;
                     ProgressState = false;
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
                     Thread.Sleep(10000);
                     Thread.Sleep(10000);
                     return;
                     return;
                 }
                 }
@@ -5050,8 +5085,8 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                     ProgressState = false;
                     ProgressState = false;
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
                     Thread.Sleep(10000);
                     Thread.Sleep(10000);
                     return;
                     return;
                 }
                 }
@@ -5337,23 +5372,14 @@ namespace MainForm
                         }
                         }
                         else
                         else
                         {
                         {
-                            #region PCB出站
-                            //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000239";
-                            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";
                             //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
                             //richTextBox1.AppendText("\n" + "读取成功");
                             //richTextBox1.AppendText("\n" + "读取成功");
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
@@ -5384,8 +5410,13 @@ namespace MainForm
                                     {
                                     {
                                         uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
                                         uuid = Guid.NewGuid().ToString(); //创建贯穿进出站的uuid
                                         ProgressState = true;
                                         ProgressState = true;
-                                        isPCBStation = true;//开启PCB进出站
-                                        Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
+                                        string PCBBarcode = stPLC_MesData.BarcodeSet.strPCBBarcode;
+                                        if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
+                                        {
+                                            ProgressState = true;
+                                            Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData, tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName, out ProgressState));
+
+                                        }
                                     }
                                     }
                                 }
                                 }
                             }
                             }
@@ -5543,15 +5574,15 @@ namespace MainForm
             {
             {
                 stopwatch1.Start();
                 stopwatch1.Start();
                 AddMessage(LogType.Info, stationNameStr + "_进站开始");
                 AddMessage(LogType.Info, stationNameStr + "_进站开始");
-                string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
+                //string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;  // 产品SN(物料码)
                 //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
                 //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
-
-                string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
-                string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
+                string MachineId = GlobalContext.S5_MachineId;  // 装备ID(可配置)
+                string StationId = GlobalContext.S5_StationId;  // 工位ID(可配置)
                 string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
                 string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
                 string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
                 string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
                 int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
                 int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
                 bool pass = a1Result == 1;
                 bool pass = a1Result == 1;
+                AddMessage(LogType.Info, $"ADD板编码(PCB码):{pcbBarcode}");
 
 
                 //绑定载具和产品
                 //绑定载具和产品
                 ResponseMessage message = new ResponseMessage();
                 ResponseMessage message = new ResponseMessage();
@@ -5562,15 +5593,15 @@ namespace MainForm
                 }
                 }
 
 
                 //载具码验证产品码                                                                              //载具码验证产品码 
                 //载具码验证产品码                                                                              //载具码验证产品码 
-                string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
+                //string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
 
 
-                if (string.IsNullOrEmpty(strProductBarcode))
-                {
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
-                }
+                //if (string.IsNullOrEmpty(strProductBarcode))
+                //{
+                //    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
+                //}
 
 
-                sn = strProductBarcode;
-                AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
+                //sn = strProductBarcode;
+                //AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
 
 
                 // 产品SN(物料码)校验
                 // 产品SN(物料码)校验
                 List<TestItem> item = new List<TestItem>();
                 List<TestItem> item = new List<TestItem>();
@@ -5580,10 +5611,9 @@ namespace MainForm
                 stopwatch2.Stop();
                 stopwatch2.Stop();
 
 
                 //指令执行结果 1:OK   110:失败
                 //指令执行结果 1:OK   110:失败
-                byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
+                byte mesResultFrmWeb = (byte)(result == 1 ? 2 : 120);
                 if (mesResultFrmWeb == 1)
                 if (mesResultFrmWeb == 1)
                 {
                 {
-                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
                     AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
                     AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
                 }
                 }
 
 
@@ -5639,7 +5669,7 @@ namespace MainForm
                 string batch_num = GlobalContext.BatchNumber;         // 批次号
                 string batch_num = GlobalContext.BatchNumber;         // 批次号
                 string mtltmrk = GlobalContext.Mtltmrk;               // 产品型号
                 string mtltmrk = GlobalContext.Mtltmrk;               // 产品型号
                 string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;  // 产品条码;
                 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 CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode;  // 载具条码;
                 string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
                 string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
 
 
@@ -5647,24 +5677,31 @@ namespace MainForm
                 string StationId = GlobalContext.S5_StationId;  // ⼯位ID(可配置)  // ZS
                 string StationId = GlobalContext.S5_StationId;  // ⼯位ID(可配置)  // ZS
                 int a1Result = (int)stPLC_MesData.iotData.testStatus;          // 产品结果
                 int a1Result = (int)stPLC_MesData.iotData.testStatus;          // 产品结果
                 bool pass = a1Result == 1;
                 bool pass = a1Result == 1;
+                CommandFromPLC resultToPlC = new CommandFromPLC();
 
 
                 //根据载具码获取产品码
                 //根据载具码获取产品码
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
-                    ProgressState = false;
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
-                    Thread.Sleep(10000);
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
+                    ProgressState=false;
+                    //写入PLC
+                    resultToPlC.cmd = 0;
+                    resultToPlC.cmdParam = 0; //指令参数
+                    resultToPlC.cmdResult = 110;
+                    WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
                     return;
                     return;
                 }
                 }
-
+                stPLC_MesData.BarcodeSet.strProductBarcode = strProductBarcode;
                 sn = strProductBarcode;
                 sn = strProductBarcode;
                 //数据库绑定载具和PCB
                 //数据库绑定载具和PCB
                 ResponseMessage message = new ResponseMessage();
                 ResponseMessage message = new ResponseMessage();
                 message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
                 message = SQLHelper.PCBCarrierBind(CarrierBarcode, pcbBarcode);
                 if (message.result == false)
                 if (message.result == false)
                 {
                 {
-                    AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
+                    AddMessage(LogType.Error, stationNameStr + "_PCB码数据库绑定失败,错误:" + message.text);
+                    ProgressState = true;//防止循环报错
+                    return;
                 }
                 }
                 AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
                 AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
 
 
@@ -5681,6 +5718,12 @@ namespace MainForm
                     Parameter_value = sn,
                     Parameter_value = sn,
                     Parameter_unit = ""
                     Parameter_unit = ""
                 });
                 });
+                items.Add(new TestItem()
+                {
+                    Parameter_name = "PCB码",
+                    Parameter_value = pcbBarcode,
+                    Parameter_unit = ""
+                });
 
 
                 #region 上传图片
                 #region 上传图片
 
 
@@ -5708,33 +5751,32 @@ namespace MainForm
                     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
                     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1",
                     MachineId, StationId, PartBarcode, paramJson);
                     MachineId, StationId, PartBarcode, paramJson);
 
 
-                byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
-                if (mesResultFrmWeb == 1)
-                {
-                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
-                    AddMessage(LogType.Info, stationNameStr + "_出站PLC检测结果:FAIL");
+                int result1 = 0;
+                byte mesResultFrmWeb = 0;
+                if (stPLC_MesData.mesCommFrmPLC.cmdParam == 2) {
+                    result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num
+                        , mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
+                }
+                else if (stPLC_MesData.mesCommFrmPLC.cmdParam == 1) {
+                    result1=PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
                 }
                 }
+                mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
 
 
-                stopwatch2.Start();
                 //进站结果写入PLC
                 //进站结果写入PLC
-                CommandFromPLC resultToPlC = new CommandFromPLC();
                 resultToPlC.cmd = 0;
                 resultToPlC.cmd = 0;
                 resultToPlC.cmdParam = 0; //指令参数
                 resultToPlC.cmdParam = 0; //指令参数
                 resultToPlC.cmdResult = mesResultFrmWeb;
                 resultToPlC.cmdResult = mesResultFrmWeb;
                 WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
                 WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
-                stopwatch2.Stop();
                 AddMessage(LogType.Info, stationNameStr + "_出站结束");
                 AddMessage(LogType.Info, stationNameStr + "_出站结束");
 
 
                 //保存PLC返回MES数据到本地
                 //保存PLC返回MES数据到本地
                 //ResponseMessage message = new ResponseMessage();
                 //ResponseMessage message = new ResponseMessage();
                 message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
                 message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
-                    stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
-                    stPLC_MesData.mesData.nRemainCount, "");
+                    stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB, stPLC_MesData.mesData.nRemainCount, "");
                 if (message.result == false)
                 if (message.result == false)
                 {
                 {
                     AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
                     AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
                 }
                 }
-
                 //保存部件码信息
                 //保存部件码信息
                 if (!string.IsNullOrEmpty(PartBarcode))
                 if (!string.IsNullOrEmpty(PartBarcode))
                 {
                 {
@@ -5744,7 +5786,6 @@ namespace MainForm
                         AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
                         AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
                     }
                     }
                 }
                 }
-
                 AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
                 AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
             }
             }
             catch (Exception ex)
             catch (Exception ex)
@@ -5769,8 +5810,7 @@ namespace MainForm
             ProgressState = false;
             ProgressState = false;
         }
         }
         private int S5_PCB进出站(OP50_MesData_t stPLC_MesData,int plcNo,string stationNameStr,string tagBaseName,string tagMesCommName) {
         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))
             if (PCBBarcode != "ERROR" && !string.IsNullOrEmpty(PCBBarcode))
             {
             {
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(stPLC_MesData.BarcodeSet.strCarrierBarcode);
@@ -5782,19 +5822,19 @@ namespace MainForm
 
 
                 if (GlobalContext.IsSendStationIn)
                 if (GlobalContext.IsSendStationIn)
                 {
                 {
-                    #region 
-                    int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
-                    if (res1 == 1)
-                    {
-                        resultToPlC.cmdResult = 2;//OK
-                        WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
-                    }
-                    else
-                    {
-                        resultToPlC.cmdResult = 120;
-                        WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
-                        return 2;
-                    }
+                    #region 
+                    //int res1 = PCBStationInData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
+                    //if (res1 == 1)
+                    //{
+                    //    resultToPlC.cmdResult = 2;//OK
+                    //    WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
+                    //}
+                    //else
+                    //{
+                    //    resultToPlC.cmdResult = 120;
+                    //    WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
+                    //    return 2;
+                    //}
                     #endregion
                     #endregion
 
 
                     #region 出站
                     #region 出站
@@ -6055,6 +6095,11 @@ namespace MainForm
                         }
                         }
                         else
                         else
                         {
                         {
+                            //去除扫码产生的特殊字符
+                            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);
                             //richTextBox1.AppendText("\n" + "读取成功");
                             //richTextBox1.AppendText("\n" + "读取成功");
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
@@ -6255,7 +6300,7 @@ namespace MainForm
 
 
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                 }
                 }
 
 
                 sn = strProductBarcode;
                 sn = strProductBarcode;
@@ -6360,10 +6405,7 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
-                    ProgressState = false;
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
-                    Thread.Sleep(10000);
-                    return;
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                 }
                 }
 
 
                 sn = strProductBarcode;
                 sn = strProductBarcode;
@@ -6627,7 +6669,16 @@ namespace MainForm
                         }
                         }
                         else
                         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
 
 
                             int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
                             int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
                             int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
                             int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
@@ -7005,7 +7056,7 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                 }
                 }
 
 
                 sn = strProductBarcode;
                 sn = strProductBarcode;
@@ -7125,10 +7176,7 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
-                    ProgressState = false;
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
-                    Thread.Sleep(10000);
-                    return;
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                 }
                 }
 
 
                 sn = strProductBarcode;
                 sn = strProductBarcode;
@@ -7424,6 +7472,14 @@ namespace MainForm
                         }
                         }
                         else
                         else
                         {
                         {
+                            //去除扫码产生的特殊字符
+                            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();
                             //richTextBox1.AppendText("\n" + "读取成功");
                             //richTextBox1.AppendText("\n" + "读取成功");
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
@@ -7706,31 +7762,27 @@ namespace MainForm
                     int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
                     int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
                     bool pass = a1Result == 1;
                     bool pass = a1Result == 1;
 
 
-                    //根据载具码获取产品码
-                    string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
-                    if (string.IsNullOrEmpty(strProductBarcode))
-                    {
-                        ProgressState = false;
-                        AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
-                        Thread.Sleep(10000);
-                        return;
-                    }
-
-                    sn = strProductBarcode;
-                    AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
-                    List<TestItem> items = new List<TestItem>();
-                    items.Add(new TestItem()
-                    {
-                        Parameter_name = "载具码",
-                        Parameter_value = CarrierBarcode,
-                        Parameter_unit = ""
-                    });
-                    items.Add(new TestItem()
-                    {
-                        Parameter_name = "产品码",
-                        Parameter_value = sn,
-                        Parameter_unit = ""
-                    });
+                //根据载具码获取产品码
+                string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
+                if (string.IsNullOrEmpty(strProductBarcode))
+                {
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
+                }
+                sn = strProductBarcode;
+                AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
+                List<TestItem> items = new List<TestItem>();
+                items.Add(new TestItem()
+                {
+                    Parameter_name = "载具码",
+                    Parameter_value = CarrierBarcode,
+                    Parameter_unit = ""
+                });
+                items.Add(new TestItem()
+                {
+                    Parameter_name = "产品码",
+                    Parameter_value = sn,
+                    Parameter_unit = ""
+                });
 
 
                     #region 上传图片
                     #region 上传图片
 
 
@@ -7992,6 +8044,11 @@ namespace MainForm
                         }
                         }
                         else
                         else
                         {
                         {
+                            //去除扫码产生的特殊字符
+                            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);
                             //richTextBox1.AppendText("\n" + "读取成功");
                             //richTextBox1.AppendText("\n" + "读取成功");
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
                             xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
@@ -8194,7 +8251,7 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                 }
                 }
 
 
                 sn = strProductBarcode;
                 sn = strProductBarcode;
@@ -8277,10 +8334,7 @@ namespace MainForm
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
                 if (string.IsNullOrEmpty(strProductBarcode))
                 if (string.IsNullOrEmpty(strProductBarcode))
                 {
                 {
-                    ProgressState = false;
-                    AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
-                    Thread.Sleep(10000);
-                    return;
+                    AddMessage(LogType.Error, $"{stationNameStr}_数据库未查询到该载具绑定信息!");
                 }
                 }
 
 
                 sn = strProductBarcode;
                 sn = strProductBarcode;