WIN-GH9CEESPLTB\Administrator 1 месяц назад
Родитель
Сommit
9cd6587197
1 измененных файлов с 80 добавлено и 19 удалено
  1. 80 19
      MainForm/FaForm/Form_Home.cs

+ 80 - 19
MainForm/FaForm/Form_Home.cs

@@ -37,6 +37,7 @@ using System.Web.Services.Description;
 using System.Numerics;
 using MathNet.Numerics.RootFinding;
 using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
+using static MainForm.ClassFile.XiaomiClass.MesHelper;
 
 /*
  * 注:本源码对外提供,所以有些地方使用中文命名方法及变量
@@ -1233,7 +1234,51 @@ namespace MainForm
 
             return compensationDict;
         }
+        public int PCBStationOutData(BarcodeSet_t Barcode,IoT_DataSet_t iotData)
+        {
+            int res = 0;
+            string jsonstr1 = "";
+            try
+            {
+                XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
+                outRequest_Body.machineId = GlobalContext.S5_MachineId;  // 装备id(可配置) 
+                outRequest_Body.stationId = GlobalContext.S5_station;  // ⼯位ID(可配置)  
+                outRequest_Body.clientMac = GlobalContext.MacStr;    // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
+                outRequest_Body.clientTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");  // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
+                outRequest_Body.unitSn = Barcode.strPCBBarcode;                         // 产品SN
+                int a1Result = (int)iotData.testStatus;
+                bool pass = a1Result == 1;
+                outRequest_Body.state = pass ? "PASS" : "FAIL"; ;      // 出站条件 PASS或FAIL
+                outRequest_Body.userId = GlobalContext.MESUserId;           // ⽤⼾ID
+                outRequest_Body.factoryId = GlobalContext.Factory_Code;     // ⼯⼚id
+
+                jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
+
+                XmMES_StationOutResponse response = new XmMES_StationOutResponse();
+
+                response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
+
+                if (response != null && response.header.code == "200")
+                {
+                    res = 1;
+                    AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---成功!请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
+                }
+                else
+                {
+                    res = 0;
+                    AddMessage(LogType.Error, "上传PCB出站数据到MES服务器---失败!错误信息:"+ response.header.desc + ",请求信息:" + jsonstr1 + ",返回信息:" + JsonConvert.SerializeObject(response.body));
+                }
+            }
+            catch (Exception e)
+            {
+                res = 0;
+                AddMessage(LogType.Info, "上传PCB出站数据到MES服务器---失败!请求信息:" + jsonstr1 + ",返回信息:" + e.Message);
+            }
 
+            
+           
+            return res;
+        }
 
         /// <summary>
         /// 调用进站接口并保存进站数据
@@ -2067,7 +2112,7 @@ namespace MainForm
                 string MachineId = GlobalContext.S1_MachineId;  // 装备id(可配置)  
                 string StationId = GlobalContext.S1_StationId;  // ⼯位ID(可配置)
                 int a1Result = (int)stPLC_MesData.iotData.testStatus;          // 产品结果
-                a1Result = 1;
+                //a1Result = 1;
                 bool pass = a1Result == 1;
 
                 //根据载具码获取产品码
@@ -3171,7 +3216,10 @@ namespace MainForm
                         }
                         else
                         {
-                            //richTextBox1.AppendText("\n" + "读取成功");
+                            #region PCB出站
+                            //stPLC_MesData.BarcodeSet.strPCBBarcode = "A1507V000243";
+                            S5_PCB出站(stPLC_MesData, plcNo, stationNameStr, tagBaseName,tagMesCommName);
+                            #endregion
                         }
                         #endregion 一次性读取所有数据
                         stopwatch2.Stop();
@@ -3269,21 +3317,8 @@ namespace MainForm
                 string MachineId = GlobalContext.S5_MachineId;  // 装备ID(可配置)
                 string StationId = GlobalContext.S5_StationId;  // 工位ID(可配置)
                 string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode;  // 载具条码
-                string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
 
-                //绑定载具和产品
-                ResponseMessage message = new ResponseMessage();
-                if (pcbBarcode == "ERROR")
-                {
-                    ProgressState = false;
-                    AddMessage(LogType.Error, stationNameStr + "_进站失败!无效PCB码");
-                    return;
-                }
-                message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
-                if (message.result == false)
-                {
-                    AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
-                }
+
                 //载具码验证产品码                                                                              //载具码验证产品码 
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
 
@@ -3293,7 +3328,7 @@ namespace MainForm
                 }
 
                 sn = strProductBarcode;
-                AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
+                AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
 
                 // 产品SN(物料码)校验
                 List<TestItem> item = new List<TestItem>();
@@ -3353,6 +3388,8 @@ namespace MainForm
                 string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;  // 产品条码;
                 string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode;  // 产品条码;
                 string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode;  // 载具条码;
+                string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
+
                 string MachineId = GlobalContext.S5_MachineId;  // 装备id(可配置)  // ZS
                 string StationId = GlobalContext.S5_StationId;  // ⼯位ID(可配置)  // ZS
                 int a1Result = (int)stPLC_MesData.iotData.testStatus;          // 产品结果
@@ -3365,7 +3402,7 @@ namespace MainForm
                     AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
                 }
                 sn = strProductBarcode;
-                AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
+                AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
 
                 List<TestItem> items = new List<TestItem>();
                 items.Add(new TestItem()
@@ -3433,6 +3470,30 @@ namespace MainForm
             ProgressState = false;
         }
 
+        private void S5_PCB出站(OP50_MesData_t stPLC_MesData,int plcNo,string stationNameStr,string tagBaseName,string tagMesCommName) {
+            if (stPLC_MesData.BarcodeSet.strPCBBarcode.Replace("\r", "") != "ERROR")
+            {
+                int res = PCBStationOutData(stPLC_MesData.BarcodeSet, stPLC_MesData.iotData);
+                CommandFromPLC resultToPlC = new CommandFromPLC();
+                resultToPlC.cmd = 0;
+                resultToPlC.cmdParam = 0; //指令参数
+                if (res == 1)
+                {
+                    resultToPlC.cmdResult = 2;
+                    WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
+                }
+                else
+                {
+                    resultToPlC.cmdResult = 120;
+                    WriteResultToPlc(plcNo, stationNameStr, tagBaseName + "." + tagMesCommName, 1, resultToPlC);
+                }
+            }
+            else
+            {
+                return;
+            }
+
+        }
         #endregion
 
         #region S6
@@ -4041,7 +4102,7 @@ namespace MainForm
                     StationId = GlobalContext.S7_StationId_2;
                 }
                 int a1Result = (int)stPLC_MesData.iotData.testStatus;          // 产品结果
-                a1Result = 1;
+                //a1Result = 1;
                 bool pass = a1Result == 1;
                 //根据载具码获取产品码
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);