-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupserial.cpp
108 lines (85 loc) · 2.47 KB
/
setupserial.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "setupserial.h"
#include "ui_setupserial.h"
setupSerial::setupSerial(QWidget *parent) :
QDialog(parent),
ui(new Ui::setupSerial)
{
ui->setupUi(this);
ui->baudBox->addItem(QStringLiteral("9600"), QSerialPort::Baud9600);
ui->baudBox->addItem(QStringLiteral("19200"), QSerialPort::Baud19200);
ui->baudBox->addItem(QStringLiteral("38400"), QSerialPort::Baud38400);
ui->baudBox->addItem(QStringLiteral("57600"), QSerialPort::Baud57600);
ui->baudBox->addItem(QStringLiteral("115200"), QSerialPort::Baud115200);
ui->baudBox->addItem(QStringLiteral("Custom"));
GetPortInfo();
}
setupSerial::~setupSerial()
{
delete ui;
}
QString setupSerial::getPort()
{
return myPort;
}
qint32 setupSerial::getBaud()
{
return myBaud;
}
void setupSerial::setPort(QString savedPort)
{
int search = ui->portBox->findText(savedPort);
if(search != -1)
{
ui->portBox->setCurrentIndex(search);
myPort = ui->portBox->currentText();
}
}
void setupSerial::setBaud(qint32 savedBaud)
{
QString temp = QString::number(savedBaud);
int search = ui->baudBox->findText(temp);
if(search != -1)
{
ui->baudBox->setCurrentIndex(search);
myBaud = ui->baudBox->currentText().toInt();
}
else
{
myBaud = savedBaud;
}
}
void setupSerial::GetPortInfo()
{
ui->baudBox->setCurrentIndex(4);
ui->portBox->clear();
static const QString blankString = QObject::tr("N/A");
QString description;
QString manufacturer;
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
QStringList list;
description = info.description();
manufacturer = info.manufacturer();
list << info.portName()
<< (!description.isEmpty() ? description : blankString)
<< (!manufacturer.isEmpty() ? manufacturer : blankString)
<< info.systemLocation()
<< (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : blankString)
<< (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : blankString);
ui->portBox->addItem(list.first(), list);
}
}
void setupSerial::UpdateList()
{
myPort = ui->portBox->currentText();
myBaud = ui->baudBox->currentText().toInt();
}
void setupSerial::on_pushButton_clicked()
{
UpdateList();
emit portBaudSetting(myPort, myBaud);
this->hide();
}
void setupSerial::on_pushButton_2_clicked()
{
this->hide();
}