protected virtual void OnReceived(TCPEventArgs e) { if (MessageReceived != null) { MessageReceived(this, e); } }
private void AnalyzePLCMessage(object sender, TCPEventArgs e) { Debug.WriteLine(e.receivedmessage); string recStr = e.receivedmessage; recStr.Replace(" ", ""); string[] recStrArr = recStr.Split(' '); if (recStrArr[0] == "steps:") { Steps.RobotInterface = int.Parse(recStrArr[1]); Steps.WPCPreStop = int.Parse(recStrArr[2]); Steps.WPCPosing = int.Parse(recStrArr[3]); Steps.RFIDCheck = int.Parse(recStrArr[4]); Steps.PCUSBTest = int.Parse(recStrArr[5]); Steps.CameraColorTest = int.Parse(recStrArr[6]); Steps.PCCommandToRobot = int.Parse(recStrArr[7]); Steps.RobotAssemblyStep = int.Parse(recStrArr[8]); SetStatesTable(); } //throw new NotImplementedException(); }
private void Polling() { while (mark) { try { string data = Recieve(); if (data != "") { TCPEventArgs args = new TCPEventArgs(data, client); if (MessageReceived != null) { MessageReceived(this, args); } //Messages.WriteLine(data); } Thread.Sleep(20); if (isconnect != null) { isconnect(IsConnected()); } } catch (Exception ex) { //Log.WriteLog("网络循环出现错误,信息为" + ex.Message); } } }
public void AnalyzePLCMessage(Object sender, TCPEventArgs e) { string str = e.receivedmessage; if (str == "copy") { UdiskCopyTest(); } Debug.WriteLine(str); }
/// <summary> /// 数据接收委托函数 /// </summary> /// <param name="result">传入参数</param> protected void DataRec(IAsyncResult result) { if (IsOnline()) { int length = networkstream.EndRead(result); //获取接收数据的长度 List <byte> data = new List <byte>(); //新建byte数组 data.AddRange((byte[])result.AsyncState); //获取数据 data.RemoveRange(length, data.Count - length); //根据长度移除无效的数据 byte[] data2 = new byte[1000]; //重新定义接收缓冲 bool c = tcpclient.Connected; networkstream.BeginRead(data2, 0, 1000, new AsyncCallback(DataRec), data2); //重新挂起数据的接收等待 //自定义代码区域,处理数据data //for (int i = 0; i < data.Count;i++ ) //{ // Debug.WriteLine(data[i]); //} Encoding receiveEncoding_ = Encoding.UTF8; string receiveStr = receiveEncoding_.GetString((byte[])result.AsyncState, 0, length); receivedMessage = receiveStr; receivedMessageCount++; // Debug.WriteLine(receiveStr); TCPEventArgs e = new TCPEventArgs(receiveStr); OnReceived(e); if (length == 0) { //连接已经关闭 Debug.WriteLine("connection closed by server----------------"); } } else { ReConnect(); } }
public void AnalyzePLCMessage(Object sender, TCPEventArgs e) { string recStr = e.receivedmessage; string[] recStrArr = recStr.Split(' '); //Debug.WriteLine(recStr); if (recStr == "control system is available") { _PLCstate = PLCSTATE.AVAILABLE; } else if (recStr == "control system and wpc is ready") { _PLCstate = PLCSTATE.READY; } else if (recStr == "control system is busy") { _PLCstate = PLCSTATE.BUSY; } else if (recStrArr[0] == "result:") { int taskResult = 0; int checkRejectReason = 0; int.TryParse(recStrArr[1], out taskResult); int.TryParse(recStrArr[2], out checkRejectReason); if (CurrentMESTask.Force == 0) { if (taskResult == 1) { TaskInfo.TaskResult = TASKRESULT.GOOD; } else { TaskInfo.TaskResult = TASKRESULT.NOTGOOD; } TaskInfo.RejectReason = (REJECTREASON)checkRejectReason; } else if (CurrentMESTask.Force == 1) { TaskInfo.TaskResult = TASKRESULT.GOOD; TaskInfo.RejectReason = (REJECTREASON)0; } else if (CurrentMESTask.Force == 2) { TaskInfo.TaskResult = TASKRESULT.NOTGOOD; TaskInfo.RejectReason = (REJECTREASON)REJECTREASON.ForceNG; } else { Messages.WriteLine("Force Value Error Input"); } TaskInfo.PQCFilePath = recStrArr[3]; Debug.WriteLine("taskresult is :" + TaskInfo.TaskResult.ToString()); Debug.WriteLine("rejectreason is :" + TaskInfo.RejectReason.ToString()); Debug.WriteLine(recStr); } // Debug.WriteLine("anastate: "+ _PLCstate.ToString()); eventWait.Set(); // Debug.WriteLine(recStr); }
public void AnalyzePLCMessage(Object sender, TCPEventArgs e) { PCCameraTcp.Send(e.receivedmessage); Messages.WriteLine("PLC To PC Camera" + e.receivedmessage); }
private void AnalyzePCCameraMessage(object sender, TCPEventArgs e) { PLCTcp.Send(e.receivedmessage); Messages.WriteLine("PC Camera to PLC" + e.receivedmessage); }