ImageVerifierCode 换一换
格式:DOCX , 页数:45 ,大小:33.17KB ,
资源ID:6913648      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6913648.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Mobile GPS Reader.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Mobile GPS Reader.docx

1、Mobile GPS Reader核心类 GPSReader/ GPSReader.cs/ Copyright (C) 2003 JW Hedgehog, Inc. All rights reserved/ JW Hedgehog, Inc/ / / Direct questions to mailto:jimw/ / This code, comments and information are provided AS IS with/ no warrenty of any kind, either expressed or implied, including/ but not limit

2、ed 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

3、/ / 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

4、 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 por

5、t 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 sente

6、nce 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 intera

7、ct 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 th

8、is.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 Forms associated

9、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 th

10、e 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 t

11、he 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-char

12、acter / 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

13、 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 s

14、o 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 wa

15、y 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 Pref

16、erredReadMode 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. / * / public class GPSReader : Control / * / Constructors / * / / Default constructor / At a minimum,

17、 will need to set the PortName and BaudRate properties before calling StartRead / public GPSReader() / / Constructor - Accepts COMM port name (COMx:) / Will need to set the BaudRate properties before calling StartRead / / public GPSReader(string portName) : this() _portName = portName ; / / Construc

18、tor - 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 / / / public GPSReader(string portName, int baudRate) : this(portName) _baudRate = baudRat

19、e ; / / Constructor - verbose / Provides full control over all COMM port settings / / / / / / public GPSReader(string portName, int baudRate, ParitySetting parity, byte byteSize, StopBitsSetting stopBits) : this(portName, baudRate) _parity = parity ; _byteSize = byteSize ; _stopBits = stopBits ; / *

20、 / Events / * / / Fires each time a GPS message is received / public event GPSEventHandler OnGPSMessage ; / / Fires when the background thread begins the read process / public event EventHandler OnGPSReadStart ; / / Fires when the background thread exits the read process / public event EventHandler

21、OnGPSReadStop ; / * / Start/Stop Reading / * / / Initiate GPS Reading / Actual reading done on a background thread - this method returns immediatly / / Throws an error if either PortName or BaudRate not set / public void StartRead() / Verify that we know the port name and baud rate if (_baudRate = b

22、audRateNotSet | _portName = portNameNotSet) throw new ApplicationException( 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 = Cur

23、sors.Default ; / / 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 / public void StopRead() Cursor.Current = Cursors.WaitCursor ; _readData = false ; Thread.Sleep(500) ; / Give thread time

24、to finish any pending work ClosePort() ; Cursor.Current = Cursors.Default ; / * / Port Setup and configuration / * / / Set Port Name (COMx:) / public string PortName get return _portName ; set _portName = value ; / / Set Baud Rate - No Default / public int BaudRate get return _baudRate ; set _baudRa

25、te = value ; / / Set Port Parity - defaults to NoParity / public ParitySetting Parity get return _parity ; set _parity = value ; / / Set Port StopBits - defaults to OneStopBit / public StopBitsSetting StopBits get return _stopBits ; set _stopBits = value ; / / Set Port Byte Size (in bits) - defaults to 8 / public byte ByteSize get return _byteSize ; set _byt

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1