public static bool CheckCode(byte[] dataReceived, IAssistant assistant) { if (dataReceived[5] == 224) { if (dataReceived[18] != 4) { assistant.DataToSend = COTPConnectionPacket.ConnectionConfirmLoad(dataReceived).ToArray(); return(true); } else { assistant.DataToSend = new byte[] { 3, 0, 0, 33, 2, 240, 128, 50, 7, 0, 0, 193, 2, 0, 12, 0, 4, 0, 1, 18, 8, 18, 131, 0, 0, 0, 0, 210, 9, 10, 0, 0, 0 }; return(true); } } else if (dataReceived[5] == 240) { if (S7PacketGenerator.Check(dataReceived)) { assistant.DataToSend = S7PacketGenerator.GetDataToSend().ToArray(); return(true); } } return(false); }
public static void client_DataReceived(object sender, Hardware.CommunicationModule.DataReceivedEventArgs e) { Assistant assistant = new Assistant(); Socket client = sender as Socket; assistant.SomethingToSend = false; assistant.SomethingToReceive = true; Hardware.CommunicationModule.DataReceivedEventArgs courier = e as Hardware.CommunicationModule.DataReceivedEventArgs; byte[] dataReceived = courier.RcvInfo.Data; int dataLength = courier.RcvInfo.Count; if (dataLength != 7) { assistant.SomethingToSend = S7Packet.CheckCode(dataReceived, assistant); assistant.SomethingToReceive = !(S7PacketGenerator.requestDiagData || S7PacketGenerator.requestDownload); } else { if (S7PacketGenerator.requestDownload) { assistant.SomethingToSend = true; assistant.DataToSend = S7PacketGenerator.DownloadBlock().ToArray(); S7PacketGenerator.requestDownload = false; } else if (S7PacketGenerator.requestDiagData) { assistant.SomethingToSend = true; assistant.DataToSend = S7PacketGenerator.PushRequestDiagData().ToArray(); S7PacketGenerator.requestDiagData = false; S7PacketGenerator.lockedAccessToDiagData = false; } else { assistant.SomethingToSend = false; } } bool somethingToSend = assistant.SomethingToSend; bool somethingToReceive = assistant.SomethingToReceive; if (somethingToSend) { string str = ""; for (int i = 0; i < assistant.DataToSend.Length; i++) { str += assistant.DataToSend[i] + ","; } System.Diagnostics.Debug.WriteLine(str); courier.FeedBack.SetFeedback(new Hardware.CommunicationModule.SendInfo(somethingToSend, somethingToReceive, assistant.DataToSend)); } else { courier.FeedBack.SetFeedback(new Hardware.CommunicationModule.SendInfo(somethingToSend, somethingToReceive)); } }