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这种类型的,需要跳过行首或者行尾一些和数据无关的或者自 ...
随机推荐
- [LeetCode] Sliding Window Maximum 滑动窗口最大值
Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...
- [LeetCode] Nth Highest Salary 第N高薪水
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- AppBoxPro - 细粒度通用权限管理框架(可控制表格行内按钮)源码提供下载
特别声明: 提供的源代码已经包含了 AppBoxPro 的全部源代码,用 VS2012 打开项目后,直接 Ctrl+F5 可以运行起来(默认使用VS自带的LocalDB数据库). FineUIPro是 ...
- 【Quartz】将定时任务持久化到数据库
之前的文章所做的demo是将定时任务的信息保存在内存中的,见以下配置 org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore 如果,我们需要在 ...
- iOS推送流程
1. 在apple开发者帐号上创建一个BundleID,创建证书或者Xcode上都是用这个BundleID(例如com.mycompany.pushDemo) 2. 代码层面: 在capability ...
- Python 【第五章】:线程、进程和协程
Python线程 Threading用于提供线程相关的操作,线程是应用程序中工作的最小单元. #!/usr/bin/env python # -*- coding:utf-8 -*- import t ...
- ASE周会记录
本周Sprint Master Atma Hou 一. 本周会议概要 本次会议的主要任务是明确和老师讨论后的数据库设计定稿,同时为我们接下来的连接工作确定包含实现细节的story和接口. 二. 会议内 ...
- UVA1225
每增加1个整数,所有位上的对应数都加一.建立一个10000列10行的表,然后查表就可以了. #include<stdio.h> #include<string.h> ][]; ...
- Linux可信计算机制模块详细分析之核心文件分析(8)tpm.c核心代码注释(中)
/*设置TPM命令格式*/ ssize_t tpm_getcap(struct device *dev, __be32 subcap_id, cap_t *cap, const char *desc) ...
- 埃拉托色尼筛法(Sieve of Eratosthenes)求素数。
埃拉托色尼筛法(Sieve of Eratosthenes)是一种用来求所有小于N的素数的方法.从建立一个整数2~N的表着手,寻找i? 的整数,编程实现此算法,并讨论运算时间. 由于是通过删除来实现, ...