#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qextserialport.h"
#include <QTimer>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
com = ui->comboBox->currentText();
port = new QextSerialPort(com);
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
ui->dataWindow1->setDisabled(1);
ui->dataWindow2->setDisabled(1);
if(port->isOpen())
{
port->flush();
port->close();
}
connect(timer, SIGNAL(timeout()), this, SLOT(serialupdate()));
timer->start(100);
}
MainWindow::~MainWindow()
{
port->close();
delete ui;
delete port;
}
void MainWindow::serialupdate()
{
port->flush();
char buff[1024];
if(port->bytesAvailable())
{
int i = port->read(buff, 1);
buff[i] = '\0';
if(i != -1)
{
ui->dataWindow1->append("0x"+data);
ui->dataWindow2->append(str);
}
else
qDebug("cannot open");
}
}
void MainWindow::on_pushButton_clicked()
{
ui->dataWindow1->setDisabled(0);
ui->dataWindow2->setDisabled(0);
ui->comboBox->setDisabled(1);
ui->comboBox_2->setDisabled(1);
}
void MainWindow::on_pushButton_2_clicked()
{
ui->dataWindow1->setDisabled(1);
ui->dataWindow2->setDisabled(1);
ui->comboBox->setDisabled(0);
ui->comboBox_2->setDisabled(0);
port->close();
}
void MainWindow::on_pushButton_3_clicked()
{
ui->dataWindow1->clear();
ui->dataWindow2->clear();
}
void MainWindow::on_comboBox_2_currentIndexChanged(int index)
{
if(index == 0)
port->setBaudRate(BAUD4800);
if(index == 1)
port->setBaudRate(BAUD9600);
if(index == 2)
port->setBaudRate(BAUD14400);
if(index == 3)
port->setBaudRate(BAUD19200);
}
Bookmarks