Ejemplo n.º 1
0
        private void Start_Car(object sender, MouseEventArgs e)//小车启动函数
        {
            xml_con.read();
            Redraw_Panel(route.map);
            string portName     = "";
            string portBaudrate = "";
            int    flag         = 0;

            this.alarm_list.BeginUpdate();   //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
            for (int i = 0; i < 3; i++)
            {
                switch (xml_con.data[i * 2])
                {
                case 0: portName = "COM1"; break;

                case 1: portName = "COM2"; break;

                case 2: portName = "COM3"; break;

                case 3: portName = "COM4"; break;

                case 4: portName = "COM5"; break;

                case 5: portName = "COM6"; break;

                case 6: portName = "COM7"; break;

                case 7: portName = "COM8"; break;

                case 8: portName = "COM9"; break;

                case 9: portName = "COM10"; break;
                }
                switch (xml_con.data[i * 2 + 1])
                {
                case 0: portBaudrate = "9600"; break;

                case 1: portBaudrate = "115200"; break;
                }
                switch (i)
                {
                case 0:
                    if (urg_port.OpenPort(portName, portBaudrate) == false)
                    {
                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = DateTime.Now.ToString();;
                        lvi.SubItems.Add("激光雷达串口未打开");
                        this.alarm_list.Items.Add(lvi);
                        system_light.FillColor = System.Drawing.Color.Red;
                        system_label.Text      = "系统状态:串口异常";
                        flag = 1;
                    }
                    break;

                case 1:
                    if (con_port.OpenPort(portName, portBaudrate) == false)
                    {
                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = DateTime.Now.ToString();;
                        lvi.SubItems.Add("控制串口未打开");
                        this.alarm_list.Items.Add(lvi);
                        system_light.FillColor = System.Drawing.Color.Red;
                        system_label.Text      = "系统状态:串口异常";
                        flag = 1;
                    }
                    break;

                case 2:
                    if (dr_port.OpenPort(portName, portBaudrate) == false)
                    {
                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = DateTime.Now.ToString();;
                        lvi.SubItems.Add("编码器串口未打开");
                        this.alarm_list.Items.Add(lvi);
                        system_light.FillColor = System.Drawing.Color.Red;
                        system_label.Text      = "系统状态:串口异常";
                        flag = 1;
                    }
                    break;
                }
            }
            this.alarm_list.EndUpdate();  //结束数据处理,UI界面一次性绘制。
            if (flag == 0)
            {
                //Thread goMap = new Thread(new ThreadStart(this.goAlongMap));
                //goMap.Start();

                goAlongMap();
                //goAlongMap(route.map.listLine);
                system_light.FillColor = System.Drawing.Color.Blue;
                system_label.Text      = "系统状态:正在运行";
            }
            system_light.FillColor = System.Drawing.Color.Gray;
            system_label.Text      = "系统状态:运行完成";
        }
Ejemplo n.º 2
0
        private void Collect_Route1_Click(object sender, EventArgs e)
        {
            if (Collect_Route1.Text == "获取路径信息")
            {
                Urg_Point.Visible    = true;
                Com_Point.Visible    = true;
                Delete_Point.Visible = true;
                groupBox1.Visible    = true;
                xml_con.read();
                string portName     = "";
                string portBaudrate = "";
                switch (xml_con.data[4])
                {
                case 0: portName = "COM1"; break;

                case 1: portName = "COM2"; break;

                case 2: portName = "COM3"; break;

                case 3: portName = "COM4"; break;

                case 4: portName = "COM5"; break;

                case 5: portName = "COM6"; break;

                case 6: portName = "COM7"; break;

                case 7: portName = "COM8"; break;

                case 8: portName = "COM9"; break;

                case 9: portName = "COM10"; break;
                }
                switch (xml_con.data[5])
                {
                case 0: portBaudrate = "9600"; break;

                case 1: portBaudrate = "115200"; break;
                }
                if (dr_port.OpenPort(portName, portBaudrate) == false)
                {
                    MessageBox.Show("编码器串口未能打开,请配置串口!");
                    return;
                }
                Collect_Route1.Text = "初始位置校准";
                route.map.listLine.Clear();
                route.map.listPoint.Clear();
                route.map.listFixedRect.Clear();

                dr_port.clearData();
            }
            else if (Collect_Route1.Text == "初始位置校准")
            {
                string portName     = "";
                string portBaudrate = "";
                switch (xml_con.data[2])
                {
                case 0: portName = "COM1"; break;

                case 1: portName = "COM2"; break;

                case 2: portName = "COM3"; break;

                case 3: portName = "COM4"; break;

                case 4: portName = "COM5"; break;

                case 5: portName = "COM6"; break;

                case 6: portName = "COM7"; break;

                case 7: portName = "COM8"; break;

                case 8: portName = "COM9"; break;

                case 9: portName = "COM10"; break;
                }
                switch (xml_con.data[3])
                {
                case 0: portBaudrate = "9600"; break;

                case 1: portBaudrate = "115200"; break;
                }
                if (con_port.OpenPort(portName, portBaudrate) == false)
                {
                    MessageBox.Show("控制串口未能打开,请配置串口!");
                    return;
                }
                //new CameraControl().cameraLeading(dr_port, con_port);
                Collect_Route1.Text = "结束路径信息";
                route.map.listLine.Clear();
                route.map.listPoint.Clear();
                route.map.listFixedRect.Clear();

                dr_port.clearData();
            }
            else
            {
                route.map.listLine.Clear();
                for (int i = 0; i < route.map.listPoint.Count() - 1; i++)
                {
                    Line r_line = new Line();
                    r_line.startpoint = route.map.listPoint[i];
                    r_line.endpoint   = route.map.listPoint[i + 1];
                    route.map.listLine.Add(r_line);
                }
                dr_port.ClosePort();
                con_port.ClosePort();
                Collect_Route1.Text = "获取路径信息";
                Redraw_Panel1(route.map);
            }
        }