• 大小: 51KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: C#
  • 标签: C#  GPS  

资源简介

C#写的获取GPS信息,通过串口获取经度,纬度,海拔,还可以通过文本框实时显示GPS收到的信息。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace GPS
{
    public partial class Form1 : Form
    {
        SerialPort serialcom = new SerialPort();
        Thread thread_busy; //占线服务线程
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            String str1 = comboBox1.Text;
            try
            {
                if (str1 == null)
                {
                    MessageBox.Show(“请先选择串口!“ “Error“);
                    return;
                }

                serialcom.PortName = str1;
                serialcom.BaudRate = 9600;
                serialcom.DataBits = 8;
                serialcom.StopBits = StopBits.One;
                serialcom.Parity = Parity.None;
                if (serialcom.IsOpen == true)
                {
                    serialcom.Close();
                }

                serialcom.Open();
                MessageBox.Show(“串口打开成功!“ str1);
                button1.Enabled = false;
                comboBox1.Enabled = false;
            }
            catch (Exception er)
            {
                MessageBox.Show(“Error:“ + er.Message “Error“);
                return;
            }
            
        }

        private void button2_Click(object sender EventArgs e)
        {
            button1.Enabled = true;
            comboBox1.Enabled = true;
            serialcom.Close();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            serialcom.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
            textBox2.Text = “未定位“;
        }
         private void serialPort1_DataReceived(object sender SerialDataReceivedEventArgs e)
        {
           byte[] byteRead = new byte[serialcom.BytesToRead];
            serialcom.Read(byteRead 0 byteRead.Length);
            string strRcv = null;
       
                for (int i = 0; i < byteRead.Length; i++)
                {
                    strRcv += ((char)Convert.ToInt32(byteRead[i]));
                   
                }
                textBox1.Text += strRcv;
                this.textBox1.Focus();
                this.textBox1.Select(this.textBox1.TextLength0);
                this.textBox1.ScrollToCaret();
        }

        private void button3_Click(object sender EventArgs e)
        {
            textBox1.Clear();
        }
        private void busy()
        {
            while (true)
            {
                Invoke(new EventHandler(timer1_Tick));
            }
        }
        private void timer1_Tick(object sender EventArgs

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      14336  2014-05-19 10:31  GPS信息采集\GPS\bin\Debug\GPS.exe

     文件      30208  2014-05-19 10:31  GPS信息采集\GPS\bin\Debug\GPS.pdb

     文件      11600  2014-05-19 12:41  GPS信息采集\GPS\bin\Debug\GPS.vshost.exe

     文件        490  2010-03-17 22:39  GPS信息采集\GPS\bin\Debug\GPS.vshost.exe.manifest

     文件       6447  2014-05-19 10:31  GPS信息采集\GPS\Form1.cs

     文件      10859  2014-05-19 10:31  GPS信息采集\GPS\Form1.Designer.cs

     文件       6011  2014-05-19 10:31  GPS信息采集\GPS\Form1.resx

     文件       3665  2014-05-17 20:45  GPS信息采集\GPS\GPS.csproj

     文件       5359  2014-05-18 21:33  GPS信息采集\GPS\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6283  2014-05-19 10:31  GPS信息采集\GPS\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        738  2014-05-19 12:41  GPS信息采集\GPS\obj\x86\Debug\GPS.csproj.FileListAbsolute.txt

     文件        975  2014-05-19 10:31  GPS信息采集\GPS\obj\x86\Debug\GPS.csproj.GenerateResource.Cache

     文件       9040  2014-05-18 21:34  GPS信息采集\GPS\obj\x86\Debug\GPS.csprojResolveAssemblyReference.cache

     文件      14336  2014-05-19 10:31  GPS信息采集\GPS\obj\x86\Debug\GPS.exe

     文件        180  2014-05-19 10:31  GPS信息采集\GPS\obj\x86\Debug\GPS.Form1.resources

     文件      30208  2014-05-19 10:31  GPS信息采集\GPS\obj\x86\Debug\GPS.pdb

     文件        180  2014-05-17 20:45  GPS信息采集\GPS\obj\x86\Debug\GPS.Properties.Resources.resources

     文件        484  2014-05-17 20:28  GPS信息采集\GPS\Program.cs

     文件       1338  2014-05-17 20:28  GPS信息采集\GPS\Properties\AssemblyInfo.cs

     文件       2858  2014-05-17 20:28  GPS信息采集\GPS\Properties\Resources.Designer.cs

     文件       5612  2014-05-17 20:28  GPS信息采集\GPS\Properties\Resources.resx

     文件       1090  2014-05-17 20:28  GPS信息采集\GPS\Properties\Settings.Designer.cs

     文件        249  2014-05-17 20:28  GPS信息采集\GPS\Properties\Settings.settings

     文件        851  2014-05-17 20:28  GPS信息采集\GPS信息采集.sln

    ..A..H.     19456  2014-05-19 13:22  GPS信息采集\GPS信息采集.suo

     目录          0  2014-05-17 20:28  GPS信息采集\GPS\obj\x86\Debug\TempPE

     目录          0  2014-05-19 10:31  GPS信息采集\GPS\obj\x86\Debug

     目录          0  2014-05-17 20:46  GPS信息采集\GPS\bin\Debug

     目录          0  2014-05-17 20:28  GPS信息采集\GPS\obj\x86

     目录          0  2014-05-17 20:28  GPS信息采集\GPS\bin

............此处省略7个文件信息

评论

共有 条评论