void server_ClientConnected(object sender, TcpClientConnectedEventArgs e) { try { bool PLCComm = false; bool CoderComm = false; bool RobotComm = false; IPEndPoint ClientIP = e.TcpClient.Client.RemoteEndPoint as IPEndPoint; if (ClientIP.Address.ToString() == Properties.Settings.Default.样件架PLC端) { clientPLC = e.TcpClient; PLCComm = true; } if (ClientIP.Address.ToString() == Properties.Settings.Default.拉力机PLC端) { clientCoder = e.TcpClient; CoderComm = true; } if (ClientIP.Address.ToString() == Properties.Settings.Default.Robot端) { clientRobot = e.TcpClient; RobotComm = true; } if (PLCComm && CoderComm && RobotComm) { LogRefresh(ipC.iPConfig[ClientIP.Address.ToString()] + e.TcpClient.Client.RemoteEndPoint.ToString() + " has connected.", null, dic["测试命令模式"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new Object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Communication) }); } } catch (Exception ex) { log.Exception(ex); } }
void server_DatagramReceived(object sender, TcpDatagramReceivedEventArgs <byte[]> e) { IPEndPoint ClientIP = (IPEndPoint)e.TcpClient.Client.RemoteEndPoint; LogRefresh(ipC.iPConfig[ClientIP.Address.ToString()] + " has sent messages:", CommonFunction.byteToHexString(e.Datagram), dic["测试命令模式"]); try { #region 样架PLC端 if (e.TcpClient == clientPLC) { LogRefresh(ipC.iPConfig[ClientIP.Address.ToString()] + " has sent messages:", CommonFunction.byteToHexString(e.Datagram), dic["测试命令模式"]); switch (pd.receiveCommand(e.Datagram)) { case Params.PLC2PCCommandType.Ready: dic["上夹钳闭合"] = false; dic["下夹钳闭合"] = false; dic["批次试验完成"] = false; MsgSend(clientPLC, pd.createCommand(Params.PC2PLCCommandType.Active), dic["暂停模式选择"]); tsbAdd_Click(null, null); break; case Params.PLC2PCCommandType.Operation: break; case Params.PLC2PCCommandType.DataSend: dic["上夹钳闭合"] = false; dic["下夹钳闭合"] = false; dic["批次试验完成"] = false; SampleDiameter = seDiameter.Value; SampleLength = seLength.Value; MsgSend(clientPLC, pd.createCommand(Params.PC2PLCCommandType.DataFeedBack), dic["暂停模式选择"]); break; case Params.PLC2PCCommandType.CatchSample: MsgSend(clientPLC, pd.createCommand(Params.PC2PLCCommandType.WaitKey), dic["暂停模式选择"]); if (dic["Robot就绪"] && !dic["从样件架接料并夹持"] && dic["U型架升降到位"] && !dic["批次试验完毕"]) { MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.ZQ1B), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new Object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.CatchSample) }); dic["从样件架接料并夹持"] = true; } break; case Params.PLC2PCCommandType.Complete: dic["批次试验完毕"] = true; //该批次实验完毕 break; case Params.PLC2PCCommandType.UrgencyStop: break; case Params.PLC2PCCommandType.ServoMotorError: break; case Params.PLC2PCCommandType.MeasuerRrror: break; case Params.PLC2PCCommandType.Error: LogRefresh(ipC.iPConfig[ClientIP.Address.ToString()] + e.TcpClient.Client.RemoteEndPoint.ToString() + " has sent messages: " + CommonFunction.byteToHexString(e.Datagram), " [Receive Unvalid Data!Please Check the PLC's Status]", dic["测试命令模式"]); break; case Params.PLC2PCCommandType.CoderER: dic["有急停信号"] = true; LogRefresh(ipC.iPConfig[ClientIP.Address.ToString()] + e.TcpClient.Client.RemoteEndPoint.ToString() + " has sent messages: " + CommonFunction.byteToHexString(e.Datagram), " [样件架触发急停!请检查相关设备!]", false); break; case Params.PLC2PCCommandType.DevER: dic["有急停信号"] = true; LogRefresh(ipC.iPConfig[ClientIP.Address.ToString()] + e.TcpClient.Client.RemoteEndPoint.ToString() + " has sent messages: " + CommonFunction.byteToHexString(e.Datagram), " [伺服电机触发急停!请检查相关设备!]", false); break; case Params.PLC2PCCommandType.IntrusionDetectionER: dic["有急停信号"] = true; LogRefresh(ipC.iPConfig[ClientIP.Address.ToString()] + e.TcpClient.Client.RemoteEndPoint.ToString() + " has sent messages: " + CommonFunction.byteToHexString(e.Datagram), " [入侵检测触发急停!请检查相关设备!]", false); break; case Params.PLC2PCCommandType.RobotER: dic["有急停信号"] = true; LogRefresh(ipC.iPConfig[ClientIP.Address.ToString()] + e.TcpClient.Client.RemoteEndPoint.ToString() + " has sent messages: " + CommonFunction.byteToHexString(e.Datagram), " [机器人触发急停!请检查相关设备!]", false); break; } } #endregion #region 拉力机PLC端 else if (e.TcpClient == clientCoder) { if (dic["系统开始运行"]) //系统开始运行 { ss = ma.StatusAnalysis(e); BeginInvoke(new UpdateDisplayDelegate(HeightDisplay), new object[] { ss.HeightValue.ToString() }); if (ss.HeightValue >= 1200) { MouseMovementControl(Params.MouseMovementType.ToStop, dic["暂停模式选择"]); MessageBox.Show("拉力机移动到达上限位,请确认系统状态!"); } if (dic["开始试验"] && dic["试验完毕"] && dic["拉断后U型架抬升完成"]) { if (positionFlag == 1) { MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.M1), dic["暂停模式选择"]); Thread.Sleep(1000); MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.ZQ3B), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new Object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Zq3b) }); } else if (positionFlag == 2) { MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.M2), dic["暂停模式选择"]); Thread.Sleep(1000); MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.ZQ3B), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new Object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Zq3b) }); } } if (!dic["样件上半段下料至夹取位"] && dic["开始试验"] && dic["试验完毕"] && dic["拉断后U型架抬升完成"]) //获取上升高度,命令机器人抓取 { if ((positionFlag == 1 && dic["样件下半段下料至夹取位反馈"]) || positionFlag == 3) { if (!dic["U型架正在下降"]) { if (!ss.isPlatformMoving) { MouseMovementControl(Params.MouseMovementType.ToDown, dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new Object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Down) }); } else { dic["U型架正在下降"] = true; } } for (; ss.HeightValue < 800;) { MouseMovementControl(Params.MouseMovementType.ToStop, dic["暂停模式选择"]); //tsbRead_Click(null, null); dic["U型架下降到位"] = true; break; } } if (dic["U型架下降到位"]) { if (positionFlag != 0) { if (positionFlag == 1 || positionFlag == 3) { rd.AxisValue = (ss.HeightValue - float.Parse(seZBHeight.Value.ToString())).ToString(); MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.ZBAXIS), dic["暂停模式选择"]); Thread.Sleep(1000); MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.ZQ2B), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Zq2b) }); } dic["样件上半段下料至夹取位"] = true; } else { LogRefresh("未能正确获得断裂位置!", null, dic["测试命令模式"]); MessageBox.Show("未能正确获得断裂位置!"); } } } else if (!dic["放入拉力机并返回反馈"] && !dic["拉力机准备就绪"]) //初始化 { #region 初始化逻辑修改:防止上下夹钳先后打开造成死机的情况发生,修改为先打开下夹钳,然后下降U型台,最后打开上夹钳的过程 //调整下夹钳 if (ss.isLowCaliperClamp)//下夹钳关闭 { MsgSend(clientCoder, ma.CommandAnalysis(Params.PC2CoderCommandType.LowCaliperOpen), dic["暂停模式选择"]); } if (!ss.isLowCaliperClamp) { dic["下夹钳打开"] = true;//下夹钳打开 } //调整上台高度 if ((ss.HeightValue > 805) || (ss.HeightValue < 795)) { if (dic["下夹钳打开"]) //下夹钳已打开完成 { if (ss.HeightValue > 805) //下降 { if (!dic["U型架上升命令触发"]) { if (!ss.isPlatformMoving) { MouseMovementControl(Params.MouseMovementType.ToDown, dic["暂停模式选择"]); } else { dic["U型架上升命令触发"] = true; } } } if (ss.HeightValue < 795)//上升 { if (!dic["U型架下降命令触发"]) { if (!ss.isPlatformMoving) { MouseMovementControl(Params.MouseMovementType.ToUp, dic["暂停模式选择"]); } else { dic["U型架下降命令触发"] = true; } } } } } else { MouseMovementControl(Params.MouseMovementType.ToStop, dic["暂停模式选择"]); dic["U型架升降到位"] = true; } //调整上夹钳 if (ss.isTopCaliperClamp && dic["下夹钳打开"] && dic["U型架升降到位"]) { MsgSend(clientCoder, ma.CommandAnalysis(Params.PC2CoderCommandType.TopCaliperOpen), dic["暂停模式选择"]); } if (!ss.isTopCaliperClamp) { dic["上夹钳打开"] = true; } //全部调整完毕以后,执行后续过程 if (dic["上夹钳打开"] && dic["下夹钳打开"] && dic["U型架升降到位"]) { MsgSend(clientPLC, pd.createCommand(Params.PC2PLCCommandType.CatchSampleRequest), dic["暂停模式选择"]); tsbAdd_Click(null, null); dic["拉力机准备就绪"] = true; } #endregion } else if (dic["样件架样件夹持反馈"] && !dic["拉断后U型架抬升完成"]) //机器人抓取样件完成,送入拉力机位置 { if (ss.isTopCaliperClamp) { Thread.Sleep(3000); MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.Return1), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Return1) }); } //上夹钳闭合,机器人退回 else { MsgSend(clientCoder, ma.CommandAnalysis(Params.PC2CoderCommandType.TopCaliperClamp), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.ClampClosing) }); } if (dic["放入拉力机并返回反馈"])//机器人放入完成 { if (!ss.isLowCaliperClamp) { MsgSend(clientCoder, ma.CommandAnalysis(Params.PC2CoderCommandType.LowCaliperClamp), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.ClampClosing) }); } if (ss.isLowCaliperClamp && ss.isTopCaliperClamp && !dic["开始试验"]) //开始试验 { if (Properties.Settings.Default.类别 == "1") { //试验版本 MouseMovementControl(Params.MouseMovementType.ToStart, dic["暂停模式选择"]); if (ss.isPlatformMoving) { dic["开始试验"] = true; BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Test) }); } } else { //模拟测试版本 if (!dic["开始试验"]) { MouseMovementControl(Params.MouseMovementType.ToUp, dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Test) }); } if (ss.isPlatformMoving) { dic["开始试验"] = true; if (ss.HeightValue > 830) { MouseMovementControl(Params.MouseMovementType.ToStop, dic["暂停模式选择"]); } } } } if (dic["开始试验"]) { if (ss.isPlatformMoving) { dic["U型架正在移动"] = true; } else { i++; if (i > 5) { dic["U型架移动到位并停止"] = true; } BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.TestFinished) }); } } } if (dic["放入拉力机并返回反馈"] && dic["U型架正在移动"] && dic["U型架移动到位并停止"])//机器人放入样件完成,已经移动且停止(试验完毕) { if (!dic["U型架当前高度获得"]) { V_Height = ss.HeightValue; dic["U型架当前高度获得"] = true; } dic["试验完毕"] = true; if (Properties.Settings.Default.类别 == "1") { MouseMovementControl(Params.MouseMovementType.ToSave, dic["暂停模式选择"]); Thread.Sleep(2000); tsbRead_Click(null, null); if (dic["试验数据保存完成"]) { fracturePositionResult = dt.Rows[0][53].ToString();//“需要根据数据库文件就行索引修改” switch (fracturePositionResult) { case "中间": positionFlag = 1; break; case "断于下钳口": positionFlag = 2; break; case "断于上钳口": positionFlag = 3; break; } } } dic["拉断后U型架抬升完成"] = true; } } if (dic["样件上半段下料至夹取位反馈"] && !ss.isTopCaliperClamp) //机器人取出上断裂样件后返回 { MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.Return2), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Return2) }); } if (dic["样件下半段下料至夹取位反馈"] && !ss.isLowCaliperClamp) //机器人取出下断裂样件后返回 { MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.Return3), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Return3) }); } if (dic["样件上半段夹取位到达"]) { MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.JQ1), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.JQ1) }); if (ss.isTopCaliperClamp) { Thread.Sleep(10000); MsgSend(clientCoder, ma.CommandAnalysis(Params.PC2CoderCommandType.TopCaliperOpen), dic["暂停模式选择"]); } } if (dic["样件下半段夹取位到达"]) { MsgSend(clientRobot, rd.createCommand(Params.PC2RobotCommandType.JQ2), dic["暂停模式选择"]); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.JQ2) }); if (ss.isLowCaliperClamp) { Thread.Sleep(10000); MsgSend(clientCoder, ma.CommandAnalysis(Params.PC2CoderCommandType.LowCaliperOpen), dic["暂停模式选择"]); } } } } #endregion } catch (Exception ex) { LogRefresh(ipC.iPConfig[ClientIP.Address.ToString()] + e.TcpClient.Client.RemoteEndPoint.ToString() + " has some errors:", ex.Message, dic["测试命令模式"]); } }
private void btnPause_Click(object sender, EventArgs e) { if (dic["有急停信号"]) { BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new Object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Emergency) }); } else { MsgSend(clientPLC, pd.createCommand(Params.PC2PLCCommandType.PS), false); BeginInvoke(new CheckStateControlDelegate(CheckStateControl), new Object[] { PlatformStatusClassifier.StatusClassifier(Params.ProcessName.Pause) }); } btnManual.Enabled = true; dic["暂停模式选择"] = true; if (dic["开始试验"] && !dic["U型架移动到位并停止"]) { MouseMovementControl(Params.MouseMovementType.ToStop, dic["暂停模式选择"]); } }