/// <summary> /// 监听下位机状态 /// </summary> public void ListenSatue() { while (true) { if (ModbusRead(GlobalVar.gl_SolenoidvalveSignal) == "1")//判断气缸到位,1表示到位 { if (GlobalVar.gl_TestComplete) { GlobalVar.gl_TestPcsCount = (int.Parse(GlobalVar.gl_TestPcsCount) + 1).ToString(); GlobalVar.gl_TestComplete = false; CommLogDisplay("气缸到位", MsgType.RcvMsg); string[] arrylist = new string[3]; arrylist[0] = "0"; arrylist[1] = "0"; arrylist[2] = "6"; RefleshResultView(arrylist);//清除显示 Thread.Sleep(100); MyFunctions.SendMessage(GlobalVar.gl_IntPtr_MainWindow, GlobalVar.WM_StartTest, (IntPtr)0, (IntPtr)0); Thread.Sleep(2000); GlobalVar.gl_TestComplete = true; //CommLogDisplay("标志位复位", MsgType.RcvMsg); } else { Thread.Sleep(2000); } } Thread.Sleep(100); } }
protected override void WndProc(ref Message m) { switch (m.Msg) { case GlobalVar.WM_StartTest: //开始测试 ClearFlag(); flowLayoutPanel1.VerticalScroll.Value = 0; Thread.Sleep(50); Thread th_Starttest = new Thread(StartTest); th_Starttest.IsBackground = true; th_Starttest.Start(); break; case GlobalVar.WM_ResultPass: //接收到测试结果OK ModBusSend("E10", GlobalVar.gl_CompleteTest); //发送OK结果 GlobalVar.gl_TestPcsPassCount = (int.Parse(GlobalVar.gl_TestPcsPassCount) + 1).ToString(); myfunction.writelog("发送OK结果"); CommLogDisplay("发送OK结果", MsgType.SendMsg); break; case GlobalVar.WM_ResultFail: //接收到测试结果NG ModBusSend("E11", GlobalVar.gl_CompleteTest); //发送NG结果 GlobalVar.gl_TestPcsFailCount = (int.Parse(GlobalVar.gl_TestPcsFailCount) + 1).ToString(); myfunction.writelog("发送NG结果"); CommLogDisplay("发送NG结果", MsgType.SendMsg); break; case GlobalVar.WM_RemoveControl: flowLayoutPanel1.Controls.RemoveByKey(GlobalVar.gl_ControlName); MyFunctions.SendMessage(GlobalVar.gl_IntPtr_MainWindow, GlobalVar.WM_RenamControl, (IntPtr)0, (IntPtr)0); break; case GlobalVar.WM_RenamControl: int i = 0; foreach (SetParamer num in flowLayoutPanel1.Controls.OfType <SetParamer>()) { num.Name = "Number" + i; i++; } break; default: break; } base.WndProc(ref m); }
private void btn_StarTest_Click(object sender, EventArgs e) { MyFunctions.SendMessage(GlobalVar.gl_IntPtr_MainWindow, GlobalVar.WM_StartTest, (IntPtr)0, (IntPtr)0); }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { MyFunctions.SendMessage(GlobalVar.gl_IntPtr_MainWindow, GlobalVar.WM_RemoveControl, (IntPtr)0, (IntPtr)0); }