⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpspet.cs

📁 嵌入式终端的gps定位程序
💻 CS
📖 第 1 页 / 共 3 页
字号:
            //东南
            double southeastX = (Origin.X + offset - Origin.X) * cosA + (Origin.Y + offset - Origin.Y) * sinA + Origin.X;
            double southeastY = -(Origin.X + offset - Origin.X) * sinA + (Origin.Y + offset - Origin.Y) * cosA + Origin.Y;
            label_southeast.Location = new Point(Convert.ToInt32(southeastX - label_southeast.Width * 0.5), Convert.ToInt32(southeastY - label_southeast.Height * 0.5));

            //南
            double southX = (Origin.X - Origin.X) * cosA + (Origin.Y + r + 3 + label_south.Height * 0.5 - Origin.Y) * sinA + Origin.X;
            double southY = -(Origin.X - Origin.X) * sinA + (Origin.Y + r + 3 + label_south.Height * 0.5 - Origin.Y) * cosA + Origin.Y;
            label_south.Location = new Point(Convert.ToInt32(southX - label_south.Width * 0.5), Convert.ToInt32(southY - label_south.Height * 0.5));

            //西南
            double southwestX = (Origin.X - offset - Origin.X) * cosA + (Origin.Y + offset - Origin.Y) * sinA + Origin.X;
            double southwestY = -(Origin.X - offset - Origin.X) * sinA + (Origin.Y + offset - Origin.Y) * cosA + Origin.Y;
            label_southwest.Location = new Point(Convert.ToInt32(southwestX - label_southwest.Width * 0.5), Convert.ToInt32(southwestY - label_southwest.Height * 0.5));

            //西
            double westX = (Origin.X - r - 3 - label_west.Width * 0.5 - Origin.X) * cosA + (Origin.Y - Origin.Y) * sinA + Origin.X;
            double westY = -(Origin.X - r - 3 - label_west.Width * 0.5 - Origin.X) * sinA + (Origin.Y - Origin.Y) * cosA + Origin.Y;
            label_west.Location = new Point(Convert.ToInt32(westX - label_west.Width * 0.5), Convert.ToInt32(westY - label_west.Height * 0.5));

            //西北
            double northwestX = (Origin.X - offset - Origin.X) * cosA + (Origin.Y - offset - Origin.Y) * sinA + Origin.X;
            double northwestY = -(Origin.X - offset - Origin.X) * sinA + (Origin.Y - offset - Origin.Y) * cosA + Origin.Y;
            label_northwest.Location = new Point(Convert.ToInt32(northwestX - label_northwest.Width * 0.5), Convert.ToInt32(northwestY - label_northwest.Height * 0.5));

        }

        /// <summary>
        /// 显示时间
        /// </summary>
        /// <param name="time"></param>
        private void GPS_DateTimeChanged(DateTime time)   //显示时间
        {
            label_time.Text = Convert.ToString(time);
        }

        /// <summary>
        /// 定位状态
        /// </summary>
        void GPS_CurrentState(string state)  // 定位状态
        {
            switch (state)
            {
                case "1":
                    label_state.Text = "未定位";
                    break;
                case "2":
                    label_state.Text = "二维定位";
                    break;
                case "3":
                    label_state.Text = "三维定位";
                    break;


            }
        }

        /// <summary>
        /// 定位模式
        /// </summary>
        void GPS_Mode(string mode)    // 定位模式
        {
            switch (mode)
            {
                case "A":
                    label_mode.Text = "自动";
                    break;
                case "M":
                    label_mode.Text = "手动";
                    break;
            }
        }

        /// <summary>
        /// 显示垂直精度
        /// </summary>
        /// <param name="value"></param>
        void GPS_VDOPReceived(double value)      //显示垂直精度
        {
            label_vdop.Text = Convert.ToString(value) + "米";
        }

        /// <summary>
        /// 显示水平精度
        /// </summary>
        /// <param name="value"></param>
        void GPS_HDOPReceived(double value)      //显示水平精度
        {
            label_hdop.Text = Convert.ToString(value) + "米";
        }

        /// <summary>
        /// 显示高度
        /// </summary>
        /// <param name="value"></param>
        void GPS_EllipsoidHeightReceived(double value)       //显示高度
        {
            _EllipHeight = value;
            label_height1.Text = Convert.ToString(_EllipHeight) + "米";
            label_height3.Text = Convert.ToString(_EllipHeight) + "米";
        }

        #endregion

         #region 点击按钮
        private void menu_link_Click(object sender, EventArgs e)
        {

              
            // 获取一个值,该值指示 SerialPort 对象的打开或关闭状态。
            // 如果串行端口已打开,则为 true;否则为 false。默认为 false。
            if (_ComPort.IsOpen)
            {
                //将计时器关闭并释放资源

                timer1.Enabled = false;
                timer1.Dispose();

                //关闭端口连接,将 IsOpen 属性设置为 false,并释放内部 Stream 对象。
                _ComPort.Close();
                menu_link.Text = "连接GPS设备";
            }
            else
            {
                timer1.Enabled = true;
                _ComPort.PortName = _PortName;
                _ComPort.BaudRate = _BaudRate;
                _ComPort.Open();
                menu_link.Text = "断开GPS设备连接";
                //清空轨迹文件内容
                StreamWriter sw = new StreamWriter(_TracePath, false);
                string content = null;
                sw.Write(content);
                sw.Close();

            }
        }
        private void menu_exit_Click(object sender, EventArgs e)
        {
            if (_ComPort.IsOpen)
                _ComPort.Close();

            Application.Exit();
        }
        private void menu_return_Click(object sender, EventArgs e)
        {
            panel_main.Visible = true;
            panel_position.Visible = false;
            panel_SateInView.Visible = false;
            panel_map.Visible = false;
            menu_return.Enabled = false;
            
        }
       
        private void pictureBox_sate_Click(object sender, EventArgs e)
        {
            panel_SateInView.Visible = true;
            panel_main.Visible = false;
            menu_return.Enabled = true;
        }

        private void pictureBox_trace_Click(object sender, EventArgs e)
        {
            panel_map.Visible = true;
            panel_main.Visible = false;
            menu_return.Enabled = true;
        }

        private void pictureBox_position_Click(object sender, EventArgs e)
        {
            panel_position.Visible = true;
            panel_main.Visible = false;
            menu_return.Enabled = true;
        }

        private void pictureBox_set_Click(object sender, EventArgs e)
        {
            if (_Setting == null)
                _Setting = new GpsParam(this);
            _Setting.ShowDialog();

            menu_link.Enabled = true;

            _TraceInterval = Convert.ToInt32(_Setting._TraceInterval);
            _TracePath = _Setting._TracePath;
            _ScreenInterval = Convert.ToInt32(_Setting._ScreenInterval);
            _ScreenTraceInterval = Convert.ToInt32(_Setting._ScreenTraceInterval);
            _YN = _Setting._YN;
            _BaudRate = Convert.ToInt32(_Setting._BaudRate);
            _PortName = _Setting._PortName;
            _SafeSpeedFile = _Setting._SafeSpeedFile;
            _HighSpeedFile = _Setting._HighSpeedFile;
            _OverSpeedFile = _Setting._OverSpeedFile;
            _SafeSpeed = Convert.ToInt32(_Setting._SafeSpeed);
            _HighSpeed = Convert.ToInt32(_Setting._HighSpeed);
            _OverSpeed = Convert.ToInt32(_Setting._OverSpeed);
        }
        #endregion

        #region mouse
        private void pictureBox_sate_MouseDown(object sender, MouseEventArgs e)
        {
            Bitmap button = new Bitmap("program files\\pic\\button11.png");
            pictureBox_sate.Image = (Image)button;
        }

        private void pictureBox_sate_MouseUp(object sender, MouseEventArgs e)
        {
            Bitmap button = new Bitmap("program files\\pic\\button10.png");
            pictureBox_sate.Image = (Image)button;
        }

        private void pictureBox_trace_MouseDown(object sender, MouseEventArgs e)
        {
            Bitmap button = new Bitmap("program files\\pic\\button21.png");
            pictureBox_trace.Image = (Image)button;
        }

        private void pictureBox_trace_MouseUp(object sender, MouseEventArgs e)
        {
            Bitmap button = new Bitmap("program files\\pic\\button20.png");
            pictureBox_trace.Image = (Image)button;
        }

        private void pictureBox_position_MouseDown(object sender, MouseEventArgs e)
        {
            Bitmap button = new Bitmap("program files\\pic\\button31.png");
            pictureBox_position.Image = (Image)button;
        }

        private void pictureBox_position_MouseUp(object sender, MouseEventArgs e)
        {
            Bitmap button = new Bitmap("program files\\pic\\button30.png");
            pictureBox_position.Image = (Image)button;
        }

        private void pictureBox_set_MouseDown(object sender, MouseEventArgs e)
        {
            Bitmap button = new Bitmap("program files\\pic\\button41.png");
            pictureBox_set.Image = (Image)button;
        }

        private void pictureBox_set_MouseUp(object sender, MouseEventArgs e)
        {
            Bitmap button = new Bitmap("program files\\pic\\button40.png");
            pictureBox_set.Image = (Image)button;
        }
        #endregion

        private void pictureBox_ActiveSate_Paint(object sender, PaintEventArgs e)
        {
            Point Origin = new Point((int)(pictureBox_ActiveSate.Width * 0.5), (int)(pictureBox_ActiveSate.Height * 0.5));
            Graphics g = e.Graphics;
            Pen pen1 = new Pen(Color.Red);
            g.DrawEllipse(pen1, Origin.X - 90, Origin.Y - 90, 180, 180);
            g.DrawEllipse(pen1, Origin.X - 45, Origin.Y - 45, 90, 90);
            g.DrawLine(pen1, Origin.X, Origin.Y - 100, Origin.X, Origin.Y + 100);
            g.DrawLine(pen1, Origin.X - 100, Origin.Y, Origin.X + 100, Origin.Y);
        }

       

        

        
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -