亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? gpsreader.cs

?? 在wince下接收gps的數(shù)據(jù)
?? CS
?? 第 1 頁 / 共 3 頁
字號:
// GPSReader.cs
//
// Copyright (C) 2003 JW Hedgehog, Inc.  All rights reserved
//
// JW Hedgehog, Inc
// http://www.jwhh.com
// 
// Direct questions to mailto:jimw@jwhh.com
// 
// This code, comments and information are provided "AS IS" with
// no warrenty of any kind, either expressed or implied, including
// but not limited to the implied warranties of merchentability and/or
// fitness for a particular purpose
// ---------------------------------------------------------------------

using System;
using System.Data;
using System.Windows.Forms ;
using System.Runtime.InteropServices ;
using System.Text ;
using System.Collections ;
using System.Threading ;
using System.IO ;

namespace GPSExample.Util
{

	/// <summary>
	/// Class that manages the GPS reading process.
	/// 
	/// To get started using the class do the following
	/// 1) Construct GPSReader passing the port name and baud rate of the GPS device
	///		C#: GPSReader gps = new GPSReader("COM4:", 4800) ;
	///		VB: Dim WithEvents gps As New GPSReader("COM4:", 4800)
	///	2) Handle the OnGPSMessage event
	///		This event will fire each time the GPS sends an update
	///	3) Call gps.StartRead()
	///		Launches the GPS reading process on a background thread
	///		
	/// Use the StartRead and StopRead methods to control the GPS reading process.  Before calling 
	/// StartRead you must provide at least the port name in the form "COMx" (x is the port number) and
	/// the baud rate.  You can do this using either a constructor or the PortName and BaudRate properties.
	/// Each time a GPS message is received, the OnGPSMessage event will fire passing an instance of the 
	/// GPSEventArgs class containing the raw GPS sentence along with some of the values already parsed into
	/// read-only fields.
	/// 
	/// This class does the actual GPS reading work on a background thread.  The individual OnGPSMessage events
	/// are raised in a UI thread safe manner so no special handling is required.  Because it is considered unsafe
	/// to interact with UI elements (TextBox, ListBox, etc.) from a thread other then the thread on which they were
	/// created, the GPS reader thread raises the OnGPSMessage event on the UI thread.  These is acheived by deriving 
	/// the GPSReader class from Control and then using the inherited Invoke method.  Calling this.Invoke causes the 
	/// event to be raised on the same thread on which the GPSReader was created.  Since the GPSReader is usually 
	/// created as a member of either a Form or a method on a Form, it is safe to assume that the GPSReader was
	/// created on the same thread as the Form and the Form's associated UI elements.
	/// 
	/// Because there can sometimes be a short delay between when StartRead/StopRead are called and when the 
	/// action actually occurs on the background thread, OnGPSStartRead and OnGPSStopRead events are provided.  
	/// Each fires when the background thread actually performs the action.  Like the OnGPSMessage event, 
	/// these are raised in a UI thread safe manner.
	/// 
	/// To support the broadest number of GPS devices, the class actually supports two different read modes.
	/// The preferred read mode is "MesssageMode".  In MessageMode, we let the COMM port driver monitor the 
	/// GPS stream watching for the arrival of the carriage-return (\n).  Our code blocks until the COMM port
	/// driver notifies us of the carriage-return, at which time we then go read the entire GPS sentence from 
	/// the COMM port driver.
	/// The alternative read mode is "CharacterMode".  In CharacterMode we read the data character-by-character
	/// from the COMM port driver manually building the GPS sentence and watching for the carriage-return.  This
	/// mode was added because experimentation showed that some GPS devices that simulate COMM ports(i.e. the GPS
	/// might be an expansion pack of compact flash card but appears as a COMM port to the device) do not 
	/// support letting the COMM port driver monitor for the carriage-return.
	/// Using the PreferredReadMode property, you can set which mode the GPSReader uses  If you choose MessageMode
	/// or Auto (the default) The GPSReader class tests to see if the driver supports MessageMode and if so use it.
	/// Otherwise it will downgrade to CharacterMode.  The ActiveReadMode property indicates which read mode is 
	/// actually being used.
	/// The code that tests for MessageMode support is in the "DriverSupportsMessageMode method.  Because its not 
	/// possible to test every GPS in existence there is no way to be 100% sure that this test will always work but 
	/// on the devices tested it has been reliable. 
	/// ***************************************************************************************************************
	///        Note                                         ***********************************************************
	/// If you try reading from a device and the GPSReader never returns any data, the cause may be that MessageMode
	/// support has been falsly indicated as supported.  Setting the GPSReader PreferredReadMode to ReadMode.Character 
	/// should over come the problem.  The need to do this has never been observered but since its not possible to test
	/// every GPS device the possibility always exists.
	/// ***************************************************************************************************************
	/// </summary>
	public class GPSReader : Control
	{
		// *************************************************************
		//   Constructors
		// *************************************************************

		/// <summary>
		/// Default constructor
		/// At a minimum, will need to set the PortName and BaudRate properties before calling StartRead 
		/// </summary>
		public GPSReader()
		{
		}

		/// <summary>
		/// Constructor - Accepts COMM port name (COMx:)
		///  Will need to set the BaudRate properties before calling StartRead
		/// </summary>
		/// <param name="portName"></param>
		public GPSReader(string portName)
			: this()
		{
			_portName = portName ;
		}

		/// <summary>
		/// Constructor - Accepts COMM port name (COMx:) and BaudRate
		///  If default COMM port settings (NoParity, 8 bits/byte and OneStopBit) are acceptable,
		///  can call StartRead without setting any of the configuration properties
		/// </summary>
		/// <param name="portName"></param>
		/// <param name="baudRate"></param>
		public GPSReader(string portName, int baudRate)
			: this(portName)
		{
			_baudRate = baudRate ;
		}

		/// <summary>
		/// Constructor - verbose
		/// Provides full control over all COMM port settings
		/// </summary>
		/// <param name="portName"></param>
		/// <param name="baudRate"></param>
		/// <param name="parity"></param>
		/// <param name="byteSize"></param>
		/// <param name="stopBits"></param>
		public GPSReader(string portName, int baudRate, ParitySetting parity, byte byteSize, StopBitsSetting stopBits)
			: this(portName, baudRate)
		{
			_parity = parity ;
			_byteSize = byteSize ;
			_stopBits = stopBits ;
		}

		// *************************************************************
		//   Events
		// *************************************************************

		/// <summary>
		/// Fires each time a GPS message is received
		/// </summary>
		public event GPSEventHandler OnGPSMessage ;

		/// <summary>
		/// Fires when the background thread begins the read process
		/// </summary>
		public event EventHandler OnGPSReadStart ;

		/// <summary>
		/// Fires when the background thread exits the read process
		/// </summary>
		public event EventHandler OnGPSReadStop ;

		// *************************************************************
		//   Start/Stop Reading
		// *************************************************************

		/// <summary>
		/// Initiate GPS Reading 
		///  Actual reading done on a background thread - this method returns immediatly
		///
		/// Throws an error if either PortName or BaudRate not set
		/// </summary>
		public void StartRead()
		{
			// Verify that we know the port name and baud rate
			if (_baudRate == baudRateNotSet || _portName == portNameNotSet)
				throw new ApplicationException("<GPSReader> Must set Baud Rate & Port Name before opening the port") ;

			Cursor.Current = Cursors.WaitCursor ;
			_readData = true ;

			_gpsReadThread = new Thread(new ThreadStart(this.GPSReadLoop)) ;
			_gpsReadThread.Start() ;
			Cursor.Current = Cursors.Default ;
		}

		/// <summary>
		/// Terminate GPS Reading
		/// Sets _readData to false which exits the underlying read loop
		///  Also closes the COMM port which aborts any pending COMM port operations
		/// </summary>
		public void StopRead()
		{
			Cursor.Current = Cursors.WaitCursor ;
			_readData = false ;
			Thread.Sleep(500) ;		// Give thread time to finish any pending work

			ClosePort() ;
			Cursor.Current = Cursors.Default ;
		}

		// *************************************************************
		//   Port Setup and configuration
		// *************************************************************

		/// <summary>
		/// Set Port Name (COMx:)
		/// </summary>
		public string PortName
		{
			get { return _portName ;}
			set {_portName = value ;}
		}

		/// <summary>
		/// Set Baud Rate - No Default 
		/// </summary>
		public int BaudRate
		{
			get { return _baudRate ;}
			set {_baudRate = value ;}
		}

		/// <summary>
		/// Set Port Parity - defaults to NoParity
		/// </summary>
		public ParitySetting Parity
		{
			get { return _parity ;}
			set {_parity = value ;}
		}

		/// <summary>
		/// Set Port StopBits - defaults to OneStopBit 
		/// </summary>
		public StopBitsSetting StopBits
		{
			get { return _stopBits ;}
			set {_stopBits = value ;}
		}

		/// <summary>
		/// Set Port Byte Size (in bits) - defaults to 8
		/// </summary>
		public byte ByteSize
		{
			get { return _byteSize ;}
			set {_byteSize = value ;}
		}

		// *************************************************************
		//   Port Reading
		// *************************************************************

		/// <summary>
		/// Main Read Loop
		/// After openning the COMM Port, repeatedly retrieves a GPS sentence.
		///  If the sentence appears correct (starts with $GP) the GPSMessage event is fired
		/// If an exception should occur, the COMM Port is closed and the exception is propagated
		/// </summary>
		private void GPSReadLoop()
		{
			EventHandler GPSMessageHandler   = new EventHandler(this.DispatchGPSMessage) ;
			EventHandler GPSReadStartHandler = new EventHandler(this.DispatchGPSReadStart) ;
			EventHandler GPSReadStopHandler  = new EventHandler(this.DispatchGPSReadStop) ;

			OpenPort() ;

			// Signal beginning of read process - event fired on UI thread
			this.Invoke(GPSReadStartHandler) ;

			try
			{
				gpsSentence = ReadSentence() ;
				while (gpsSentence != null)	// will only be null if StopRead() is called
				{
					// If appears to be valid message, Signal GPS Message received - event fired on UI thread
					// Invoke blocks this thread until the method wrapped by the GPSMessageHandler returns.
					//  If this code is ever changed to an asynchronous method of execution then the gpsSentence
					//  variable will have to be protected against simultaneous access.
					if (gpsSentence.StartsWith("$GP"))
						this.Invoke(GPSMessageHandler) ; 

					gpsSentence = ReadSentence() ;
				}
			}
			catch (Exception e)
			{   // If any exception is thrown, close the COMM port and propagate the exception
				ClosePort() ;
				throw e ;
			}
			// Signal end of read process - event fired on UI thread
			this.Invoke(GPSReadStopHandler) ;

		}

		/// <summary>
		/// Handoff to the appopriate ReadSentence based on active ReadMode
		/// </summary>
		/// <returns>GPS Sentence</returns>
		private string ReadSentence()
		{
			string returnVal = string.Empty ;
			if (_activeReadMode == ReadMode.Message)
				returnVal = ReadSentence_Message() ;
			else
				returnVal = ReadSentence_Character() ;
			return returnVal ;
		}

		/// <summary>
		/// Retrieves the sentence and translates from ASCII to Unicode
		/// </summary>
		/// <returns>GPS Sentence</returns>
		private string ReadSentence_Message()
		{
			Byte[] buffer;
			Byte[] temp = new Byte[1] ;
			int numBytesRead = 0 ;
			Encoding asciiConverter = Encoding.ASCII ;

			// keep reading until we are told to stop or we get something 
			//  looped read should only occur if read errors are encountered
			bool portReturnedData = ReadPort_Message(MAX_MESSAGE, out buffer, out numBytesRead) ;
			while (_readData && ! portReturnedData)
				portReturnedData = ReadPort_Message(MAX_MESSAGE, out buffer, out numBytesRead) ;

			// if still reading, Translate from ASCII to Unicode
			return _readData ? asciiConverter.GetString(buffer, 0, numBytesRead) : null ;
		}

		/// <summary>
		/// Builds the sentence by doing single character reads then translates from ASCII to Unicode
		/// Additional code is used to adjust whether translation starts at the beginning of the string
		/// or skips the first character.  This had to be added because one of the GPS simulators we were
		/// using would send an extra character after the carriage-return (\n).
		/// </summary>
		/// <returns>GPS Sentence</returns>
		public string ReadSentence_Character()
		{
			Byte[] data = new Byte[MAX_MESSAGE] ;
			Byte temp = 0 ;
			int pos = 0 ;
			Encoding asciiConverter = Encoding.ASCII ;

			// Build the sentence until carriage-return encountered
			while(_readData && temp != endOfGPSSentenceMarker) 
			{
				temp = ReadPort_Character() ;
				data[pos++] = temp ;
			} 
			
			// Translation adjustment to handle extra character sent by some simulation programs
			int translateStartPos = 0 ;
			int translateCount = pos ;
			if (data[0] != (Byte) '$')
			{
				translateStartPos++ ;
				translateCount-- ;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩亚洲欧美一区二区三区| 日韩西西人体444www| 国产乱码精品一区二区三区av | 国产精品欧美经典| 欧美日韩成人在线一区| 97久久超碰国产精品| 国内欧美视频一区二区| 日韩精品国产精品| 一区二区三区影院| 亚洲欧洲精品一区二区三区不卡| 久久中文字幕电影| 欧美一级xxx| 91精品国产福利| 欧美精品v日韩精品v韩国精品v| 一本一道久久a久久精品综合蜜臀| 成人性生交大片免费看在线播放| 国产永久精品大片wwwapp| 午夜精品aaa| 综合久久给合久久狠狠狠97色| 国产精品沙发午睡系列990531| 久久久影院官网| 欧美精品一区二区在线观看| 精品国产一区二区三区忘忧草| 日韩一区二区电影在线| 日韩欧美在线影院| 精品久久人人做人人爽| 精品免费国产二区三区 | 国产女人aaa级久久久级| 欧美精品一区二区三区蜜桃视频| 26uuu欧美| 日本一区二区三区高清不卡| 中文字幕av资源一区| 麻豆成人久久精品二区三区红 | 国产麻豆成人精品| 国产麻豆成人精品| 成人久久视频在线观看| 国产精品综合久久| 国产美女av一区二区三区| 成人性色生活片免费看爆迷你毛片| 成年人网站91| 北条麻妃一区二区三区| 99riav一区二区三区| 在线视频一区二区三区| 欧美美女直播网站| 精品免费视频.| 国产精品人成在线观看免费| 中文字幕在线观看不卡视频| 一区二区三区精品| 天堂久久一区二区三区| 久久精品国产999大香线蕉| 国产成人夜色高潮福利影视| 99久久久无码国产精品| 欧美日韩精品一区二区三区| 日韩欧美黄色影院| 国产亲近乱来精品视频| 国产精品免费丝袜| 亚洲第一久久影院| 国产真实乱偷精品视频免| 成人黄色软件下载| 欧美日韩国产综合视频在线观看| 精品福利一区二区三区| 1024国产精品| 欧美aa在线视频| 成人精品视频一区二区三区| 欧美日韩国产综合视频在线观看| 国产亚洲综合色| 亚洲超碰精品一区二区| 国产乱码精品一区二区三区五月婷| 9l国产精品久久久久麻豆| 欧美亚洲国产一区在线观看网站| 日韩美女一区二区三区| 亚洲日本乱码在线观看| 午夜视频在线观看一区| 国产成人av电影在线观看| 在线观看免费一区| 久久午夜色播影院免费高清 | 午夜影院在线观看欧美| 日本中文字幕一区二区视频| 伦理电影国产精品| 色婷婷av一区二区三区大白胸 | 国产视频在线观看一区二区三区| 亚洲一区影音先锋| 国产99久久久精品| 欧美日韩在线播放一区| 国产精品日韩成人| 日本欧洲一区二区| 国模一区二区三区白浆| 欧美日精品一区视频| 中文字幕电影一区| 理论电影国产精品| 欧美性受xxxx| 亚洲人午夜精品天堂一二香蕉| 国产麻豆精品在线| 91精品国产高清一区二区三区| 尤物在线观看一区| 国产成人精品亚洲777人妖| 欧美一区日韩一区| 亚洲国产欧美在线人成| 成人黄色av电影| 国产亚洲一区二区三区四区 | 国产精品全国免费观看高清| 麻豆91在线播放免费| 欧美日韩国产色站一区二区三区| 亚洲欧洲精品一区二区三区不卡| 国产一区二区三区在线观看免费视频 | 三级一区在线视频先锋| 色综合中文综合网| 国产成人小视频| 欧美日韩日日骚| 中文字幕五月欧美| 国产福利视频一区二区三区| 欧美大片拔萝卜| 亚洲成人资源在线| 欧美亚洲动漫制服丝袜| 亚洲乱码国产乱码精品精可以看| 不卡一区二区三区四区| 久久精品一区二区三区不卡牛牛| 国产麻豆精品theporn| 精品国产91乱码一区二区三区| 麻豆视频观看网址久久| 欧美日韩一区二区电影| 亚洲一二三四久久| 欧美性xxxxx极品少妇| 亚洲欧美日韩国产成人精品影院| 丁香桃色午夜亚洲一区二区三区| 日本一区二区三区免费乱视频| 国产精品中文字幕日韩精品| 国产亚洲精品免费| 国产激情精品久久久第一区二区| 久久久不卡网国产精品二区| 国产精品1024| 亚洲国产精品v| 国产成人精品午夜视频免费| 337p粉嫩大胆噜噜噜噜噜91av| 国产一区二区三区香蕉| 日本一区二区不卡视频| 99国产精品久久久久久久久久 | 国产麻豆午夜三级精品| 欧美一级夜夜爽| 狠狠色狠狠色综合系列| 久久久久国色av免费看影院| 成人午夜伦理影院| 亚洲精品国产精品乱码不99| 欧美日韩中文一区| 秋霞午夜鲁丝一区二区老狼| 精品久久久久久无| 成人精品小蝌蚪| 亚洲亚洲人成综合网络| 91精品蜜臀在线一区尤物| 国产在线播放一区二区三区| 日韩一区二区在线播放| 色综合久久中文综合久久牛| 午夜精品久久久久久久99水蜜桃| 欧美不卡在线视频| www.日韩精品| 日日夜夜精品视频免费| 亚洲国产精品t66y| 欧美日韩高清一区二区| 国产精品一区二区免费不卡| 一区二区三区欧美视频| 精品国产一区二区三区四区四| 91在线观看视频| 伦理电影国产精品| 亚洲乱码一区二区三区在线观看| 日韩欧美高清一区| 色综合激情五月| 国产乱码精品一区二区三区忘忧草 | 91麻豆免费视频| 激情另类小说区图片区视频区| 亚洲一区二区视频在线观看| 国产欧美一区二区三区网站| 91精品国产色综合久久不卡蜜臀 | 中文子幕无线码一区tr| 欧美日韩一区二区三区视频| 粉嫩av一区二区三区| 日本不卡一区二区| 中文字幕一区av| 精品99一区二区三区| 欧美日本乱大交xxxxx| 99久久er热在这里只有精品15| 国内久久婷婷综合| 免费成人你懂的| 天堂精品中文字幕在线| 依依成人精品视频| 1024精品合集| 中文文精品字幕一区二区| 在线不卡a资源高清| 一本色道a无线码一区v| 成人永久aaa| 国产成人av在线影院| 免费看欧美女人艹b| 亚洲午夜影视影院在线观看| 亚洲欧美另类久久久精品2019| 亚洲国产成人在线| 欧美精品一区二区精品网| 51精品国自产在线| 欧美日韩一区二区三区视频| 欧美视频在线播放| 欧美性色黄大片| 欧美色图激情小说|