用C#读取GPS数据的基类,适用于wince操作系统

using System;
using System.Runtime.InteropServices;
using System.Text;

namespace BaseStationPDA
{
 class GPS
 {

  public string PortNum;
  public int BaudRate;
  public byte ByteSize;
  public byte Parity; // 0-4=no,odd,even,mark,space
  public byte StopBits; // 0,1,2 = 1, 1.5, 2
  public int ReadTimeout;
  
  //comm port win32 file handle
  private int hComm = -1;
  
  public bool Opened = false;
  
  //win32 api constants
  private const uint GENERIC_READ = 0x80000000;
  private const uint GENERIC_WRITE = 0x40000000;
  private const int OPEN_EXISTING = 3;  
  private const int INVALID_HANDLE_VALUE = -1;
  
  [StructLayout(LayoutKind.Sequential)]
   public struct DCB
  {
   //taken from c struct in platform sdk
   public int DCBlength;           // sizeof(DCB)
   public int BaudRate;            // 指定当前波特率 current baud rate
   // these are the c struct bit fields, bit twiddle flag to set
   public int fBinary;          // 指定是否允许二进制模式,在windows95中必须主TRUE binary mode, no EOF check
   public int fParity;          // 指定是否允许奇偶校验 enable parity checking
   public int fOutxCtsFlow;      // 指定CTS是否用于检测发送控制,当为TRUE是CTS为OFF,发送将被挂起。 CTS output flow control
   public int fOutxDsrFlow;      // 指定CTS是否用于检测发送控制 DSR output flow control
   public int fDtrControl;       // DTR_CONTROL_DISABLE值将DTR置为OFF, DTR_CONTROL_ENABLE值将DTR置为ON, DTR_CONTROL_HANDSHAKE允许DTR"握手" DTR flow control type
   public int fDsrSensitivity;   // 当该值为TRUE时DSR为OFF时接收的字节被忽略 DSR sensitivity
   public int fTXContinueOnXoff; // 指定当接收缓冲区已满,并且驱动程序已经发送出XoffChar字符时发送是否停止。TRUE时,在接收缓冲区接收到缓冲区已满的字节XoffLim且驱动程序已经发送出XoffChar字符中止接收字节之后,发送继续进行。 FALSE时,在接收缓冲区接收到代表缓冲区已空的字节XonChar且驱动程序已经发送出恢复发送的XonChar之后,发送继续进行。XOFF continues Tx
   public int fOutX;          // TRUE时,接收到XoffChar之后便停止发送接收到XonChar之后将重新开始 XON/XOFF out flow control
   public int fInX;           // TRUE时,接收缓冲区接收到代表缓冲区满的XoffLim之后,XoffChar发送出去接收缓冲区接收到代表缓冲区空的XonLim之后,XonChar发送出去 XON/XOFF in flow control
   public int fErrorChar;     // 该值为TRUE且fParity为TRUE时,用ErrorChar 成员指定的字符代替奇偶校验错误的接收字符 enable error replacement
   public int fNull;          // eTRUE时,接收时去掉空(0值)字节 enable null stripping
   public int fRtsControl;     // RTS flow control
   /*RTS_CONTROL_DISABLE时,RTS置为OFF
            RTS_CONTROL_ENABLE时, RTS置为ON
            RTS_CONTROL_HANDSHAKE时,
            当接收缓冲区小于半满时RTS为ON
             当接收缓冲区超过四分之三满时RTS为OFF
            RTS_CONTROL_TOGGLE时,
            当接收缓冲区仍有剩余字节时RTS为ON ,否则缺省为OFF*/

   public int fAbortOnError;   // TRUE时,有错误发生时中止读和写操作 abort on error
   public int fDummy2;        // 未使用 reserved
   
   public uint flags;
   public ushort wReserved;          // 未使用,必须为0 not currently used
   public ushort XonLim;             // 指定在XON字符发送这前接收缓冲区中可允许的最小字节数 transmit XON threshold
   public ushort XoffLim;            // 指定在XOFF字符发送这前接收缓冲区中可允许的最小字节数 transmit XOFF threshold
   public byte ByteSize;           // 指定端口当前使用的数据位 number of bits/byte, 4-8
   public byte Parity;             // 指定端口当前使用的奇偶校验方法,可能为:EVENPARITY,MARKPARITY,NOPARITY,ODDPARITY  0-4=no,odd,even,mark,space
   public byte StopBits;           // 指定端口当前使用的停止位数,可能为:ONESTOPBIT,ONE5STOPBITS,TWOSTOPBITS  0,1,2 = 1, 1.5, 2
   public char XonChar;            // 指定用于发送和接收字符XON的值 Tx and Rx XON character
   public char XoffChar;           // 指定用于发

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值