分享
 
 
 

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

王朝c#·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

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; // 指定用于发送和接收字符XOFF值 Tx and Rx XOFF character

public char ErrorChar; // 本字符用来代替接收到的奇偶校验发生错误时的值 error replacement character

public char EofChar; // 当没有使用二进制模式时,本字符可用来指示数据的结束 end of input character

public char EvtChar; // 当接收到此字符时,会产生一个事件 received event character

public ushort wReserved1; // 未使用 reserved; do not use

}

[StructLayout(LayoutKind.Sequential)]

private struct COMMTIMEOUTS

{

public int ReadIntervalTimeout;

public int ReadTotalTimeoutMultiplier;

public int ReadTotalTimeoutConstant;

public int WriteTotalTimeoutMultiplier;

public int WriteTotalTimeoutConstant;

}

[StructLayout(LayoutKind.Sequential)]

private struct OVERLAPPED

{

public int Internal;

public int InternalHigh;

public int Offset;

public int OffsetHigh;

public int hEvent;

}

[DllImport("coredll.dll")]

private static extern int CreateFile(

string lpFileName, // 要打开的串口名称

uint dwDesiredAccess, // 指定串口的访问方式,一般设置为可读可写方式

int dwShareMode, // 指定串口的共享模式,串口不能共享,所以设置为0

int lpSecurityAttributes, // 设置串口的安全属性,WIN9X下不支持,应设为NULL

int dwCreationDisposition, // 对于串口通信,创建方式只能为OPEN_EXISTING

int dwFlagsAndAttributes, // 指定串口属性与标志,设置为FILE_FLAG_OVERLAPPED(重叠I/O操作),指定串口以异步方式通信

int hTemplateFile // 对于串口通信必须设置为NULL

);

[DllImport("coredll.dll")]

private static extern bool GetCommState(

int hFile, //通信设备句柄

ref DCB lpDCB &

[1] [2] [3] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有