/// <summary> /// 接收数据接口 /// </summary> public void ReceiveData() { radarsystem.udpSocket.StructDemo struct_df = new radarsystem.udpSocket.StructDemo(); int port = 10000; IPAddress HostIP = IPAddress.Parse("127.0.0.1"); IPEndPoint host; int trail_type; while (PortInUse(port)) { port++; } while (checkBox_udpSocket.Checked == true) { host = new IPEndPoint(HostIP, port); UdpClient udpClient = new UdpClient(host); try { Byte[] receiveBytes = udpClient.Receive(ref host); struct_df = (radarsystem.udpSocket.StructDemo)radarsystem.udpSocket. ByteToStruct(receiveBytes, typeof(radarsystem.udpSocket.StructDemo)); if (struct_df.scsmhead.unit_flag != 0x76) continue; if (!arr_tar.Contains(struct_df.srcTgtTrk.nType.ToString())) arr_tar.Add(struct_df.srcTgtTrk.nType.ToString()); Point point = new Point(); point.X = (int)struct_df.srcTgtTrk.dLat; point.Y = (int)struct_df.srcTgtTrk.dLon; list_trace_update[arr_tar.IndexOf(struct_df.srcTgtTrk.nType.ToString())].Add(point); drawtrace_update(); udpClient.Close(); } catch (Exception e) { MessageBox.Show(e.ToString()); } } }
private void sendData(Double X, Double Y) { if (checkBox_udpSocket.Checked == true) //udp报文复选框选中,且此时雷达扫描到该目标 //返回数据给发送端,//即数据发送模块 { radarsystem.udpSocket.StructDemo structSend = new radarsystem.udpSocket.StructDemo(); structSend.srcTgtTrk.dLat = (float)X; structSend.srcTgtTrk.dLon = (float)Y; int port = 11000; IPAddress HostIP = IPAddress.Parse("127.0.0.1"); IPEndPoint host; host = new IPEndPoint(HostIP, port); UdpClient udpClient = new UdpClient(host); byte[] bytes = radarsystem.udpSocket.StructToBytes(structSend, 264); udpClient.Send(bytes, bytes.Length, host); udpClient.Close(); } }