技术开发 频道

WM下的GPS开发


【IT168技术文档】

  内置GPS: 对于通用的WM设备,我们是通过串口Com9来获得内置GPS的信息的,而一般我们打开的比特率使用的是4800

  gPort.OpenPort(“com9”, 4800)

  打开端口之后,一般我们会启用新线程进行读数据
void ReadThreadFun() { byte[] buf = new byte[512];//端口缓存大小为512 int readLength = 0; while (_isWorking) { readLength = gPort.ReadPort(buf.Length, buf); lastReport += System.Text.Encoding.ASCII.GetString(buf, 0, readLength); try { string[] reports = lastReport.Split(new char[] { '\n' }); if ((reports[reports.Length - 1].Length > 0) && (reports[reports.Length - 1][reports[reports.Length - 1].Length - 1] != '\r')) lastReport = reports[reports.Length - 1]; else lastReport = ""; for (int i = 0; i < reports.Length; i++) { if (GetGpsInfo(reports[i])) { //记录GPS的各种信息 } } catch (Exception err) { } } } }
0
相关文章