コード例 #1
0
ファイル: SecondBoard.cs プロジェクト: lyqscmy/APP439B
        public List<DopplerParameters> DopplerQuery()
        {
            List<DopplerParameters> parameters = new List<DopplerParameters>();
            try
            {
                byte[] input = new byte[1024];
                byte[] recv = new byte[1024];
                byte[] data = new byte[1024];
                int len_recv;

                //string stringRecv;
                IPAddress ip = IPAddress.Parse(ip_address);  //定义主机的IP及端口
                IPEndPoint ipEnd = new IPEndPoint(ip, port);
                Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                try
                {
                    socket.Connect(ipEnd);

                    input = commands["Stop"];
                    socket.Send(input, input.Length, SocketFlags.None);

                    len_recv = socket.Receive(recv);
                    data[0] = recv[2];  //add
                    data[1] = recv[3];  //c
                    data[2] = recv[4];  //l
                    data[3] = recv[5];  //data
                    data[4] = recv[5];  //data
                    data[5] = recv[5];  //data
                    Console.WriteLine("Echoed test = {0}", Encoding.ASCII.GetString(recv, 0, len_recv));

                    // Release the socket.
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();

                }
                catch (ArgumentNullException ane)
                {
                    Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
                }
                catch (SocketException se)
                {
                    Console.WriteLine("SocketException : {0}", se.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unexpected exception : {0}", e.ToString());
                }
                if (data[3] != CheckSum(data)) //cs
                { throw new Exception(); }

                DopplerParameters parameter = new DopplerParameters((double)data[3],
                    (double)data[4]);
                parameters.Add(parameter);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return parameters;
        }
コード例 #2
0
ファイル: MainBoard.cs プロジェクト: lyqscmy/APP439B
 public List<DopplerParameters> DopplerQuery()
 {
     Write(commands["Query"]);
     byte[] data = new byte[2];
     List<DopplerParameters> parameters = new List<DopplerParameters>();
     try
     {
         data = ReadData();
         DopplerParameters parameter = new DopplerParameters((double)data[0],
             (double)data[1]);
         parameters.Add(parameter);
     }
     catch (Exception e)
     {
         Console.WriteLine("Unexpected exception : {0}", e.ToString());
     }
     return parameters;
 }