#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qextserialport.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
port = new QextSerialPort("/dev/ttyUSB0");
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->setRts(true);
port->setDtr(true);
connect(ui->btnExit, SIGNAL(clicked()), SLOT(exit()));
connect(ui->btnConnect, SIGNAL(clicked()), SLOT(openPort()));
connect(ui->btnRead, SIGNAL(clicked()), SLOT(readSerial()));
connect(ui->btnDisconnect, SIGNAL(clicked()), SLOT(closePort()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openPort()
{
if (port->bytesAvailable())
{
ui->textEdit->setText("Connected");
}
else
ui->textEdit->append("Please Check Your Serial");
}
void MainWindow::readSerial()
{
char buff[64];
qint64 i=port->readLine(buff,63);
while(1)
{
if (port->bytesAvailable())
{
buff[i]='\0';
//Dispaly
ui->textEdit->append(msg);
}
}
void MainWindow::closePort()
{
port->flush();
port->close();
}
void MainWindow::exit()
{
close();
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qextserialport.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
port = new QextSerialPort("/dev/ttyUSB0");
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->setRts(true);
port->setDtr(true);
connect(ui->btnExit, SIGNAL(clicked()), SLOT(exit()));
connect(ui->btnConnect, SIGNAL(clicked()), SLOT(openPort()));
connect(ui->btnRead, SIGNAL(clicked()), SLOT(readSerial()));
connect(ui->btnDisconnect, SIGNAL(clicked()), SLOT(closePort()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openPort()
{
port->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
if (port->bytesAvailable())
{
ui->textEdit->setText("Connected");
}
else
ui->textEdit->append("Please Check Your Serial");
}
void MainWindow::readSerial()
{
char buff[64];
qint64 i=port->readLine(buff,63);
while(1)
{
if (port->bytesAvailable())
{
buff[i]='\0';
QString msg = buff;
//Dispaly
ui->textEdit->append(msg);
}
}
void MainWindow::closePort()
{
port->flush();
port->close();
}
void MainWindow::exit()
{
close();
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks