Qt - 读取GPS数据
1.GPS型号为ublox(EVK-M8L),配有USB接口,Qt版本5.7
2.实现步骤:
(1)实现串口通信
采用Qt5.7 内置的串口操作类QSerialPort和QSerialPortInfo,通过QSerialPortInfo提供的函数availablePorts(),可枚举出当前计算机中可用的com口。使用该类需在pro文件中添加:
QT += serialport
(2)筛选感兴趣的信号,解析
GPRMC数据包基本上包含经纬度、航向角、时间等常用的信号。
3.效果图

4.源码
4.1 头文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo> namespace Ui {
class MainWindow;
} class MainWindow : public QMainWindow
{
Q_OBJECT public:
explicit MainWindow(QWidget *parent = );
~MainWindow(); public:
QSerialPort serial;//串口实例
void initSeialPort();//初始化串口函数
private:
void gpsParse(QByteArray GPSBuffer);//gps解析函数 private slots:
void serialRead(); void on_connectBtn_clicked(); void on_closeBtn_clicked(); private:
Ui::MainWindow *ui;
}; #endif // MAINWINDOW_H
4.2实现文件
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include <QList> MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QStringList strBaud;
strBaud<<""<<""<<"";
ui->baudcomboBox->addItems(strBaud); initSeialPort();
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::initSeialPort()
{
connect(&serial,SIGNAL(readyRead()),this,SLOT(serialRead())); //连接槽 //获取计算机上所有可用串口并添加到comboBox中
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
if(infos.isEmpty())
{
ui->portcomboBox->addItem("无串口");
return;
}
foreach (QSerialPortInfo info, infos) {
ui->portcomboBox->addItem(info.portName());
qDebug() << info.portName();
} } void MainWindow::serialRead()
{
QByteArray qa = serial.readAll(); ui->textEdit->append(qa); gpsParse(qa); ui->statusLabel->setText("读取中...");
} void MainWindow::gpsParse(QByteArray GPSBuffer)
{ // qDebug()<<GPSBuffer.size(); if(GPSBuffer.contains("$GNRMC") )
{ QList<QByteArray> gpsByteArrays = GPSBuffer.split(',');
int count = gpsByteArrays.count(); int gpsLat_1 = static_cast<int>(gpsByteArrays.at().toDouble()/);
double gpsLat_2 = (gpsByteArrays.at().toDouble() - gpsLat_1 * )/;
double gpslat=gpsLat_1 + gpsLat_2; int gpsLong_1 = static_cast<int>(gpsByteArrays.at().toDouble()/);
double gpsLong_2 = (gpsByteArrays.at().toDouble()-gpsLong_1 * )/;
double gpsLong = gpsLong_1 + gpsLong_2; ui->timelineEdit->setText(gpsByteArrays.at());
ui->latlineEdit->setText(QString::number(gpslat,'g',));
ui->longlineEdit->setText(QString::number(gpsLong,'g',)); if(!gpsByteArrays.at().isEmpty())
ui->headlineEdit->setText(gpsByteArrays.at()); }
} void MainWindow::on_connectBtn_clicked()
{
QSerialPortInfo info;
QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts();
int i = ;
foreach (info, infos) {
if(info.portName() == ui->portcomboBox->currentText()) break;
i++;
} if(i != infos.size ()){//can find
ui->statusLabel->setText("串口打开成功"); serial.close();
serial.setPort(info);
serial.open(QIODevice::ReadWrite); //读写打开
switch (ui->baudcomboBox->currentIndex()) {
case :
serial.setBaudRate(QSerialPort::Baud4800);
break;
case :
serial.setBaudRate(QSerialPort::Baud9600);
qDebug()<<"";
break;
case :
serial.setBaudRate(QSerialPort::Baud115200);
qDebug()<<"";
default:
break;
} // serial.setBaudRate(QSerialPort::Baud9600); //波特率
// serial.setDataBits(QSerialPort::Data8); //数据位
// serial.setParity(QSerialPort::NoParity); //无奇偶校验
// serial.setStopBits(QSerialPort::OneStop); //无停止位
// serial.setFlowControl(QSerialPort::NoFlowControl); //无控制
}else{
serial.close(); ui->statusLabel->setText("串口打开失败");
}
} void MainWindow::on_closeBtn_clicked()
{
serial.close();
ui->statusLabel->setText("串口断开");
}
Qt - 读取GPS数据的更多相关文章
- GPS数据读取与处理
GPS数据读取与处理 GPS模块简介 SiRF芯片在2004年发布的最新的第三代芯片SiRFstar III(GSW 3.0/3.1),使得民用GPS芯片在性能方面登上了一个顶峰,灵敏度比以前的产品大 ...
- Qt读取JSON和XML数据
QJSON JSON(JavaScript Object Notation)是一个轻量级的数据交换格式; 可以将数据以name/value的形式任意组合; QJson 是一个基于Qt的库, 将JSON ...
- Qt通过odbc读取excel数据
传统的读取方式是通过Excel.Application,这种方式不仅操作繁琐,而且速度也不快. 通过odbc读取,可以使用select语句直接读取整个工作表,处理excel数据就跟数据库一样方便. 当 ...
- Qt监控Arduino开关状态(读取串口数据)
setup.ini配置文件内容 [General] #游戏所在主机IP GameIp1=192.168.1.151 GameIp2=192.168.1.152 GameIp3=192.168.1.15 ...
- 采集的GPS数据如何正确显示在arcgis和cad中
利用GPS定位卫星,在全球范围内实时进行定位.导航的系统,称为全球卫星定位系统,简称GPS.GPS是由美国国防部研制建立的一种具有全方位.全天候.全时段.高精度的卫星导航系统,能为全球用户提供低成本. ...
- 格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: GetLzdtArticleResult。InnerException 消息是“反序列化对象 属于类型 lzdt.DTO.Dtolzdt[] 时出现错误。读取 XML 数据时,超出最大
当遇到这个错误的时候郁闷了好长时间报错是字符串长度过大可是修改了MaxStringContentLength”属性的值却不起作用最后才发现还是因为配置文件配置的问题在服务端 格式化程序尝试对消息反序列 ...
- 使用 Qt 获取 UDP 数据并显示成图片(2)
本文首发于 BriFuture 的 个人博客 在我的前一篇文章 使用 Qt 获取 UDP 数据并显示成图片 中,我讲了如何用 Python 模拟发送数据,如何在 Qt 中高效的接收 UDP 数据包并将 ...
- java的poi技术读取Excel数据到MySQL
这篇blog是介绍java中的poi技术读取Excel数据,然后保存到MySQL数据中. 你也可以在 : java的poi技术读取和导入Excel了解到写入Excel的方法信息 使用JXL技术可以在 ...
- Hive读取外表数据时跳过文件行首和行尾
作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 有时候用hive读取外表数据时,比如csv这种类型的,需要跳过行首或者行尾一些和数据无关的或者自 ...
随机推荐
- simpson
使用二次函数拟合复杂的连续函数求积分 对于(l,r)拟合的积分为(r-l)*(f(l)+4*f((l+r)/2)+f(r))/6 ___________________________ BZOJ217 ...
- sql server 中隐藏掉无关数据库
先贴上我实际测试的效果 方法一: Problem I have a SQL Server instance that has hundreds of databases. Navigating th ...
- ES6深入学习记录(一)class方法相关
今天学习class相关的一些使用方法,着重在于class extends class之间可以通过extends关键字实现继承,这比ES5的通过修改原型链实现继承,要清晰和方便很多. 上面的代码定义了一 ...
- Git忽略.gitignore规则不生效的解决办法
在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改根目录中 .gitignore 文件的方法(如无,则需自己手工建立此文件). 这个文件每一行保存了一个匹配的规则例如: # 此为 ...
- ORB-SLAM(六)回环检测
上一篇提到,无论在单目.双目还是RGBD中,追踪得到的位姿都是有误差的.随着路径的不断延伸,前面帧的误差会一直传递到后面去,导致最后一帧的位姿在世界坐标系里的误差有可能非常大.除了利用优化方法在局部和 ...
- c# 判断访问来源是否来自手机
public Boolean IsMobileDevice() { string[] mobileAgents =new []{ "iphone", "android&q ...
- 【poj2151】 Check the difficulty of problems
http://poj.org/problem?id=2151 (题目链接) 题意 T支队伍,一共M道题,第i支队伍解出第j道题的概率为p[i][j].问每支队伍至少解出1道题并且解题最多的的队伍至少解 ...
- Linux下几款好用的录屏软件
最近需要在Linux环境下录制一段视频,自己的Linux是LinuxMint Xfce 18,网上搜了一圈发现都不太顺手.尤其是VLC,感觉不是很易用,幸好最后在Linux自带的软件管理器找到了两个不 ...
- 常用的Jquery插件
0.模块化前端框架(http://www.layui.com) 1.拖拽滑动验证码(http://www.geetest.com/,https://github.com/dyh1995/jquery. ...
- js中 checkTime()函数
<html><head><script type="text/javascript">function startTime()//函数start ...