Browse Source

iot过站结果、操作记录

WIN-GH9CEESPLTB\Administrator 1 month ago
parent
commit
baa95d505e

+ 9 - 0
MainForm/ClassFile/ProjectClass/GlobalContext.cs

@@ -171,6 +171,7 @@ namespace MainForm
         public static string MQTTServerHost;         // 服务器IP
         public static int MQTTServerPort;            // 服务器Port
         public static bool IsMqttSendProcessData;    // 上传过站数据
+        public static bool IsMqttSendProcessResult;    // 上传过站数据
         public static bool IsMqttDeviceState;        // 上传设备状态
         public static bool IsMqttFaultLog;           // 上传故障⽇志
         public static bool IsMqttSensorData;         // 上传传感器数据
@@ -182,6 +183,10 @@ namespace MainForm
         public static string MQTTAppPwd;           // IOT登录密码
         public static int IsUsePLCNow { set; get; } = 0;              // 单机模式下,存储当前在用的plcNum
         public static string IsUseStationName { set; get; } = "";     // 单机模式下,存储当前在用的主工站全称
+        public static string address;           // fds地址
+        public static string appId;           // fds应⽤识别码
+        public static string appKey;           // fds应⽤密钥
+
 
         // IOT-AGV
         public static bool IsUseAGV;  // 是否 启用AGV
@@ -424,6 +429,7 @@ namespace MainForm
                 MQTTServerHost = IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTServerHost", "127.0.0.1");
                 MQTTServerPort = int.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTServerPort", "80"));
                 IsMqttSendProcessData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSendProcessData", ConstIsSend));
+                IsMqttSendProcessResult = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSendProcessResult", ConstIsSend));
                 IsMqttDeviceState = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttDeviceState", ConstIsSend));
                 IsMqttFaultLog = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttFaultLog", ConstIsSend));
                 IsMqttSensorData = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttSensorData", ConstIsSend));
@@ -433,6 +439,9 @@ namespace MainForm
                 IsMqttProcConfig = bool.Parse(IniFile.INIGetStringValue(FilePath, "MQTT", "IsMqttProcConfig", ConstIsSend));
                 MQTTAppId = IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTAppId", "AKPKTSQAS46NKE4NHY");
                 MQTTAppPwd = IniFile.INIGetStringValue(FilePath, "MQTT", "MQTTAppPwd", "pwd");
+                appKey = IniFile.INIGetStringValue(FilePath, "MQTT", "appKey", ConstIsSend);
+                appId = IniFile.INIGetStringValue(FilePath, "MQTT", "appId", ConstIsSend);
+                address = IniFile.INIGetStringValue(FilePath, "MQTT", "address", ConstIsSend);
 
                 // AGV配置
                 IsUseAGV = bool.Parse(IniFile.INIGetStringValue(FilePath, "AGV", "IsUseAGV", "false"));  // 是否 启用AGV

+ 1 - 1
MainForm/ClassFile/XiaomiAPI_IOT/Extend/XiaomiMqttClient_OperateLog.cs

@@ -43,7 +43,7 @@ namespace MainForm.ClassFile.XiaomiAPI
                 resultStr = XiaomiMqttResponse_ErrCode.ERR_UNKOWN.ToString();
 
             string logPath = GlobalContext.MqttOperateLogDir + "OperationRecord" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
-            FileOperate.NewTxtFile(logPath, "MQTT【用户操作】提交:" + msg + "\r\n==>提交结果:" + resultStr + "");
+            FileOperate.NewTxtFile(logPath, "MQTT【操作记录】提交:" + msg + "\r\n==>提交结果:" + resultStr + "");
 
             return (result, resultStr);
         }

+ 8 - 0
MainForm/ClassFile/XiaomiAPI_MES/XiaomiMESHttp_StationInbound.cs

@@ -104,6 +104,14 @@ namespace MainForm.ClassFile.XiaomiAPI_MES
             /// </summary>
             public string unitSn { get; set; } = string.Empty;
             /// <summary>
+            /// 过站明细唯⼀标识UUID
+            /// </summary>
+            public string uuidInspection { get; set; } = string.Empty;
+            /// <summary>
+            /// 过站条件,取值:PASS或FAIL
+            /// </summary>
+            public string state { get; set; } = string.Empty;
+            /// <summary>
             /// ⽤⼾ID,如果接⼊了MES⽤⼾才需要传⼊;非必填
             /// </summary>
             public string userId { get; set; } = string.Empty;

+ 246 - 79
MainForm/FaForm/Form_Home.cs

@@ -150,6 +150,14 @@ namespace MainForm
         //XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
         XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
 
+        private int test_item_num = 0;//iot 过站数据序号
+        private string uuid = "";
+        private bool inpass = false;//保存进站测试状态
+        
+        public string _deviceCode="";//装备编码
+        public string _stationCode="";//工站ID
+        public string _workstation="";//工位编码
+
         #endregion 变量
 
         #region 窗体基础事件
@@ -181,6 +189,8 @@ namespace MainForm
                 //组建plc对象字典
                 //plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
                 //plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
+                //上传操作记录
+                operateToIot("startup","开启");
 
                 if (GlobalContext.IsUsePLC1)
                 {
@@ -354,9 +364,9 @@ namespace MainForm
                             // 配置参数
                             XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
                             // fds
-                            param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
-                            param.parameter.fds.appId = "Auto-Soft";
-                            param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
+                            param.parameter.fds.address =  GlobalContext.address;
+                            param.parameter.fds.appId =  GlobalContext.appId;
+                            param.parameter.fds.appKey =  GlobalContext.appKey;
                             // mes
                             param.parameter.mes.address = GlobalContext.ServerIp;
                             param.parameter.mes.appId = GlobalContext.MESAppId;
@@ -372,12 +382,14 @@ namespace MainForm
                             {
                                 param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
                                 param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
+                                _workstation= GlobalContext.S1_work_station;//工站
                             }
 
                             if (GlobalContext.IsUsePLC2)
                             {
                                 param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
                                 param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
+                                _workstation= GlobalContext.S2_work_station;//工站
                             }
 
                             if (GlobalContext.IsUsePLC3)
@@ -390,18 +402,21 @@ namespace MainForm
                             {
                                 param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
                                 param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
+                                _workstation= GlobalContext.s4_work_station;//工站
                             }
 
                             if (GlobalContext.IsUsePLC5)
                             {
                                 param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
                                 param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
+                                _workstation= GlobalContext.s5_work_station;//工站
                             }
 
                             if (GlobalContext.IsUsePLC6)
                             {
                                 param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
                                 param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
+                                _workstation= GlobalContext.s6_work_station;//工站
                             }
 
                             if (GlobalContext.IsUsePLC7)
@@ -414,43 +429,26 @@ namespace MainForm
                             {
                                 param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
                                 param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
+                                _workstation= GlobalContext.s8_work_station;//工站
                             }
 
                             if (GlobalContext.IsUsePLC9)
                             {
                                 param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
                                 param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
+                                _workstation= GlobalContext.s9_work_station;//工站
                             }
-
+                       
                             param.parameter.equipment.project = GlobalContext.Project_Code;
                             param.parameter.equipment.productMode = "debug";
                            
                             param.parameter.other.logLevel = 0;
                             param.parameter.other.LogPath = GlobalContext.MqttLogDir;
-
-                            //测试
-                            //param.parameter.fds.address = "http://file-cm.be.mi.com/file/x5/file/upload/mqtt";
-                            //param.parameter.fds.appId = "Auto-Soft";
-                            //param.parameter.fds.appKey = "d11ec2b9-0e7a-4086-a80c-a1ec716e0896";
-                            //param.parameter.mes.address = "cm.pre.mi.com";
-                            //param.parameter.mes.appId = "MIUAT";
-                            //param.parameter.mes.appKey = "6B3D57E2-F062-471F-932B-76C8A79E0D66";
-                            //param.parameter.mqtt.address = "staging-cnbj2-rmq-mqtt.api.xiaomi.com";
-                            //param.parameter.mqtt.port = 80;
-                            //param.parameter.mqtt.username = "AKPKTSQAS46NKE4NHY";
-                            //param.parameter.mqtt.password = "Vfr/yyxVSkCVkHFjvD2rwb3ZOoUh+75KwnfWZX3N";
-                            //param.parameter.equipment.factoryCode = "1";
-                            //param.parameter.equipment.deviceCode = "C-MBA-ADDCU-A-BZJG-0001";
-                            //param.parameter.equipment.stationCode = "Y46-ADDCU-11";
-                            //param.parameter.equipment.project = "801";
-                            //param.parameter.equipment.productMode = "debug";
-                            //param.parameter.other.logLevel = 0;
-                            //param.parameter.other.runMode = "online";
-                            //param.parameter.other.uploadDigitalTwinData = "true";
-                            //param.parameter.other.LogPath = "D:/XiaomiMqttLog";
-                            //param.parameter.other.mqttEnableService = "true";
-
+                            
                             XiaomiMqttClient_Extend.ParameterConfig(param);
+                            //保存全局变量
+                            _stationCode = param.parameter.equipment.deviceCode;
+                            _deviceCode = param.parameter.equipment.stationCode;
                         }
                         else
                         {
@@ -1374,6 +1372,7 @@ namespace MainForm
         private static bool isCollectingFlagLeft;
         private static bool isCollectingFlagRight;
         private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
+        
         /// <summary>
         /// float[]转为string
         /// </summary>
@@ -1544,7 +1543,7 @@ namespace MainForm
         /// <param name="items">进站数据</param>
         /// <returns>1成功;5MES报警;6上位机报警</returns>
         public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
-            List<TestItem> items, string MachineId, string StationId)
+            List<TestItem> items, string MachineId, string StationId,bool pass)
         {
             int result = 0;
 
@@ -1555,6 +1554,8 @@ namespace MainForm
             inRequest_Body.clientTime =
                 DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
             inRequest_Body.unitSn = sn; // 产品SN
+            inRequest_Body.uuidInspection = uuid;
+            inRequest_Body.state = pass ? "PASS" : "FAIL";
             inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
             inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
 
@@ -1630,6 +1631,36 @@ namespace MainForm
                 }
             }
 
+            #region IOT
+            string slot = "01-SLOT-01";
+            //过站结果
+            if (GlobalContext.IsMqttSendProcessData)
+            {
+                PassStationResultRequest request = new PassStationResultRequest();
+                request.project_code = GlobalContext.Project_Code;                  // 项⽬编码
+                request.factory_code = GlobalContext.Factory_Code;                  // ⼯⼚Id
+                request.process_section_code = GlobalContext.Process_Section_Code;  // ⼯段编码
+                request.line_code = GlobalContext.LineCode;                         // 线体编码
+                request.work_station = _workstation;  // ⼯站ID
+                request.device_code = _deviceCode;    // 装备编码
+                request.station = _stationCode;
+                request.process_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");  // 节拍发⽣时间(2022-06-01 14:27:57.283)
+                request.slot = slot;                  // 槽位编码
+                request.sn = sn;                      // 产品SN
+                // request.enter_status = inpass ? "PASS" : "FAIL";  // 进站状态
+                request.enter_status = pass ? "PASS" : "FAIL";  // 进站状态
+                request.result = ""; // 出站条件 PASS或FAIL;              // 过站结果
+                request.work_type = "OUT_STATION";        // 作业类型
+
+                // 上传过站结果
+                (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
+                if (iotResult.Item1 != 0)
+                {
+                    OnMessage(LogType.Info, $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}]  进站结果[{request.enter_status}]  出站结果[{request.result}]");
+                }
+            }
+            #endregion
+
             return result;
         }
 
@@ -1689,14 +1720,13 @@ namespace MainForm
             string sql = processData.ToStringInsert(upload);
             string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
             //AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
-            string uuid = "";
-            // 上传MES
+
+            #region MES
             if (GlobalContext.IsSendProcessData)
             {
                 try
                 {
                     string id = processData.ID.Copy();
-                    uuid = Guid.NewGuid().ToString();
 
                     XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
                     outRequest_Body.uuidInspection = uuid;
@@ -1761,7 +1791,6 @@ namespace MainForm
                             }
                         }
                     }
-                    
 
                     string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
 
@@ -1775,8 +1804,8 @@ namespace MainForm
                             response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
                             if (response != null && response.header.code == "200")
                             {
-                                OnMessage(LogType.Error,
-                                    "上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
+                                OnMessage(LogType.Info,
+                                    $"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
                                     JsonConvert.SerializeObject(response.body));
                                 break;
                             }
@@ -1787,7 +1816,7 @@ namespace MainForm
 
                             mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
                             // 记录失败原因
-                            OnMessage(LogType.Error, "上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
+                            OnMessage(LogType.Error, $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
                         }
 
                         if (response?.header?.code == "200")
@@ -1817,14 +1846,21 @@ namespace MainForm
                         str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
                 }
             }
+            #endregion
+
 
+            #region IOT
+            string slot = "01-SLOT-01";
+            //过站明细
             if (GlobalContext.IsMqttSendProcessData)
             {
+
+                test_item_num += 1;
                 PassStationDetailRequest request = new PassStationDetailRequest();
                 request.pass_station_id = uuid;
                 request.sn = sn;                      // 产品SN
-                request.slot = "";                  // 槽位编码
-                request.test_item_num = "1";
+                request.slot = slot;                  // 槽位编码
+                request.test_item_num = test_item_num.ToString();
                 request.function_name = "Machine_加⼯模块";
                 request.status = "PASS";
                 (int, string) iotResult = (0, "");
@@ -1834,10 +1870,10 @@ namespace MainForm
                     var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonParm);
                     foreach (var kvp in dictionary)
                     {
-                        request.test_item= kvp.Key.ToString();
+                        request.test_item = kvp.Key.ToString();
                         request.result_val = kvp.Value.ToString();
                         request.description = request.test_item;
-                        // 上传过站结果
+                        // 上传过站明细
                         iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
                         if (iotResult.Item1 != 0)
                         {
@@ -1846,6 +1882,35 @@ namespace MainForm
                     }
                 }
             }
+
+            //过站结果
+            if (GlobalContext.IsMqttSendProcessData)
+            {
+                PassStationResultRequest request = new PassStationResultRequest();
+                request.project_code = GlobalContext.Project_Code;                  // 项⽬编码
+                request.factory_code = GlobalContext.Factory_Code;                  // ⼯⼚Id
+                request.process_section_code = GlobalContext.Process_Section_Code;  // ⼯段编码
+                request.line_code = GlobalContext.LineCode;                         // 线体编码
+                request.work_station = _workstation;  // ⼯站ID
+                request.device_code = _deviceCode;    // 装备编码
+                request.station = _stationCode;
+                request.process_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");  // 节拍发⽣时间(2022-06-01 14:27:57.283)
+                request.slot = slot;                  // 槽位编码
+                request.sn = sn;                      // 产品SN
+                // request.enter_status = inpass ? "PASS" : "FAIL";  // 进站状态
+                request.enter_status = "";  // 进站状态
+                request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL;              // 过站结果
+                request.work_type = "OUT_STATION";        // 作业类型
+
+                // 上传过站结果
+                (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
+                if (iotResult.Item1 != 0)
+                {
+                    OnMessage(LogType.Info, $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}]  进站结果[{request.enter_status}]  出站结果[{request.result}]");
+                }
+            }
+            #endregion
+
             return result;
         }
 
@@ -2638,6 +2703,25 @@ namespace MainForm
             }
         }
 
+        public void operateToIot(string action, string stationNameStr)
+        {
+            OperateLogRequest request = new OperateLogRequest();
+            request.software_version = "V" + Application.ProductVersion;              // 软件版本号;如:V1.2.4
+            request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");  // 操作时间(2022-06-01 14:27:57.283)
+            request.operate_action = action;   // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
+            //request.current_process = Process.GetCurrentProcess()?.Id.ToString();  // 当前进程;进程ID
+            request.current_process = Application.ProductName;
+            request.operate_desc = stationNameStr;       // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
+            request.operate_result = "success";   // 操作结果
+            request.operator_name = "default";  // 操作账号名;填当前操作⽤⼾,如⽆则填default
+            // 上传
+            (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
+            if (iotResult.Item1 != 0)
+            {
+                AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:"+ iotResult.Item2+"操作状态:"+stationNameStr);
+            }
+        }
+
         #endregion
 
         #region S1
@@ -2727,6 +2811,7 @@ namespace MainForm
                                 {
                                     if (!ProgressState)
                                     {
+                                        uuid = Guid.NewGuid().ToString();
                                         ProgressState = true;
                                         Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
                                             tagBaseName + "." + tagMesCommName, out ProgressState));
@@ -2757,18 +2842,11 @@ namespace MainForm
                                     {
                                         ProgressState = true;
 
-                                        stPLC_MesData.mesData.nThrowCount = 1;
-                                        stPLC_MesData.mesData.fCleanAirPress = 4;
-                                        stPLC_MesData.mesData.fCleanSpeed = 2;
-                                        stPLC_MesData.mesData.fWindBladeHeight = 5;
-                                        stPLC_MesData.mesData.fCleanTime = 2;
-                                        stPLC_MesData.mesData.nCleanCount = 7;
-                                        stPLC_MesData.mesData.nRemainCount = 1;
-
                                         Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
                                             tagBaseName + "." + tagMesCommName, stationCode, stationName,
                                             out ProgressState));
                                         stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
+                                        uuid = "";
                                     }
                                 }
                             }
@@ -2878,6 +2956,8 @@ namespace MainForm
                 string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
                 string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
                 string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
+                int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
+                bool pass = a1Result == 1;
 
                 if (string.IsNullOrEmpty(sn))
                 {
@@ -2904,12 +2984,17 @@ namespace MainForm
                 stopwatch2.Start();
 
                 int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
-                    item, MachineId, StationId);
+                    item, MachineId, StationId,pass);
 
                 stopwatch2.Stop();
 
                 //指令执行结果 1:OK   110:失败
                 byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
+                if (mesResultFrmWeb==1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
+                }
 
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
@@ -2948,6 +3033,7 @@ namespace MainForm
         {
             Stopwatch stopwatch1 = new Stopwatch();
             Stopwatch stopwatch2 = new Stopwatch();
+            test_item_num = 0;//iot 过站明细序号
 
             try
             {
@@ -3013,7 +3099,11 @@ namespace MainForm
     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
 
                 byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
+                }
                 stopwatch2.Start();
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
@@ -3290,7 +3380,8 @@ namespace MainForm
                 AddMessage(LogType.Info, stationNameStr + "_进站开始");
                 string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
                 //sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
-
+                int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
+                bool pass = a1Result == 1;
                 string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
                 string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
                 string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
@@ -3313,12 +3404,16 @@ namespace MainForm
                 List<TestItem> item = new List<TestItem>();
                 stopwatch2.Start();
                 int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
-                    item, MachineId, StationId);
+                    item, MachineId, StationId,pass);
                 stopwatch2.Stop();
 
                 //指令执行结果 1:OK   110:失败
                 byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
+                }
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
                 resultToPlC.cmd = 0;
@@ -3413,7 +3508,11 @@ namespace MainForm
    , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", 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 + "_出站检测结果:FAIL");
+                }
                 stopwatch2.Start();
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
@@ -3797,6 +3896,9 @@ namespace MainForm
                 string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
                 string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
                 string StationId = string.Empty;
+                int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
+                bool pass = a1Result == 1;
+
                 if (direction == "Left")
                 {
                     StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
@@ -3823,12 +3925,16 @@ namespace MainForm
                 List<TestItem> item = new List<TestItem>();
                 stopwatch2.Start();
                 int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
-                    item, MachineId, StationId);
+                    item, MachineId, StationId,pass);
                 stopwatch2.Stop();
 
                 //指令执行结果 1:OK   110:失败
                 byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
+                }
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
                 resultToPlC.cmd = 0;
@@ -3922,17 +4028,20 @@ namespace MainForm
                     Parameter_unit = ""
                 });
 
-                int result1 = 1;
                 //if (direction == "Right")
                 //{ 
                 string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
-                result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
+                int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
    , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson, direction);
                 //}
 
 
                 byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
+                }
                 stopwatch2.Start();
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
@@ -4222,6 +4331,8 @@ namespace MainForm
                 string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
                 string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
                 string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
+                int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
+                bool pass = a1Result == 1;
                 string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
                 //载具码验证产品码 
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
@@ -4237,12 +4348,16 @@ namespace MainForm
                 List<TestItem> item = new List<TestItem>();
                 stopwatch2.Start();
                 int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
-                    item, MachineId, StationId);
+                    item, MachineId, StationId,pass);
                 stopwatch2.Stop();
 
                 //指令执行结果 1:OK   110:失败
                 byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
+                }
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
                 resultToPlC.cmd = 0;
@@ -4328,7 +4443,11 @@ namespace MainForm
    , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
 
                 byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
+                }
                 stopwatch2.Start();
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
@@ -4722,6 +4841,8 @@ namespace MainForm
                 string StationId = GlobalContext.S5_StationId;  // 工位ID(可配置)
                 string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode;  // 载具条码
                 string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
+                int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
+                bool pass = a1Result == 1;
 
                 //绑定载具和产品
                 ResponseMessage message = new ResponseMessage();
@@ -4745,12 +4866,16 @@ namespace MainForm
                 List<TestItem> item = new List<TestItem>();
                 stopwatch2.Start();
                 int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
-                    item, MachineId, StationId);
+                    item, MachineId, StationId, pass);
                 stopwatch2.Stop();
 
                 //指令执行结果 1:OK   110:失败
                 byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
+                }
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
                 resultToPlC.cmd = 0;
@@ -4838,7 +4963,11 @@ namespace MainForm
    , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", 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 + "_出站检测结果:FAIL");
+                }
                 stopwatch2.Start();
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
@@ -5239,6 +5368,8 @@ namespace MainForm
                 string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;  // 产品SN(物料码)
                 string MachineId = GlobalContext.S6_MachineId;  // 装备ID(可配置)
                 string StationId = GlobalContext.S6_StationId;  // 工位ID(可配置)
+                int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
+                bool pass = a1Result == 1;
                 string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode;  // 产品SN(物料码)
                 //strCarrierBarcode = "N801A-003";
                 //载具码验证产品码 
@@ -5274,12 +5405,16 @@ namespace MainForm
                 List<TestItem> item = new List<TestItem>();
                 stopwatch2.Start();
                 int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
-                    item, MachineId, StationId);
+                    item, MachineId, StationId, pass);
                 stopwatch2.Stop();
 
                 //指令执行结果 1:OK   110:失败
                 byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
+                }
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
                 resultToPlC.cmd = 0;
@@ -5365,7 +5500,11 @@ namespace MainForm
     , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
 
                 byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
+                }
                 stopwatch2.Start();
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
@@ -5871,6 +6010,8 @@ namespace MainForm
                 string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
                 string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
                 string StationId = string.Empty; // 工位ID(可配置)
+                int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
+                bool pass = a1Result == 1;
                 if (direction == "Left")
                 {
                     StationId = GlobalContext.S7_StationId_1;
@@ -5908,12 +6049,16 @@ namespace MainForm
                 List<TestItem> item = new List<TestItem>();
                 stopwatch2.Start();
                 int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
-                    item, MachineId, StationId);
+                    item, MachineId, StationId, pass);
                 stopwatch2.Stop();
 
                 //指令执行结果 1:OK   110:失败
                 byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
+                }
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
                 resultToPlC.cmd = 0;
@@ -6019,11 +6164,10 @@ namespace MainForm
                     Parameter_unit = ""
                 });
 
-                int result1 = 1;
                 //if (direction == "Right")
                 //{ 
                 string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
-                SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
+                int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
                     , sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
                    
                 //}
@@ -6038,7 +6182,11 @@ namespace MainForm
                 //}
 
                 byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
+                }
                 stopwatch2.Start();
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
@@ -6447,7 +6595,8 @@ namespace MainForm
         {
             Stopwatch stopwatch1 = new Stopwatch();
             Stopwatch stopwatch2 = new Stopwatch();
-
+            int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
+            bool pass = a1Result == 1;
             try
             {
                 stopwatch1.Start();
@@ -6469,12 +6618,16 @@ namespace MainForm
                 List<TestItem> item = new List<TestItem>();
                 stopwatch2.Start();
                 int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
-                    item, MachineId, StationId);
+                    item, MachineId, StationId, pass);
                 stopwatch2.Stop();
 
                 //指令执行结果 1:OK   110:失败
                 byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
+                }
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
                 resultToPlC.cmd = 0;
@@ -6560,7 +6713,11 @@ namespace MainForm
    , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
 
                 byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
+                }
                 stopwatch2.Start();
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
@@ -6951,6 +7108,8 @@ namespace MainForm
                 string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
                 string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
                 string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
+                int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
+                bool pass = a1Result == 1;
                 string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
                 //载具码验证产品码 
                 string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
@@ -6966,12 +7125,16 @@ namespace MainForm
                 List<TestItem> item = new List<TestItem>();
                 stopwatch2.Start();
                 int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
-                    item, MachineId, StationId);
+                    item, MachineId, StationId, pass);
                 stopwatch2.Stop();
 
                 //指令执行结果 1:OK   110:失败
                 byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
+                }
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();
                 resultToPlC.cmd = 0;
@@ -7058,7 +7221,11 @@ namespace MainForm
    , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
 
                 byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
-
+                if (mesResultFrmWeb == 1)
+                {
+                    mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
+                    AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
+                }
                 stopwatch2.Start();
                 //进站结果写入PLC
                 CommandFromPLC resultToPlC = new CommandFromPLC();

+ 2 - 0
MainForm/FaForm/Form_Main.cs

@@ -194,6 +194,8 @@ namespace MainForm
         /// </summary>
         private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
         {
+            Form_Home home=new Form_Home();
+            home.operateToIot("shutdown", "关闭");
             formHome.Closed2();
 
             if (GlobalContext.Save != null)