您的位置:首页 > 编程语言 > Qt开发

树莓派使用QT串口数据输出

2018-03-04 18:41 507 查看

树莓派使用QT串口数据输出

首先在.pro 文件中添加如下代码:# 下面这个LIBS很关键
LIBS += -lwiringPi
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include  <wiringPi.h>
#include  <wiringSerial.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <sys/stat.h>
#include <unistd.h>
using namespace std;

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
int fd;
// 串口初始化
if((fd = serialOpen("/dev/ttyAMA0",115200)) < 0)
{
//初始化没成功什么也不干
}
while(1)
{
serialPuts(fd,"uart send test,just by launcher");//通过串口发送
}

}

MainWindow::~MainWindow()
{
delete ui;
}
测试效果如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  树莓派 QT
相关文章推荐