java获取gps 串口_从串口读取GPS数据

2023-05-16

网上找来的代码自己修改之后放到这里的。

参考地址:

http://www.pcppc.cn/kaifa/VBjiaocheng/kaifa_18010.html

http://www.itqoo.com/programme/ASPNET/200609/1489.html

http://topic.csdn.net/t/20060812/21/4945572.html

http://bbs.pdafans.com/viewthread.php?tid=154187

Imports System.Runtime.InteropServices

Public Class Form1

Private StrInfo As String = ""

Private StrX As String = ""

Private StrY As String = ""

Public Class dcb

Friend DCBlength As UInt32

Friend BaudRate As UInt32

Friend fBinary As UInt32

Friend fParity As UInt32

Friend fOutxCtsFlow As UInt32

Friend fOutxDsrFlow As UInt32

Friend fDtrControl As UInt32

Friend fDsrSensitivity As UInt32

Friend fTXContinueOnXoff As UInt32

Friend fOutX As UInt32

Friend fInX As UInt32

Friend fErrorChar As UInt32

Friend fNull As UInt32

Friend fRtsControl As UInt32

Friend fAbortOnError As UInt32

Friend fDummy2 As UInt32

Friend wReserved As UInt32

Friend XonLim As UInt32

Friend XoffLim As UInt32

Friend ByteSize As Byte

Friend Parity As Byte

Friend StopBits As Byte

Friend XonChar As Char

Friend XoffChar As Char

Friend ErrorChar As Char

Friend EofChar As Char

Friend EvtChar As Char

Friend wReserved1 As UInt16

End Class

_

Private Shared Function CreateFile _

(ByVal lpFileName As String, _

ByVal dwDesiredAccess As Integer, _

ByVal dwShareMode As Integer, _

ByVal lpSecurityAttributes As Integer, _

ByVal dwCreationDisposition As Integer, _

ByVal dwFlagAndAttributes As Integer, _

ByVal hTemplateFile As Integer) As Integer

End Function

_

Private Shared Function GetCommState _

(ByVal hFile As Integer, _

ByVal mdcb As dcb) As Integer

End Function

_

Private Shared Function SetCommState _

(ByVal hFile As Integer, _

ByVal mdcb As dcb) As Integer

End Function

_

Private Shared Function ReadFile _

(ByVal hFile As Integer, _

ByVal Buffer() As Byte, _

ByVal nNumberOfBytesToRead As Integer, _

ByRef lpNumberOfBytesRead As Integer, _

ByRef lpOverlapped As Integer) As Integer

End Function

_

Private Shared Function WriteFile _

(ByVal hFile As Integer, _

ByVal Buffer() As Byte, _

ByVal nNumberOfBytesToWrite As Integer, _

ByRef lpNumberOfBytesWritten As Integer, _

ByVal lpOverlapped As Integer) As Boolean

End Function

_

Private Shared Function CloseHandle _

(ByVal hObject As Integer) As Integer

End Function

Dim inoutfileHandler As Long

Dim numReadWrite As Integer

Dim t1 As System.Threading.Thread

Dim stopThread As Boolean = False

Dim pdcb As New dcb

Public Sub openPort()

Dim ioPort As Short = 4

inoutfileHandler = CreateFile("COM" & ioPort & ":", &HC0000000, 0, 0, 3, 0, 0)

'设置波特率

GetCommState(inoutfileHandler, pdcb)

pdcb.BaudRate.Parse("4800")

SetCommState(inoutfileHandler, pdcb)

stopThread = False

t1 = New Threading.Thread(AddressOf receiveLoop)

t1.Start()

End Sub

Public Sub receiveLoop()

Dim inbuff(300) As Byte

Dim retCode As Integer = ReadFile _

(inoutfileHandler, _

inbuff, _

inbuff.Length, _

numReadWrite, _

0)

Application.DoEvents()

While True

If retCode = 0 Or stopThread Then

Exit While

Else

Dim updateDelegate As New myDelegate(AddressOf displayReceivedMessage)

updateDelegate.Invoke _

(byteArrayToString(inbuff))

ReDim inbuff(300)

retCode = ReadFile(inoutfileHandler, inbuff, inbuff.Length, numReadWrite, 0)

Application.DoEvents()

End If

End While

End Sub

Function byteArrayToString(ByVal b() As Byte) As String

Dim str As String

Dim enc As System.Text.ASCIIEncoding

enc = New System.Text.ASCIIEncoding

str = enc.GetString(b, 0, b.Length())

Return str

End Function

Public Delegate Sub myDelegate(ByVal str As String)

Public Sub displayReceivedMessage(ByVal str As String)

If str.Length > 0 Then

'MessageBox.Show(str)

'MessageBox.Show(GetGPS(str, "X") & " " & GetGPS(str, "Y"))

StrInfo = StrInfo + str

StrX = GetGPS(str, "X")

StrY = GetGPS(str, "Y")

If StrX <> "" And StrX <> "-1" And StrX <> "V" Then

MessageBox.Show("成功获得数据 经度" & StrX & " 纬度" & StrY)

stopThread = True

CloseHandle(inoutfileHandler)

End If

End If

End Sub

Private Sub MnuOpenPort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuOpenPort.Click

Call openPort()

End Sub

Private Sub MnuShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuShow.Click

TxtInfo.Text = StrInfo

TxtGPS.Text = StrX & " " & StrY

End Sub

Private Sub MnuClosePort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuClosePort.Click

stopThread = True

CloseHandle(inoutfileHandler)

End Sub

Private Function GetGPS(ByVal sGpsStr As String, ByVal sFindStr As String)

Dim HanderStr As String = "$GPRMC" 'GPS串头

Dim FindHander As Integer = sGpsStr.IndexOf(HanderStr)

If FindHander < 0 Then

Return "-1"

Else

sGpsStr = sGpsStr.Substring(FindHander, sGpsStr.Length - FindHander)

Dim ArryTmp() As String = sGpsStr.Split(",")

Try

If ArryTmp(2) = "V" Then

Return "V" '信号不好

Else

Select Case sFindStr

Case "X"    '返回经度

Return DM2DD(ArryTmp(5))

Case "Y"    '返回纬度

Return DM2DD(ArryTmp(3))

Case "T"

Return ArryTmp(9) & " " & ArryTmp(1)

Case "V"

Return Convert.ToString(Convert.ToDouble(ArryTmp(7)) * 1.852)

End Select

End If

Catch ex As Exception

Return "V"

End Try

End If

End Function

Public Function DM2DD(ByVal DegreeMinutes As String) As String

'转换NMEA协议的“度分”格式为十进制“度度”格式

Dim sDegree As String

Dim sMinute As String

Dim sReturn As String = ""

If DegreeMinutes.IndexOf(".") = 4 Then

DegreeMinutes = DegreeMinutes.Replace(".", "")

Dim sDegree1 As Double = Convert.ToDouble(DegreeMinutes.Substring(0, 2))

Dim sDegree2 As Double = Convert.ToDouble(DegreeMinutes.Substring(2, DegreeMinutes.Length - 2))

Dim sTmp As String = Convert.ToString(sDegree2 / 60)

sDegree2 = Convert.ToDouble(sTmp.Substring(0, sTmp.Length))

sDegree2 = sDegree2 / 10000

sDegree = Convert.ToString(sDegree1 + sDegree2)

If (sDegree.Length > 11) Then

sDegree = sDegree.Substring(0, 11)

End If

sReturn = sDegree

ElseIf DegreeMinutes.IndexOf(".") = 5 Then

DegreeMinutes = DegreeMinutes.Replace(".", "")

Dim sMinute1 As Double = Convert.ToDouble(DegreeMinutes.Substring(0, 3))

Dim sMinute2 As Double = Convert.ToDouble(DegreeMinutes.Substring(3, DegreeMinutes.Length - 2))

Dim sTmp As String = Convert.ToString(sMinute2 / 60)

sMinute2 = Convert.ToDouble(sTmp.Substring(0, sTmp.Length))

sMinute2 = sMinute2 / 10000

sMinute = Convert.ToString(sMinute1 + sMinute2)

If sMinute.Length > 10 Then

sMinute = sMinute.Substring(0, 10)

sReturn = sMinute

End If

End If

Return sReturn

End Function

End Class

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java获取gps 串口_从串口读取GPS数据 的相关文章

随机推荐

  • 51单片机串口通信原理

    计算机串行通信基础 通信有串行通信和并行通信两种方式 串行通信 xff1a 将数据字节分为一位一位的形式在一条数据线上逐个传送 如下图所示 串行通信特点 xff1a 传输线少 xff0c 长距离传送时成本低 xff0c 且可以利用电话网等现
  • C++中涉及到类继承,构造函数和析构函数执行的顺序,以及虚函数在其中的作用

    一 构造函数与析构函数在对象创建与删除时的执行顺序 构造函数 xff1a 按照继承顺序依次执行父类的构造函数 xff0c 再执行子类的构造函数 xff0c 析构函数 xff1a 和构造函数完全相反 xff1b 这个跟栈的先存后释放弹夹模型是
  • linux系统源码文档,Linux操作系统源代码详细分析

    linux内核的代码分析 Linux操作系统源代码详细分析 内容简介 xff1a Linux 拥有现代操作系统所有的功能 xff0c 如真正的抢先式多任务处理 支持多用户 xff0c 内存保护 xff0c 虚拟内存 xff0c 支持SMP
  • Kerloud mini飞控PX4固件使用详解

    简介 Kerloud Mini是由云讷科技 xff08 深圳 xff09 有限公司发布的自驾仪产品 xff0c 主要面向无人系统 xff08 如无人机 无人车等 xff09 作为一个受益于开源社区的开发团队 xff0c 我们积极使产品能够兼
  • 示波器基础二十问

    第一问 xff1a 示波器的波形代表什么意义 xff1f 一句话概括 xff1a 水平坐标代表时间 xff0c 垂直坐标代表电压 xff08 一般是电压 xff09 xff0c 电压随时间变化的曲线就是示波器显示的波形 垂直坐标比较好理解
  • 设置Ubuntu 18登陆时直接进入命令行界面(字符界面)

    一般而言 xff0c 登陆之后默认的时图形界面即Xwindows界面 xff0c 我们在登陆后默认界面后打开终端 xff08 命令行 xff09 快捷键为 xff1a ctl 43 alt 43 T sudo systemctl set d
  • Keil5配置使用IAP15F2K61S2的头文件

    一 xff0c 安装Keil版本仿真驱动 STC ISP 首先选择 Keil关联设置 页面 xff0c 点击 添加MCU型号到Keil中 xff0c 在出现的如 Keil的安装目录 自己安装时所选择的 xff0c 找到后 确定 出现下图为成
  • Java常用工具类之HttpUtils

    HttpClien请求涉及到两个类 xff0c 一个是http的请求 xff0c 另一个是对http连接池参数进行设置 所需的jar span class token tag span class token tag span class
  • Jetson 系列——基于yolov5对反光衣和安全帽的检测,部属于jetson xavier nx,使用tensorrt、c++和int8加速,可用于边缘计算

    代码地址 xff1a github c 43 43 地址 https github com RichardoMrMu yolov5 reflective clothes detect github python地址 https github
  • 开源自制的6通道航模遥控器(三)-遥控器端增加MIX混控模式

    1 了解什么是混控 要了解混控 xff0c 需要先对比一般的遥控模式 一般遥控的每个操作控制都是一个通道 xff0c 比如美国手的遥控器 xff0c 左边摇杆前后控制油门 xff0c 左右控制方向舵 xff1b 右边摇杆前后控制升降舵 xf
  • MacOS终端配置

    MacOS下终端的一些问题 安装HomeBrew 官方推荐的是 bin bash c 34 curl fsSL https raw githubusercontent com Homebrew install master install
  • ArcFaceSDK3.0 Python Demo

    做服务外包项目需要是用虹软的人脸对比SDK xff0c 项目使用Python进行开发 xff0c 但是网上以及官方社区没有基于Python的3 0版本项目 xff0c 所以自己根据社区里大佬1 1和2 0的Demo修改套了一下 face c
  • 利用Github和Hexo搭建自己的博客

    之前的自己搭的服务器gg了 xff0c 一直也没动手继续去恢复一下 xff0c 前段时间看操作系统教程的时候被NEXT这个主题吸引了 xff0c 再次萌生了整个博客的想法 之前就有听说过Github可以搭博客 xff0c 所以这次也打算试一
  • 面向行业级应用的Kerloud 600 Pro-Cam Pod开发平台

    产品定位 Kerloud 600 Pro Cam Pod是云讷科技 xff08 深圳 xff09 有限公司为行业级无人机解决方案开发者打造的一款高级无人机研发平台 xff0c 产品搭载高算力Nvidia GPU 高清吊舱云台并配备专业的SD
  • swift-网络-URLSession学习

    URLSession 在 2013年随着 iOS7 的发布一起面世的 xff0c 苹果对它的定位是作为 NSURLConnection 的替代者 xff0c 在 iOS9 之后苹果官方已经移除了 NSURLConnection xff0c
  • nil和Nil及NULL和NSNull的区别 - OC

    其实早就想研究一下nil Nil NULL和NSNull之间的区别 xff0c 只是工作上除了nil xff0c 其它的几乎少有用到 xff0c 所以一直拖到今天 有时候感觉自己越来越浮躁 xff0c 对细微处的知识理解不够深入 xff0c
  • Fast-planner代码阅读2-TopoReplan (path searchiing部分)

    文章目录 1 总体流程2 Topo Path Finding Algorithm主要算法及图例3 topoPath路径搜索代码流程3 1 createGraph xff08 xff09 3 1 1 findVisbGUard3 1 2 ne
  • centos7.7 安装google浏览器

    centos7 7 安装google浏览器 添加google chrome 源 cd etc yum repos d vi google chrome repo 添加如下内容 google chrome name 61 google chr
  • mysql5.6漏洞_MySQL 5.6.24 Buffer Overflow

    61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
  • java获取gps 串口_从串口读取GPS数据

    网上找来的代码自己修改之后放到这里的 参考地址 xff1a http www pcppc cn kaifa VBjiaocheng kaifa 18010 html http www itqoo com programme ASPNET 2