-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathmainwindow.cpp
executable file
·41 lines (36 loc) · 946 Bytes
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->portName->addItem("/dev/ttyUSB0",0);
ui->portName->addItem("COM4",0);
connect(&serial,SIGNAL(lineReceived(QString)),
this,SLOT(onLineReceived(QString)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
serial.write(ui->commandText->text()+"\n");
}
void MainWindow::onLineReceived(QString data)
{
ui->textBrowser->append(data);
}
void MainWindow::on_openCloseButton_clicked()
{
if(serial.isOpen())
{
serial.close();
ui->openCloseButton->setText("Open");
} else {
ui->textBrowser->clear();
serial.open(ui->portName->currentText(),115200);
if(!serial.isOpen() || serial.errorStatus()) return;
ui->openCloseButton->setText("Close");
}
}