예제 #1
0
            //TODO:利用电压关系直线计算

            public static List <double> cal_line(List <PointF> pts)
            {
                List <double> ret = new List <double>();

                double[] xs = new double[pts.Count];
                double[] ys = new double[pts.Count];
                for (int i = 0; i < pts.Count; i++)
                {
                    xs[i] = pts[i].X;
                    ys[i] = pts[i].Y;
                }
                var auto_line_para = LeastSquare.MultiLine(xs, ys, pts.Count, 1);

                ret.Add(auto_line_para[0]);
                ret.Add(auto_line_para[1]);
                return(ret);
            }
예제 #2
0
        static void Main(string[] args)
        {
            Client c = new Client();

            while (true)
            {
                try
                {
                    string command = Console.ReadLine();
                    if (command == "e")
                    {
                        break;
                    }
                    string[] split = command.Split(new char[] { ' ' });
                    if (split[0] == "c")
                    {
                        System.Net.IPAddress ip = System.Net.IPAddress.Parse(split[1]);
                        c.connect(ip);
                    }
                    if (split[0] == "g")
                    {
                        List <byte[]> to_send = new List <byte[]>();
                        to_send.Add(new byte[] { (byte)'G', (byte)'E', (byte)'T', (byte)'X' });
                        to_send.Add(BitConverter.GetBytes(0xff01));
                        to_send.Add(BitConverter.GetBytes(0));
                        to_send.Add(BitConverter.GetBytes(0));
                        var rev = c.send_and_receive_sync(Client.byte_connect(to_send));
                        print_rev(rev);
                    }
                    if (split[0] == "s")
                    {
                        int           x       = int.Parse(split[1]);
                        List <byte[]> to_send = new List <byte[]>();
                        to_send.Add(new byte[] { (byte)'S', (byte)'E', (byte)'T', (byte)'X' });
                        to_send.Add(BitConverter.GetBytes(0xff01));
                        to_send.Add(BitConverter.GetBytes(x));
                        to_send.Add(BitConverter.GetBytes(0));
                        var rev = c.send_and_receive_sync(Client.byte_connect(to_send));
                        print_rev(rev);
                    }
                    if (split[0] == "gx")
                    {
                        List <byte[]> to_send = new List <byte[]>();
                        to_send.Add(new byte[] { (byte)'R', (byte)'A', (byte)'W', (byte)'X' });
                        to_send.Add(BitConverter.GetBytes(0));
                        to_send.Add(BitConverter.GetBytes(0));
                        to_send.Add(BitConverter.GetBytes(0));
                        var rev = c.send_and_receive_sync(Client.byte_connect(to_send));
                        print_rev(rev);
                    }
                    if (split[0] == "pt_test")
                    {
                        double[] x2 = new double[2];
                        double[] y2 = new double[2];
                        x2[0] = double.Parse(split[1]);
                        x2[1] = double.Parse(split[2]);
                        y2[0] = double.Parse(split[3]);
                        y2[1] = double.Parse(split[4]);
                        var lsret = LeastSquare.MultiLine(x2, y2, 2, 1);
                        Console.WriteLine(lsret[0].ToString() + "  " + lsret[1].ToString());
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }