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这种类型的,需要跳过行首或者行尾一些和数据无关的或者自 ...
随机推荐
- HTTPf服务器(3)
功能完整的HTTP服务器 导语 这个一个功能完备的HTTP服务器.它可以提供一个完整的文档输,包括图像,applet,HTML文件,文本文件.它与SingleFileHttpServer非常相似,只不 ...
- Nfs+Drdb+Heartbeat 数据存储高可用服务架构方案
一.方案的应用场景 适用于2千万-3千万PV架构的网站,Nfs数据存储高可用服务方案 备注:互联网排名前30左右公司常用的架构 二.生产环境方案部署原理图 三.生产环境服务器硬件配置: 生产环境中采用 ...
- 20170103简单解析MySQL查询优化器工作原理
转自博客http://www.cnblogs.com/hellohell/p/5718238.html 感谢楼主的贡献 查询优化器的任务是发现执行SQL查询的最佳方案.大多数查询优化器,包括MySQL ...
- Android零碎知识
1.当启动一个APP时按下后退键会调用onBackPressed方法. 如果想要屏蔽后退键只需要重写onBackPressed方法如下即可: @Override public void onBackP ...
- JFinal 项目 在tomcat下部署
原文:http://my.oschina.net/jfinal/blog/353062 首先明确一下 JFinal 项目是标准的 java web 项目,其部署方式与普通 java web 项目没有任 ...
- ka/ks
1. If dN/dS = 1, amino-acid substitutions may be largely neutral. However, there is also the possibi ...
- mysql 5分钟倒计时
select * ,now(), DATE_ADD(create_time, INTERVAL 5 MINUTE) from ecs_sms_cache where now() between cre ...
- 计算机视觉之《OpenCV开发环境搭建》
codeblock安装:http://blog.csdn.net/hitwengqi/article/details/7985343 ubuntu+codeblock+opencv:http://bl ...
- ThinkPhp 3.2 常见问题与注意事项
1 命名空间声明必须写在脚本的最前面 如果运行PHP脚本后出现如下错误: Namespace declaration statement has to be the very first statem ...
- 转:解决npm install慢的问题
使用NPM(Node.js包管理工具)安装依赖时速度特别慢,为了安装Express,执行命令后两个多小时都没安装成功,最后只能取消安装,笔者20M带宽,应该不是我网络的原因,后来在网上找了好久才找到一 ...