init: 北航大学BH-DAS项目首次入库

This commit is contained in:
XingCheng3
2026-06-08 17:06:10 +08:00
commit 10f06d99cd
207 changed files with 40597 additions and 0 deletions

View File

@@ -0,0 +1,409 @@
using CCYQ_JieFang;
using DeviceDriver_BasicData;
using DK_DC_Tool;
using NJ_ZC;
using OpcBasic;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using SystemFramework;
using static System.Configuration.ConfigurationManager;
namespace MesWork
{
public partial class Temp {
public static MesWorkForm mesWorkForm = null;
public static DAS_OP10 mesWorkForm1 = null;
public static DAS_OP20 mesWorkForm2 = null;
public static DAS_OP30 mesWorkForm3 = null;
public static DAS_OP40 mesWorkForm4 = null;
public static DAS_OP50 mesWorkForm5 = null;
}
public partial class MesWorkForm
{
public static string BasicDataTableFile = AppSettings["BasicDataTableFile"];
public static int IsDemoMesServer = Convert.ToInt32(AppSettings["IsDemoMesServer"]);
public static int IsWriteMonitorLog = Convert.ToInt32(AppSettings["IsWriteMonitorLog"]);
public static string ConnectionString = AppSettings["ConnectionString"];
public static string MesServer_IpPortName = AppSettings["MesServer_IpPortName"];
public static string MesServer_SendProtocol = AppSettings["MesServer_SendProtocol"];
public static string MesServer_SendTagProtocol = AppSettings["MesServer_SendTagProtocol"];
public static string MesServer_SendTagProtocol_MES = AppSettings["MesServer_SendTagProtocol_MES"];
//机床测量数据
public static string MeasureDataString = AppSettings["MeasureDataString"];
public static string ProgramDataString = AppSettings["ProgramDataString"];
public static string WebSvrUrlPort = AppSettings["WebSvrUrlPort"];
public static string ResponseEnterOrLeaveUrl = AppSettings["ResponseEnterOrLeaveUrl"];
public static string FinishCallUrl = AppSettings["FinishCallUrl"];
public static string DeviceStatusUrl = AppSettings["DeviceStatusUrl"];
public static string IPC_product = AppSettings["IPC_product"];
public static string IPC_RequestEnterOrLeave = AppSettings["IPC_RequestEnterOrLeave"];
public static string IPC_WorkFinsih = AppSettings["IPC_WorkFinsih"];
// MQTT
// public static int connectType = Convert.ToInt32(AppSettings["connectType"]);
// public static string MqttUrl = AppSettings["MqttUrl"];
// public static string MqttTargetTopic = AppSettings["MqttTargetTopic"];
public static int TimerUpdateSql = Convert.ToInt32(AppSettings["TimerUpdateSql"]);
public static int StationStatus_Interval_Read = Convert.ToInt32(AppSettings["StationStatus_Interval_Read"]);
public static int StationStatus_Interval_Update = Convert.ToInt32(AppSettings["StationStatus_Interval_Update"]);
public static int StationStatus_Interval_Insert = Convert.ToInt32(AppSettings["StationStatus_Interval_Insert"]);
public static int ExecSql_Interval = Convert.ToInt32(AppSettings["ExecSql_Interval"]);
public static string IsLogFilePath = AppSettings["IsLogFilePath"];
public static string LogFilePath = AppSettings["LogFilePath"];
public static string IpcConfigPath = AppSettings["IpcConfigPath"];
private static StreamWriter streamWriter;
/// <summary>
///
/// </summary>
public static ConcurrentQueue<ParamT> taskSql = new ConcurrentQueue<ParamT>();
/// <summary>
///
/// </summary>
public static string StationName = "DDV";
/// <summary>
///
/// </summary>
public static DataTable dt_Robot = null;
/// <summary>
///
/// </summary>
public static DataTable dt_EEM = null;
/// <summary>
///
/// </summary>
public static DataTable dt_EEM_PLC = null;
/// <summary>
///
/// </summary>
public static DataTable dt_CNC = null;
/// <summary>
///
/// </summary>
public static DataTable dt_pmc = null;
/// <summary>
///
/// </summary>
public static DataTable dt_pmc_Simplify = null;
/// <summary>
///
/// </summary>
public static DataTable dt_PLC_Data = null;
/// <summary>
///
/// </summary>
public static Hashtable ht_PLM_Old = new Hashtable();
/// <summary>
///
/// </summary>
public static Hashtable ht_PLM_Curr = new Hashtable();
/// <summary>
///
/// </summary>
public static Hashtable ht_OpName_Status = new Hashtable();
/// <summary>
///
/// </summary>
public static Hashtable ht_OpName_PMCReadTagIDArray = new Hashtable();
/// <summary>
/// 监控数据的所有变化,从这里产生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public override void OPCTagData_TagDataOnChangeMIS(object sender, CustomeEvetnArgs e)
{
ThreadPool.QueueUserWorkItem(MIS_Funtion, e);
}
public void Tighten_E_ScanContent(string hex_str, string raw_str)
{
ThreadPool.QueueUserWorkItem(MIS_Tighten, new TightenParam
{
hex = hex_str ,
raw = raw_str
});
}
/// <summary>
/// 定时触发检测PLC在线状态周期3 s
/// </summary>
/// <param name="sender"></param>
/// <param name="eState"></param>
public override void PlcStateEvent(object sender, PlcStateEvetnArgs eState)
{
}
public static string currentOpName = "";
/// <summary>
///
/// </summary>
[STAThread]
static void Main()
{
new System.Threading.Mutex(true, "Device Data SCADA", out bool bCanRun);
if (!bCanRun)
{
MessageBox.Show("设备数据采集 程序 已经在运行!不可重复启动!");
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(Temp.mesWorkForm = new MesWorkForm());
}
/// <summary>
/// 读写取方法
/// </summary>
/// <param name="readWhat"></param>
/// <param name="opOrIp"></param>
private void DemoRead(string doWhat, string opOrIp)
{
try
{
string opName = "OP1010";
object tagValue = 1;
bool result = false;
ConcurrentDictionary<string, object> tagAdrListTagFormat = null;
switch (doWhat)
{
case "TagID":
tagValue = ReadPLC("71010001");
result = WritePLC("71010001", tagValue);
break;
case "TagTypeCodeID":
tagValue = ReadPLC(10, opName);
result = WritePLC(10, opName, tagValue);
break;
//case "Cmd":
// tagValue = ReadPLC((int)EnumTagTypeCodeID.EngineID, opName);
// result = WritePLC((int)EnumTagTypeCodeID.EngineID, opName, tagValue);
// break;
case "OpAllTag"://OP所有点
tagAdrListTagFormat = ReadPLC_GroupData(opOrIp);
break;
case "OpMonitorTag"://OP监控点
tagAdrListTagFormat = ReadPLC_GroupMonitor(opOrIp);
break;
case "IpAllTag"://IP所有点
tagAdrListTagFormat = ReadPLC_IpTag(opOrIp);
break;
case "IpMonitorTag"://IP监控点
tagAdrListTagFormat = ReadPLC_IpMonitorTag(opOrIp);
break;
case "RegionRead"://按区域读取(起始地址 + 长度)
{
string tagStartAdr = "DB411.10";
ushort tagAdrListMaxLength = 100;
GetDbAndMaxLengthByOpName(opOrIp, out tagStartAdr, out tagAdrListMaxLength);
tagAdrListTagFormat = ReadQualityDataList(opOrIp, tagStartAdr, tagAdrListMaxLength);
}
break;
case "ReadBytes"://按区域读取(起始地址 + 长度)
{
string tagStartAdr = "DB411.10";
ushort tagAdrListMaxLength = 100;
var bates1 = ReadByteData_Op(opOrIp, tagStartAdr, tagAdrListMaxLength);
var bates2 = ReadByteData_Ip(opOrIp, tagStartAdr, tagAdrListMaxLength);
}
break;
case "WriteBytes"://按区域读取(起始地址 + 长度)
{
string tagStartAdr = "DB411.10";
var result1 = WritePLC_Bytes_Op(opOrIp, tagStartAdr, new byte[1024]);
var result2 = WritePLC_Bytes_Ip(opOrIp, tagStartAdr, new byte[1024]);
}
break;
default:
break;
}
//ReadByteData_Op(string opName, string startAdrr, ushort length)
foreach (System.Collections.Generic.KeyValuePair<string, object> de in tagAdrListTagFormat)//得到工位监控点哈希表
{
TagFormat TF = (TagFormat)de.Value;
string recResult = TF.OpName + " (" + TF.TagTypeCodeID + ")" + TF.TagValue.ToString(); ;
}
}
catch (System.Exception err)
{
ApplicationLog.WriteLog("listView_ShowQualityData_Init" + err);
}
}
public string Hello_You_All_Never_Know(string[] args)
{
return Guid.NewGuid().ToString()+ Guid.NewGuid().ToString();
}
private void Button1_Click(object sender, System.EventArgs e)
{
ConcurrentDictionary<string, object> tagTypeCodeIDList = DriverCache[CacheType.Cache_OpTagTypeCodeIDList];
}
public static void SavePrintLog(int type, string message)
{
try
{
if (IsLogFilePath == "0") return;
string directPath = LogFilePath.Trim();
if (!Directory.Exists(directPath)) //判断文件夹是否存在,如果不存在则创建
{
Directory.CreateDirectory(directPath);
}
directPath += string.Format(@"\{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
if (streamWriter == null)
{
streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); //判断文件是否存在如果不存在则创建,如果存在则添加。
}
streamWriter.WriteLine("***********************************************************************");
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
if (message != null)
{
if (type == 0)
{
streamWriter.WriteLine("记录信息:\r\n" + message);
}
else
{
streamWriter.WriteLine("异常信息:\r\n" + message);
}
}
}
finally
{
if (streamWriter != null)
{
streamWriter.Flush();
streamWriter.Dispose();
streamWriter = null;
}
}
}
static private void Loop()
{
while (true)
{
taskSql.TryDequeue(out ParamT tp);
if (tp != null)
{
var procedureName = tp.procedureName;
var sqlParameter = tp.sqlParameter;
DataLinkMesWork.SQLCommon.ExecuteStoredProcedure(procedureName, MesWorkForm.ConnectionString, ref sqlParameter, out string errorMessage);
if (errorMessage.Length > 0)
{
errorMessage = errorMessage.Replace("'","**");
LogRecord.LogRecord.Insert_Log(LogRecord.LogRecord.Type_Log.Alarm, errorMessage);
}
}
if (taskSql.Count < 5)
{
Thread.Sleep(15);
}
}
}
private void DatatableCol_Simplify(DataTable dt_pmc)
{
dt_pmc_Simplify = new DataTable();
dt_pmc_Simplify.Columns.Add("TagID");
dt_pmc_Simplify.Columns.Add("TagName");
dt_pmc_Simplify.Columns.Add("TagValue");
dt_pmc_Simplify.Columns.Add("工位号");
dt_pmc_Simplify.Columns.Add("数据来源");
dt_pmc_Simplify.Columns.Add("IP");
dt_pmc_Simplify.Columns.Add("TagTypeID");
dt_pmc_Simplify.Columns.Add("TagLong");
dt_pmc_Simplify.Columns.Add("DbName");
dt_pmc_Simplify.Columns.Add("变量类型");
dt_pmc_Simplify.Columns.Add("变量地址");
dt_pmc_Simplify.Columns.Add("变量其它");
dt_pmc_Simplify.Columns.Add("列位置");
dt_pmc_Simplify.Columns.Add("变量类型代码");
dt_pmc_Simplify.Columns.Add("变量类型名称");
dt_pmc_Simplify.Columns.Add("是否启用");
dt_pmc_Simplify.Columns.Add("是否监控");
var dt_pmcT = dt_pmc.Copy();
for (int i = 0; i < dt_pmcT.Rows.Count; i++)
{
var TagID = dt_pmcT.Rows[i]["TagID"].ToString();
var TagName = dt_pmcT.Rows[i]["TagName"].ToString();
var TagValue = "0";
var = dt_pmcT.Rows[i]["工位号"].ToString();
var = dt_pmcT.Rows[i]["数据来源"].ToString();
var IP = dt_pmcT.Rows[i]["IP"].ToString();
var TagTypeID = dt_pmcT.Rows[i]["TagTypeID"].ToString();
var TagLong = dt_pmcT.Rows[i]["TagLong"].ToString();
var DbName = dt_pmcT.Rows[i]["DbName"].ToString();
var = dt_pmcT.Rows[i]["变量类型"].ToString();
var = dt_pmcT.Rows[i]["变量地址"].ToString();
var = dt_pmcT.Rows[i]["变量其它"].ToString();
var = dt_pmcT.Rows[i]["列位置"].ToString();
var = dt_pmcT.Rows[i]["变量类型代码"].ToString();
var = dt_pmcT.Rows[i]["变量类型名称"].ToString();
var = dt_pmcT.Rows[i]["是否启用"].ToString();
var = dt_pmcT.Rows[i]["是否监控"].ToString();
ht_PLM_Old.Add(TagID, "0");
dt_pmc_Simplify.Rows.Add(
TagID,
TagName,
TagValue,
,
,
IP ,
TagTypeID ,
TagLong ,
DbName ,
,
,
,
,
,
,
,
);
}
}
}
}

View File

@@ -0,0 +1,268 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MesWork
{
/// <summary>
///
/// </summary>
public class B_DB_Opera
{
public static void Event_WorkStart(string opName, int tagTypeCodeID, string partType, string tagID)
{
return;
var ChangeTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
{
procedureName = "Event_WorkStart",
sqlParameter = new SqlParameter[] {
new SqlParameter("@OpName", opName),
new SqlParameter("@TagTypeCodeID", tagTypeCodeID),
new SqlParameter("@PartType", partType),
new SqlParameter("@ChangeTime",ChangeTime),
new SqlParameter("@TagID", tagID)
}
});
}
public static void Event_WorkEnd(string opName, int tagTypeCodeID, string partType
, string barCode, int qualityMask, int outCount, int duration
, string tagID)
{
return;
/*
@OpName nvarchar(50) = null,
@TagTypeCodeID int = 0,
@PartType int = 0,
@BarCode nvarchar(2048) = null,
@QualityMask int = 0,
@OutCount int = 0,
@Duration int = 0,
@ChangeTime datetime = null,
@TagID nvarchar(200) = null
*/
var ChangeTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
{
procedureName = "Event_WorkEnd",
sqlParameter = new SqlParameter[] {
new SqlParameter("@OpName", opName),
new SqlParameter("@TagTypeCodeID", tagTypeCodeID),
new SqlParameter("@PartType", partType),
new SqlParameter("@BarCode", barCode),
new SqlParameter("@QualityMask", qualityMask),
new SqlParameter("@OutCount", outCount),
new SqlParameter("@Duration", duration),
new SqlParameter("@ChangeTime",ChangeTime),
new SqlParameter("@TagID", tagID)
}
});
}
public static void Event_Signal_Log(string opName, int tagTypeCodeID, string value, string tagID)
{
return;
var ChangeTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
{
procedureName = "Event_Signal_Log",
sqlParameter = new SqlParameter[] {
new SqlParameter("@OpName", opName),
new SqlParameter("@TagTypeCodeID", tagTypeCodeID),
new SqlParameter("@Value", value),
new SqlParameter("@ChangeTime",ChangeTime),
new SqlParameter("@TagID", tagID)
}
});
}
public static void Event_Alarm_Start(string opName, int tagTypeCodeID, string alarmText, string tagID)
{
return;
var ChangeTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
{
procedureName = "Event_Alarm_Start",
sqlParameter = new SqlParameter[] {
new SqlParameter("@OpName", opName),
new SqlParameter("@TagTypeCodeID", tagTypeCodeID),
new SqlParameter("@AlarmText", alarmText),
new SqlParameter("@ChangeTime",ChangeTime),
new SqlParameter("@TagID", tagID)
}
});
}
public static void Event_Alarm_End(string opName, int tagTypeCodeID, string alarmText, string tagID)
{
return;
var ChangeTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
{
procedureName = "Event_Alarm_End",
sqlParameter = new SqlParameter[] {
new SqlParameter("@OpName", opName),
new SqlParameter("@TagTypeCodeID", tagTypeCodeID),
new SqlParameter("@AlarmText", alarmText),
new SqlParameter("@ChangeTime",ChangeTime),
new SqlParameter("@TagID", tagID)
}
});
}
//public static void MES_ToolDataSave(string opName, string toolNum, string toolLife, string toolCount)
//{
// SqlParameter[] thisParms = new SqlParameter[4];
// thisParms[0] = new SqlParameter("@opName", opName);
// thisParms[1] = new SqlParameter("@刀具代码", toolNum);
// thisParms[2] = new SqlParameter("@刀具额定寿命", Convert.ToInt32(toolLife));
// thisParms[3] = new SqlParameter("@已用寿命", Convert.ToInt32(toolCount));
// MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
// {
// procedureName = "LG_刀具管理_刀具设备台账编辑",
// sqlParameter = thisParms
// });
//}
//public static void MES_MeasureDataSave(string opName, string partId, decimal value, string time, string measureDataAddress, string monitorData)
//{
// SqlParameter[] thisParms = new SqlParameter[6];
// thisParms[0] = new SqlParameter("@opName", opName);
// thisParms[1] = new SqlParameter("@partId", partId);
// thisParms[2] = new SqlParameter("@recordTime", time);
// thisParms[3] = new SqlParameter("@Value", value);
// thisParms[4] = new SqlParameter("@measureDataAddress", measureDataAddress);
// thisParms[5] = new SqlParameter("@monitorData", monitorData);
// MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
// {
// procedureName = "LG_临工看板_质量管理_增加数据",
// sqlParameter = thisParms
// });
//}
//public static void MES_ProgramStatusDataSave(string opName, string serialNumber, int status, string time)
//{
// SqlParameter[] thisParms = new SqlParameter[4];
// thisParms[0] = new SqlParameter("@opName", opName);
// thisParms[1] = new SqlParameter("@serialNumber", serialNumber);
// thisParms[2] = new SqlParameter("@recordTime", time);
// thisParms[3] = new SqlParameter("@status", status);
// MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
// {
// procedureName = "LG_临工看板_程序状态管理_增加数据",
// sqlParameter = thisParms
// });
//}
//public static void MES_PartDataSave(string opName, string partId, string time, int type, int isOk, string FLOW_NUM, string passTime, int durationTime)
//{
// SqlParameter[] thisParms = new SqlParameter[8];
// thisParms[0] = new SqlParameter("@opName", opName);
// thisParms[1] = new SqlParameter("@partId", partId);
// thisParms[2] = new SqlParameter("@scanTime", time);
// thisParms[3] = new SqlParameter("@type", type);
// thisParms[4] = new SqlParameter("@是否合格", isOk);
// thisParms[5] = new SqlParameter("@FLOW_NUM", FLOW_NUM);
// thisParms[6] = new SqlParameter("@passTime", passTime);
// thisParms[7] = new SqlParameter("@durationTime", durationTime);
// MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
// {
// procedureName = "LG_临工看板_产量管理_增加数据",
// sqlParameter = thisParms
// });
//}
public static void MES_StatusChange(string opName, int StatusCode, string TriggerTime)
{
return;
SqlParameter[] thisParms = new SqlParameter[3];
thisParms[0] = new SqlParameter("@opName", opName);
thisParms[1] = new SqlParameter("@StatusCode", StatusCode);
thisParms[2] = new SqlParameter("@TriggerTime", TriggerTime);
MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
{
procedureName = "设备管理_状态变化新增",
sqlParameter = thisParms
});
}
//public static void MES_StatusChange_WorkModel(string opName, int shutdown, int emergency, int auto, int debug, int manual, string TriggerTime)
//{
// SqlParameter[] thisParms = new SqlParameter[7];
// thisParms[0] = new SqlParameter("@opName", opName);
// thisParms[1] = new SqlParameter("@shutdown", shutdown);
// thisParms[2] = new SqlParameter("@emergency", emergency);
// thisParms[3] = new SqlParameter("@auto", auto);
// thisParms[4] = new SqlParameter("@debug", debug);
// thisParms[5] = new SqlParameter("@manual", manual);
// thisParms[6] = new SqlParameter("@TriggerTime", TriggerTime);
// MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
// {
// procedureName = "LG_临工看板_设备管理_状态变化新增数据_工作模式",
// sqlParameter = thisParms
// });
//}
//public static void MES_MachineParamsSave(string opName, float feedRate, float spindleSpeed, string recordTime)
//{
// SqlParameter[] thisParms = new SqlParameter[4];
// thisParms[0] = new SqlParameter("@opName", opName);
// thisParms[1] = new SqlParameter("@feedRate", feedRate);
// thisParms[2] = new SqlParameter("@spindleSpeed", spindleSpeed);
// thisParms[3] = new SqlParameter("@recordTime", recordTime);
// MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
// {
// procedureName = "LG_临工看板_设备管理_增加数据",
// sqlParameter = thisParms
// });
//}
public static void ClearLog()
{
return;
MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
{
procedureName = "Event_Delete_Station_记录_日志_运行日志",
sqlParameter = new SqlParameter[] {
new SqlParameter("@工位号", "DDV")
}
});
}
public static void Exec_DispatchSql()
{
return;
MesWorkForm.taskSql.Enqueue(new NJ_ZC.ParamT
{
procedureName = "Event_Delete_部分历史数据",
sqlParameter = new SqlParameter[] {
}
});
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MesWork
{
public partial class Temp { }
public partial class MesWorkForm
{
private void Task_DispatchSql()
{
while (true)
{
try
{
B_DB_Opera.Exec_DispatchSql();
LogRecord.LogRecord.Insert_Log(LogRecord.LogRecord.Type_Log.Tip, "执行一次数据库调度【Task_DispatchSql】");
}
catch (Exception err)
{
}
Thread.Sleep(ExecSql_Interval*60*60*1000);
}
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MesWork
{
public partial class Temp { }
public partial class MesWorkForm
{
private static void Heartbeat(string opName, string tagValue)
{
if (tagValue == "1")
{
WritePLC((int)EnumTagTypeCodeID.HeartBeatMIS, opName, true);
}
else
{
WritePLC((int)EnumTagTypeCodeID.HeartBeatMIS, opName, false);
}
}
}
}

View File

@@ -0,0 +1,196 @@
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)
{ }
}
}
}

View File

@@ -0,0 +1,144 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MesWork
{
public partial class Temp { }
public partial class MesWorkForm
{
/// <summary>
/// 允许保存(针对半自动和手动压装工位)
/// </summary>
/// <param name="OpName"></param>
/// <param name="tagValue"></param>
private static void MesRead(string opName, string tagValue, int tagID)
{
if (tagValue == "1")
{
// Hashtable valueList = ReadPLC_Sync_DataList_MesRead(opName);
// long id_tagCF;
// InsertQualityDataIndex(out id_tagCF);
//InsertQualityData(id_tagCF);
//// //Insert(System.Data.DataTable dt);
}
else
{
}
}
//static public void InsertQualityDataIndex(out long id_tagCF)
//{
// string tableName;
// ParamData[] paramWhere;
// int tagID = 81010003;
// int engineTypeID = 1;
// string engineID = "TestEn0001";
// string engineType = "Type001";
// paramWhere = new ParamData[4];
// tableName = "测量数据合格索引";
// paramWhere[0].name = "TagID_CF";
// paramWhere[0].value = tagID.ToString();
// paramWhere[1].name = "EngineTypeID";
// paramWhere[1].value = engineTypeID.ToString();
// paramWhere[2].name = "EngineID";
// paramWhere[2].value = engineID.ToString();
// paramWhere[3].name = "EngineType";
// paramWhere[3].value = engineType.ToString();
// Insert(tableName, paramWhere, out id_tagCF);
//}
//static public void InsertQualityData(long id_tagCF)
//{
// int tagID = 81010003;
// int engineTypeID = 1;
// string engineID = "TestEn0001";
// string engineType = "Type001";
// string tagValue;
// int isgood = 1;
// string tableName;
// tableName = "测量数据合格";
// DataTable dt = BuildDataTables_WWW(tableName);
// object[] value = new object[10];
// tagValue = "10001";
// value[0] = id_tagCF;
// value[1] = engineTypeID;
// value[2] = engineID;
// value[3] = tagID;
// value[4] = tagValue;
// value[5] = isgood;
// value[6] = "测量位置01";
// value[7] = "测量项目01";
// value[8] = "工位号01";
// value[9] = "理论值01";
// dt.Rows.Add(value);
// tagValue = "10002";
// value[0] = id_tagCF;
// value[1] = engineTypeID;
// value[2] = engineID;
// value[3] = tagID;
// value[4] = tagValue;
// value[5] = isgood;
// value[6] = "测量位置02";
// value[7] = "测量项目02";
// value[8] = "工位号02";
// value[9] = "理论值02";
// dt.Rows.Add(value);
// Insert(dt);
//}
static public DataTable BuildDataTables_WWW(string tableName)
{
DataTable table;
DataColumnCollection columns;
table = new DataTable(tableName);
columns = table.Columns;
table.Columns.Add("Id_tagCF", typeof(System.Int32));
table.Columns.Add("EngineTypeID", typeof(System.Int32));
table.Columns.Add("EngineID", typeof(System.String));
table.Columns.Add("TagID", typeof(System.String));
table.Columns.Add("TagValue", typeof(System.String));
table.Columns.Add("IsGoodBad", typeof(System.Int32));
table.Columns.Add("测量位置", typeof(System.String));
table.Columns.Add("测量项目", typeof(System.String));
table.Columns.Add("工位号", typeof(System.String));
table.Columns.Add("理论值", typeof(System.String));
table.Columns.Add("上限值", typeof(System.String));
table.Columns.Add("下限值", typeof(System.String));
table.Columns.Add("测量单位", typeof(System.String));
table.Columns.Add("列位置", typeof(System.Int32));
table.Columns.Add("变量排序", typeof(System.Int32));
return table;
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MesWork
{
public partial class Temp { }
public partial class MesWorkForm
{
/// <summary>
/// PLC状态展示
/// </summary>
/// <param name="obj"></param>
void ShowPlcStateList(object obj)
{
OpcData.PlcStateEvetnArgs eState = (OpcData.PlcStateEvetnArgs)obj;
string ip = eState.IP.ToString();
string onState = eState.OnLine.ToString();
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MesWork
{
public partial class Temp { }
public partial class MesWorkForm
{
/// <summary>
/// 工件到位与离开时清空MES自身信号
/// </summary>
/// <param name="opName"></param>
/// <param name="tagValue"></param>
private static void WorkStart(string opName, string tagValue)
{
if (tagValue == "1")
{
}
else
{
WritePLC((int)EnumTagTypeCodeID.EngineTypeGetOverMES, opName, false);//MES传递机型5
WritePLC((int)EnumTagTypeCodeID.FixAllow, opName, false);//允许工作66
WritePLC((int)EnumTagTypeCodeID.ConfirmOkGo, opName, false);//合格放行51
WritePLC((int)EnumTagTypeCodeID.FalseGo, opName, false);//不合格放行8
WritePLC((int)EnumTagTypeCodeID.MaterialVerifyOver, opName, false);//工作完成7
WritePLC((int)EnumTagTypeCodeID.MesReadOver, opName, false);//保存完成20
}
}
}
}