-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPortSettings.cpp
168 lines (134 loc) · 4.79 KB
/
PortSettings.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "PortSettings.h"
#include "ui_PortSettings.h"
PortSettings::PortSettings(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::PortSettings)
{
ui->setupUi(this);
this->setWindowTitle("Port Settings");
//this->setMinimumSize(guiWidth, guiHeight);
this->setGeometry(0,0, 440, 390);
if(GlobalVars::ACTORis == ActorUSER) {
//this->setWindowState(Qt::WindowMaximized);
//this->setWindowState(Qt::WindowFullScreen);
this->setWindowFlag(Qt::WindowStaysOnTopHint);
} else if(GlobalVars::ACTORis == ActorAdministrator) {
}
//this->setWindowFlags(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_DeleteOnClose);
timerSingleShot = new QTimer(this);
timerSingleShot->setSingleShot(true);
connect(timerSingleShot, SIGNAL(timeout()), this, SLOT(onTimerSingleShotElapsed()));
timerSingleShot->start(400);
}
PortSettings::~PortSettings()
{
delete ui;
}
void PortSettings::onTimerSingleShotElapsed()
{
ui->cmbCOMportName->clear();
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
//qDebug()<<"--------------------------------------";
//qDebug()<<"Name : "<< info.portName();
//qDebug()<<"Description : "<< info.description();
//qDebug()<<"Manufacturer: "<< info.manufacturer();
// Example use QSerialPort
ui->cmbCOMportName->addItem(info.portName());
}
qDebug()<<"--------------------------------------";
if(QFile::exists(GlobalVars::filePathCOMportSettings)){
QFile file(GlobalVars::filePathCOMportSettings);
if(file.open(QIODevice::ReadOnly)){
QTextStream in(&file);
while (!in.atEnd())
{
QString line = in.readLine();
//qDebug()<<" file LIne:: "<<line;
processSettingsLine(line);
}
file.close();
} else {
qDebug()<<" Error in Opening SettingsFile: "<<GlobalVars::filePathCOMportSettings;
}
}
else {
qDebug()<<" COM Port Setting File did not exist ";
}
}
void PortSettings::processSettingsLine(QString line)
{
if(line.length() < 3) return;
//qDebug()<<" Serial COM Port Processing Line: "<<line;
int index = line.indexOf(",");
//qDebug()<<" ID Index : "<<index;
if(index < 0) return;
bool okBool = false;
int parameterID = line.left(index).toInt(&okBool);
line.remove(0, index+1);
index = line.indexOf(",");
//qDebug()<<" Value Index : "<<index<<" line: "<<line;
if(index < 0) return;
okBool = false;
QString parameterValue = line.left(index);
//qDebug()<<" paraID: "<<parameterID<<" Serial Port Name Value: "<<parameterValue;
int findIndex = -1;
switch (parameterID) {
case 1:{
findIndex = ui->cmbCOMportName->findText(parameterValue);
if(findIndex>-1) ui->cmbCOMportName->setCurrentIndex(findIndex);
break;
}
case 2:{
findIndex = ui->cmbBaudRate->findText(parameterValue);
if(findIndex>-1) ui->cmbBaudRate->setCurrentIndex(findIndex);
break;
}
case 3:{
findIndex = ui->cmbDataBits->findText(parameterValue);
if(findIndex>-1) ui->cmbDataBits->setCurrentIndex(findIndex);
break;
}
case 4:{
findIndex = ui->cmbParity->findText(parameterValue);
if(findIndex>-1) ui->cmbParity->setCurrentIndex(findIndex);
break;
}
case 5:{
findIndex = ui->cmbStopBits->findText(parameterValue);
if(findIndex>-1) ui->cmbStopBits->setCurrentIndex(findIndex);
break;
}
case 6:{
findIndex = ui->cmbParityErrorChar->findText(parameterValue);
if(findIndex>-1) ui->cmbParityErrorChar->setCurrentIndex(findIndex);
break;
}
default:
break;
}
//rxInitializeSerialPort(parameterValue);
}
void PortSettings::on_pbCancel_clicked()
{
this->close();
}
void PortSettings::on_pbConfiguration_clicked()
{
QString fileData = QString("1,"+ui->cmbCOMportName->currentText()+",\n ");
fileData += QString("2,"+ui->cmbBaudRate->currentText()+",\n ");
fileData += QString("3,"+ui->cmbDataBits->currentText()+",\n ");
fileData += QString("4,"+ui->cmbParity->currentText()+",\n ");
fileData += QString("5,"+ui->cmbStopBits->currentText()+",\n ");
fileData += QString("6,"+ui->cmbParityErrorChar->currentText()+",\n ");
QFile file(GlobalVars::filePathCOMportSettings);
if(file.open(QIODevice::WriteOnly)){
//qDebug()<<" Settings File Data:: \n"<<fileData;
file.write(fileData.toUtf8(), fileData.toUtf8().length());
file.close();
} else {
qDebug()<<" Error in Opening SettingsFile: "<<GlobalVars::filePathCOMportSettings;
}
emit txNewSerialPortConfig(ui->cmbCOMportName->currentText());
this->close();
}