Files
2026-06-08 17:06:10 +08:00

197 lines
9.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
/// <summary>
///
/// </summary>
namespace MesWork
{
///
/// </summary>
public partial class MesWorkForm
{
/// <summary>
///
/// </summary>
/// <param name="e"></param>
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<n<590= 总时间超限;
4.按照等号拆分,取后面的值
第一组还需要按照逗号拆分
其他组按照等号拆分 TightenNG_Code
*/
// 1.去除所有空格
var str = raw.Replace(" ", "");
if (str.Contains("T0202"))
{
publicCore.LogInsert("Tighten", "Info", "【拧紧枪数据】" + raw);
str = str.Replace(";......", ";|.....");
var strFinal = str.Split('|');
for (int i = 0; i < strFinal.Length; i++)
{
string strFinalStr = strFinal[i];
if (strFinalStr.Contains("T0202"))
{
// 2.从索引10开始截取最后一位不要
str = strFinalStr.Substring(10, strFinalStr.Length - 11);
string isStartTighten = MesWorkForm.ReadPLC(56, currentOpName).ToString();
if (isStartTighten.ToLower() == "true" || isStartTighten.ToLower() == "1")
{
if (str.Length > 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);
}
}
/// <summary>
/// 处理MIS逻辑
/// </summary>
/// <param name="e"></param>
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)
{ }
}
}
}