using DK_DC_Tool; using NPOI.SS.Formula.Functions; using OpcBasic; using Robots.Commands; using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using SystemFramework; /// /// /// namespace MesWork { /// /// public partial class MesWorkForm { /// /// /// /// private void MIS_Tighten(object e) { var param = (TightenParam)e; var hex = param.hex; var raw = param.raw; try { /* . . . . . T 0 2 0 2 0 0 0 1 0 = 0 . 1 1 8 , 0 . 0 0 0 , 3 . 0 0 0 , 6 8 8 . 1 2 2 ; 0 0 0 1 1 = 2 ; 0 0 0 1 2 = 5 2 ; 0 1 0 1 0 = 0 . 0 0 0 , 0 . 0 0 0 , 0 . 0 0 0 ; 0 1 0 1 1 = 1 ; 0 1 0 2 0 = 0 . 0 0 0 , 0 . 0 0 0 , 0 . 0 0 0 ; 0 1 0 2 1 = 1 ; 0 1 0 3 0 = 0 . 0 0 0 , 0 . 0 0 0 , 0 . 0 0 0 ; 0 1 0 3 1 = 1 ; 0 1 0 4 0 = 0 . 0 0 0 , 0 . 0 0 0 , 0 . 0 0 0 ; 0 1 0 4 1 = 1 ; 0 1 0 5 0 = 0 . 1 1 8 , 6 8 8 . 1 2 2 , 2 . 9 9 9 ; 0 1 0 5 1 = 6 ; . 1.去除所有空格 .....T020200010=0.118,0.000,3.000,688.122;00011=2;00012=52;01010=0.000,0.000,0.000;01011=1;01020=0.000,0.000,0.000;01021=1;01030=0.000,0.000,0.000;01031=1;01040=0.000,0.000,0.000;01041=1;01050=0.118,688.122,2.999;01051=6;. 2.从索引10开始截取,最后一位不要 00010=0.118,0.000,3.000,688.122;00011=2;00012=52;01010=0.000,0.000,0.000;01011=1;01020=0.000,0.000,0.000;01021=1;01030=0.000,0.000,0.000;01031=1;01040=0.000,0.000,0.000;01041=1;01050=0.118,688.122,2.999;01051=6; 3.按照分号拆分,留前三组 00010=0.118,0.000,3.000,688.122 最终扭矩 ;监测角度 ;最终时间 ;最终角度 ; 00011=2 0= 无定意;1=OK,拧紧合格;2=NG,拧紧不合格; 00012=52 00= 无定意;01= 最终扭矩过大;02= 最终扭矩过大;03= 最终角度过大;04= 最终角度过小;n1= 第 n 步扭矩过大;n2= 第 n 步时间超限;1 20) { // 3.按照分号拆分,留前三组 var arr = str.Split(';'); if (arr.Length > 3) { // 无效数据 string 最终扭矩 = arr[0].Split('=')[1].Split(',')[0]; string 监测角度 = arr[0].Split('=')[1].Split(',')[1]; string 最终时间 = arr[0].Split('=')[1].Split(',')[2]; string 最终角度 = arr[0].Split('=')[1].Split(',')[3]; string isOk = arr[1].Split('=')[1]; string NG_Code = arr[2].Split('=')[1]; string NG_CodeStr = ""; if (isOk == "2") NG_CodeStr = Tighten.TightenNG_Code[NG_Code]; // 第几个孔位 int MeasurePosition = Convert.ToInt32(MesWorkForm.ReadPLC(55, currentOpName)); int partPosition = Convert.ToInt32(MesWorkForm.ReadPLC(54, currentOpName)); string IsOK = isOk; publicCore.LogInsert("Tighten", "Info", $"【保存拧紧枪数据】工件位置{partPosition},拧紧位置{MeasurePosition}" + raw); // 保存质量数 publicCore.QualityData_MobyInsert(partPosition, MeasurePosition, currentOpName, 最终扭矩, IsOK, NG_CodeStr, out string errMsg); MesWorkForm.WritePLC(83, currentOpName, true); publicCore.LogInsert(currentOpName, "Info", "【IPC_读电批完成置位】"); // 拧紧状态显示 if (MIS_Funtion_PLC_MeasureFinish != null) { MIS_Funtion_PLC_MeasureFinish(); } } } } else { if (str.Length > 20) { publicCore.LogInsert(currentOpName, "Error", "拧紧枪发送数据,但是PLC读电批值为:" + isStartTighten); } else { publicCore.LogInsert(currentOpName, "Info", "订阅拧紧枪数据!"); } } break; } } } } catch (Exception err) { publicCore.LogInsert("Tighten", "Error", "【拧紧枪数据错误】" + err); } } /// /// 处理MIS逻辑 /// /// private void MIS_Funtion(object e) { try { var msgEvent = (DeviceDriver_BasicData.CustomeEvetnArgs)e; if (msgEvent.TagValue == null) return; var tagID = msgEvent.TagID.ToString (); var opName = msgEvent.OpName.ToString(); var tagTypeCodeID = (int)msgEvent.TagTypeCodeID; var tagTypeID = (EnumTagTypeID)msgEvent.TagTypeID; // EnumTagTypeCodeID TagTypeCodeID = (EnumTagTypeCodeID)tagTypeCodeID; string tagValue; switch (tagTypeID) { case EnumTagTypeID.BOOL: tagValue = (Convert.ToInt32(msgEvent.TagValue)).ToString(); break; default: tagValue = msgEvent.TagValue.ToString(); break; } switch(opName) { // PLC心跳 case "OP10": if (DAS_OP10.MIS_Funtion_PLC_OP != null) { DAS_OP10.MIS_Funtion_PLC_OP(msgEvent); } break; case "OP20": if (DAS_OP20.MIS_Funtion_PLC_OP != null) { DAS_OP20.MIS_Funtion_PLC_OP(msgEvent); } break; case "OP30": if (DAS_OP30.MIS_Funtion_PLC_OP != null) { DAS_OP30.MIS_Funtion_PLC_OP(msgEvent); } break; case "OP40": if (DAS_OP40.MIS_Funtion_PLC_OP != null) { DAS_OP40.MIS_Funtion_PLC_OP(msgEvent); } break; case "OP50": if (DAS_OP50.MIS_Funtion_PLC_OP != null) { DAS_OP50.MIS_Funtion_PLC_OP(msgEvent); } break; } } catch (Exception err) { } } } }