namespace MesWork { using CCYQ_JieFang; using DK_DC_Tool; using MQTTnet.Server; using Robots; using System; using System.Data; using System.Diagnostics; using System.IO; using System.Net; using System.Threading; using System.Windows.Forms; using SystemFramework; public partial class MesWorkForm { InitServer initServer = null; /// /// 测量完成委托 /// public static Action MIS_Funtion_PLC_MeasureFinish = null; /// /// /// public MesWorkForm() { InitializeComponent(); CheckForIllegalCrossThreadCalls = false; currentOpName = File.ReadAllText(IpcConfigPath).ToString(); Never_Know.Hello_You_All_Never_Know = Hello_You_All_Never_Know; publicCore.LogInsert(currentOpName, "Info", "开启程序!"); ThreadPool.SetMaxThreads(2000, 800); LoadOPCData(MesWorkForm.BasicDataTableFile, MesWorkForm.IsDemoMesServer, MesWorkForm.IsWriteMonitorLog, false, false, out string err); if (err.Length > 0) { MessageBox.Show($"LoadOPCData报错:{err}"); Process.GetCurrentProcess().Kill(); } switch (currentOpName) { case "OP10": { Temp.mesWorkForm1 = new DAS_OP10(currentOpName); Temp.mesWorkForm1.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮) Temp.mesWorkForm1.TopLevel = false; //指示子窗体非顶级窗体 Temp.mesWorkForm1.Dock = DockStyle.Fill;//将窗体最大化填充 panel_Page.Controls.Add(Temp.mesWorkForm1); Temp.mesWorkForm1.Show(); Temp.mesWorkForm1.Load -= OpFormLoad; Temp.mesWorkForm1.Load += OpFormLoad; } break; case "OP20": Temp.mesWorkForm2 = new DAS_OP20(currentOpName); Temp.mesWorkForm2.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮) Temp.mesWorkForm2.TopLevel = false; //指示子窗体非顶级窗体 Temp.mesWorkForm2.Dock = DockStyle.Fill;//将窗体最大化填充 panel_Page.Controls.Add(Temp.mesWorkForm2); Temp.mesWorkForm2.Show(); Temp.mesWorkForm2.Load -= OpFormLoad; Temp.mesWorkForm2.Load += OpFormLoad; break; case "OP30": Temp.mesWorkForm3 = new DAS_OP30(currentOpName); Temp.mesWorkForm3.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮) Temp.mesWorkForm3.TopLevel = false; //指示子窗体非顶级窗体 Temp.mesWorkForm3.Dock = DockStyle.Fill;//将窗体最大化填充 panel_Page.Controls.Add(Temp.mesWorkForm3); Temp.mesWorkForm3.Show(); Temp.mesWorkForm3.Load -= OpFormLoad; Temp.mesWorkForm3.Load += OpFormLoad; break; case "OP40": Temp.mesWorkForm4 = new DAS_OP40(currentOpName); Temp.mesWorkForm4.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮) Temp.mesWorkForm4.TopLevel = false; //指示子窗体非顶级窗体 Temp.mesWorkForm4.Dock = DockStyle.Fill;//将窗体最大化填充 panel_Page.Controls.Add(Temp.mesWorkForm4); Temp.mesWorkForm4.Show(); Temp.mesWorkForm4.Load -= OpFormLoad; Temp.mesWorkForm4.Load += OpFormLoad; break; case "OP50": Temp.mesWorkForm5 = new DAS_OP50(currentOpName); Temp.mesWorkForm5.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮) Temp.mesWorkForm5.TopLevel = false; //指示子窗体非顶级窗体 Temp.mesWorkForm5.Dock = DockStyle.Fill;//将窗体最大化填充 panel_Page.Controls.Add(Temp.mesWorkForm5); Temp.mesWorkForm5.Show(); Temp.mesWorkForm5.Load -= OpFormLoad; Temp.mesWorkForm5.Load += OpFormLoad; break; default: MessageBox.Show("未找到对应工位!"); break; } } private void OpFormLoad(object sender, EventArgs e) { // 开启PLC监控 StartServer(); // 开启webApi initServer = new InitServer(MesWorkForm.WebSvrUrlPort); Tighten.E_LogInsert -= publicCore.LogInsert; Tighten.E_LogInsert += publicCore.LogInsert; Tighten.E_ScanContent -= Tighten_E_ScanContent; Tighten.E_ScanContent += Tighten_E_ScanContent; //string hex_str = ""; //string raw_str = " . . . . . A 0 2 0 4 A C K . . . . . Z T 0 2 0 4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 0 , 0 . 0 0 0 , 0 . 0 0 0 ; 0 1 0 4 1 = 1 ; 0 1 0 5 0 = 0 . 0 0 0 , 0 . 0 0 0 , 0 . 0 0 0 ; 0 1 0 5 1 = 1 ; . "; //// string raw_str = " . . . . . T 0 2 0 2 0 0 0 1 0 = 0 . 1 0 1 , 0 . 0 0 0 , 1 . 7 5 9 , 3 4 1 5 . 9 7 4 ; 0 0 0 1 1 = 2 ; 0 0 0 1 2 = 0 2 ; 0 1 0 1 0 = 0 . 1 6 7 , - 1 8 0 . 4 8 2 , 0 . 3 5 8 ; 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 . 1 0 1 , 3 5 9 7 . 0 2 9 , 1 . 3 6 9 ; 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 . 0 0 0 , 0 . 0 0 0 , 0 . 0 0 0 ; 0 1 0 5 1 = 1 ; ."; //Tighten.E_ScanContent.Invoke(hex_str, raw_str); var dt_Tighten = NPOITest.ExeclHelper.ExcelToDataTable(BasicDataTableFile, "拧紧枪", true); //OpName IP Port IsEnable var dataTable = dt_Tighten.Select($"OpName='{currentOpName}' and IsEnable='1'"); if(dataTable.Length > 0) { dt_Tighten = dt_Tighten.Select($"OpName='{currentOpName}' and IsEnable='1'").CopyToDataTable(); if (dt_Tighten.Rows.Count > 0) { var IP = dt_Tighten.Rows[0]["IP"].ToString(); var Port = Convert.ToInt32(dt_Tighten.Rows[0]["Port"]); var tighten = new Tighten(); tighten.Start(IP, Port, currentOpName); } } } private void MesWorkForm_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e) { if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { publicCore.LogInsert(currentOpName, "Info", "退出程序!"); e.Cancel = false; StopServer(2000); Thread.Sleep(500); System.Diagnostics.Process.GetCurrentProcess().Kill(); } else { e.Cancel = true; } } private void label_ExitSys_Click(object sender, EventArgs e) { if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { CloseDeviceConn(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } } private void MesWorkForm_Load(object sender, EventArgs e) { } private void ToolStripMenuItem_exit_Click(object sender, EventArgs e) { if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { StopServer(2000); Thread.Sleep(500); System.Diagnostics.Process.GetCurrentProcess().Kill(); } } private void pLC监控ToolStripMenuItem_Click(object sender, EventArgs e) { new OpcForm(IsDemoMesServer).Show(this); } private void 关于ToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("关于信息!"); } private void 系统日志ToolStripMenuItem_Click(object sender, EventArgs e) { new logInfo(currentOpName).Show(this); } private void 查询ToolStripMenuItem_Click(object sender, EventArgs e) { new partInfo(currentOpName).Show(this); } private void aGV调试ToolStripMenuItem_Click(object sender, EventArgs e) { new AgvTest(currentOpName).Show(this); } private void 上下限设置ToolStripMenuItem1_Click(object sender, EventArgs e) { new MeasureRangeSet(currentOpName).Show(this); } private void button1_Click(object sender, EventArgs e) { if (MessageBox.Show("是否确认跳过本次拧紧?\r\n仅适用于上位机拧紧确认失败的操作", "拧紧确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { MesWorkForm.WritePLC(83, currentOpName, true); MessageBox.Show("操作完成!"); } } } }