作者tuzr (Never Stop)
看板C_Sharp
標題Re: [問題] 請問一下,要寫GPS程式是否要引用到什묠…
時間Tue May 20 16:35:35 2008
※ 引述《pat0307 (pat)》之銘言:
: 我想請問一下各位大大,我現想用C#2005寫一之程式使得mobil可以讀到GPS值
: 請問一下我要如何開啟內部的GPS,是否才可以連接GPS,之後才可以去讀GPS的值
: 目前問題就是知道開啟seriport,去接收值,但好像GPS根本沒有開啟所以收不到值,
: 請問要如何開啟
: 拜託各位大大幫忙了,謝謝。
下面是我用C# 2005寫的,目前在PC上可以運作,
惟獨有個問題不知道如何解決,就是一但開啟serial port,
GPS的訊息就會一直進來,過一陣子,記憶體就會爆增,後來buffer就會爆掉,
導致程式當掉,不知道如何解決@@"
用了serialport1.DiscardInBuffer()這個也沒用.
"至於serial port的設定,我是用C# 2005 用元件拉過去,在屬性那邊設定的"
你可以試試看這樣能不能跑.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace rs232try
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{ string gpsdata = "";
gpsdata = serialPort1.ReadLine(); //讀取GPS接收器傳來的資料
char[] delimiterChar ={ ',' }; //分割字元為","
string[] words = gpsdata.Split(delimiterChar); //以","切割資料
textBox1.Text = words[0];
textBox2.Text = words[3];
textBox3.Text = gpsdata;
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Close();
textBox1.Text = "";
textBox2.Text = "";
}
private void button3_Click(object sender, EventArgs e)
{
serialPort1.Open();
}
}
}
以上,最近才剛接觸C#,有錯煩請指出 ~
謝謝
--
凌晨和長夜天空都一樣
這裡和北極的星星 都會發光
我會永遠欣賞你 任何模樣
我會永遠喜歡你 符合心中的理想
朝著你所在那一方 是我方向... 謝霆鋒 =別來無恙=
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.32.241.163
推 windsheep:試試看把ReadLine那些寫在serialport的DataReceived事件 05/20 17:44
→ windsheep:裏看看?? 05/20 17:44