| Line 1... |
Line 1... |
| 1 |
#include "SerialWidget.h"
|
1 |
#include "SerialWidget.h"
|
| 2 |
|
2 |
|
| 3 |
SerialWidget::SerialWidget(QWidget *parent) : QWidget(parent)
|
3 |
SerialWidget::SerialWidget(QWidget *parent) : QWidget(parent)
|
| 4 |
{
|
4 |
{
|
| 5 |
// Serial connection UI
|
5 |
// Serial connection UI
|
| 6 |
btnSerialConnect = new QPushButton("&Connect");
|
6 |
btnConnect = new QPushButton("&Connect");
|
| 7 |
btnSerialRefresh = new QPushButton("&Refresh");
|
7 |
btnRefresh = new QPushButton("&Refresh");
|
| 8 |
labelSerialPort = new QLabel("Serial Port:");
|
8 |
labelPort = new QLabel("Serial Port:");
|
| 9 |
labelSerialSpeed = new QLabel("Baud Rate:");
|
9 |
labelSpeed = new QLabel("Baud Rate:");
|
| 10 |
labelSerialDataBits = new QLabel("Data:");
|
10 |
labelDataBits = new QLabel("Data:");
|
| 11 |
labelSerialStopBits = new QLabel("Stop:");
|
11 |
labelStopBits = new QLabel("Stop:");
|
| 12 |
labelSerialParity = new QLabel("Parity Bit:");
|
12 |
labelParity = new QLabel("Parity Bit:");
|
| 13 |
labelSerialFlowControl = new QLabel("Flow Control:");
|
13 |
labelFlowControl = new QLabel("Flow Control:");
|
| 14 |
cboxSerialPort = new QComboBox();
|
14 |
cboxPort = new QComboBox();
|
| 15 |
cboxSerialPort->setMinimumWidth(80);
|
15 |
cboxPort->setMinimumWidth(80);
|
| 16 |
cboxSerialSpeed = new QComboBox();
|
16 |
cboxSpeed = new QComboBox();
|
| 17 |
cboxSerialSpeed->setEditable(true);
|
17 |
cboxSpeed->setEditable(true);
|
| 18 |
cboxSerialSpeed->setValidator(new QIntValidator(0, 100000000, this));
|
18 |
cboxSpeed->setValidator(new QIntValidator(0, 100000000, this));
|
| 19 |
cboxSerialDataBits = new QComboBox();
|
19 |
cboxDataBits = new QComboBox();
|
| 20 |
cboxSerialDataBits->setMaximumWidth(60);
|
20 |
cboxDataBits->setMaximumWidth(60);
|
| 21 |
cboxSerialStopBits = new QComboBox();
|
21 |
cboxStopBits = new QComboBox();
|
| 22 |
cboxSerialStopBits->setMaximumWidth(60);
|
22 |
cboxStopBits->setMaximumWidth(60);
|
| 23 |
cboxSerialParity = new QComboBox();
|
23 |
cboxParity = new QComboBox();
|
| 24 |
cboxSerialFlowControl = new QComboBox();
|
24 |
cboxFlowControl = new QComboBox();
|
| 25 |
cboxSerialFlowControl->setMinimumWidth(70);
|
25 |
cboxFlowControl->setMinimumWidth(70);
|
| 26 |
|
26 |
|
| 27 |
QGridLayout *serialSettingsLayout = new QGridLayout();
|
27 |
QGridLayout *serialSettingsLayout = new QGridLayout();
|
| 28 |
serialSettingsLayout->addWidget(btnSerialConnect, 0, 0);
|
28 |
serialSettingsLayout->addWidget(btnConnect, 0, 0);
|
| 29 |
serialSettingsLayout->addWidget(labelSerialPort, 0, 1);
|
29 |
serialSettingsLayout->addWidget(labelPort, 0, 1);
|
| 30 |
serialSettingsLayout->addWidget(cboxSerialPort, 0, 2);
|
30 |
serialSettingsLayout->addWidget(cboxPort, 0, 2);
|
| 31 |
serialSettingsLayout->addWidget(labelSerialDataBits, 0, 3);
|
31 |
serialSettingsLayout->addWidget(labelDataBits, 0, 3);
|
| 32 |
serialSettingsLayout->addWidget(cboxSerialDataBits, 0, 4);
|
32 |
serialSettingsLayout->addWidget(cboxDataBits, 0, 4);
|
| 33 |
serialSettingsLayout->addWidget(labelSerialParity, 0, 5);
|
33 |
serialSettingsLayout->addWidget(labelParity, 0, 5);
|
| 34 |
serialSettingsLayout->addWidget(cboxSerialParity, 0, 6);
|
34 |
serialSettingsLayout->addWidget(cboxParity, 0, 6);
|
| 35 |
|
35 |
|
| 36 |
serialSettingsLayout->addWidget(btnSerialRefresh, 1, 0);
|
36 |
serialSettingsLayout->addWidget(btnRefresh, 1, 0);
|
| 37 |
serialSettingsLayout->addWidget(labelSerialSpeed, 1, 1);
|
37 |
serialSettingsLayout->addWidget(labelSpeed, 1, 1);
|
| 38 |
serialSettingsLayout->addWidget(cboxSerialSpeed, 1, 2);
|
38 |
serialSettingsLayout->addWidget(cboxSpeed, 1, 2);
|
| 39 |
serialSettingsLayout->addWidget(labelSerialStopBits, 1, 3);
|
39 |
serialSettingsLayout->addWidget(labelStopBits, 1, 3);
|
| 40 |
serialSettingsLayout->addWidget(cboxSerialStopBits, 1, 4);
|
40 |
serialSettingsLayout->addWidget(cboxStopBits, 1, 4);
|
| 41 |
serialSettingsLayout->addWidget(labelSerialFlowControl, 1, 5);
|
41 |
serialSettingsLayout->addWidget(labelFlowControl, 1, 5);
|
| 42 |
serialSettingsLayout->addWidget(cboxSerialFlowControl, 1, 6);
|
42 |
serialSettingsLayout->addWidget(cboxFlowControl, 1, 6);
|
| 43 |
|
43 |
|
| 44 |
setLayout(serialSettingsLayout);
|
44 |
setLayout(serialSettingsLayout);
|
| 45 |
|
45 |
|
| 46 |
serialHelper = new SerialHelper();
|
46 |
serialHelper = new SerialHelper();
|
| 47 |
serialThread = new QThread();
|
47 |
serialThread = new QThread();
|
| 48 |
serialHelper->moveToThread(serialThread);
|
48 |
serialHelper->moveToThread(serialThread);
|
| 49 |
|
49 |
|
| 50 |
connect(serialHelper, SIGNAL(UpdateStatus(QString)), this, SIGNAL(UpdateStatus(QString)));
|
50 |
connect(serialHelper, SIGNAL(UpdateStatus(QString)), this, SIGNAL(UpdateStatus(QString)));
|
| 51 |
|
51 |
|
| 52 |
connect(this, SIGNAL(Serial_QueryParameters()), serialHelper, SLOT(Serial_QueryParameters()));
|
52 |
connect(this, SIGNAL(QueryParameters()), serialHelper, SLOT(QueryParameters()));
|
| 53 |
connect(serialHelper, SIGNAL(Serial_UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)),
|
53 |
connect(serialHelper, SIGNAL(UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)),
|
| 54 |
this, SLOT(Serial_UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)));
|
54 |
this, SLOT(UpdateParameters(QStringList,QStringList,QStringList,QStringList,QStringList,QStringList)));
|
| 55 |
|
55 |
|
| 56 |
connect(this, SIGNAL(Serial_Connect(QString,QString,QString,QString,QString,QString)),
|
56 |
connect(this, SIGNAL(Connect(QString,QString,QString,QString,QString,QString)),
|
| 57 |
serialHelper, SLOT(Serial_Connect(QString,QString,QString,QString,QString,QString)));
|
57 |
serialHelper, SLOT(Connect(QString,QString,QString,QString,QString,QString)));
|
| 58 |
connect(serialHelper, SIGNAL(Serial_Connected()), this, SIGNAL(Serial_Connected()));
|
58 |
connect(serialHelper, SIGNAL(Connected()), this, SIGNAL(Connected()));
|
| 59 |
connect(serialHelper, SIGNAL(Serial_Connected()), this, SLOT(Serial_LocalConnected()));
|
59 |
connect(serialHelper, SIGNAL(Connected()), this, SLOT(LocalConnected()));
|
| 60 |
|
60 |
|
| 61 |
connect(this, SIGNAL(Serial_Disconnect()), serialHelper, SLOT(Serial_Disconnect()));
|
61 |
connect(this, SIGNAL(Disconnect()), serialHelper, SLOT(Disconnect()));
|
| 62 |
connect(serialHelper, SIGNAL(Serial_Disconnected()), this, SIGNAL(Serial_Disconnected()));
|
62 |
connect(serialHelper, SIGNAL(Disconnected()), this, SIGNAL(Disconnected()));
|
| 63 |
connect(serialHelper, SIGNAL(Serial_Disconnected()), this, SLOT(Serial_LocalDisconnected()));
|
63 |
connect(serialHelper, SIGNAL(Disconnected()), this, SLOT(LocalDisconnected()));
|
| 64 |
|
64 |
|
| 65 |
connect(this, SIGNAL(Serial_TransmitByteArray(QByteArray)), serialHelper, SLOT(Serial_TransmitByteArray(QByteArray)));
|
65 |
connect(this, SIGNAL(TransmitByteArray(QByteArray)), serialHelper, SLOT(TransmitByteArray(QByteArray)));
|
| 66 |
|
66 |
|
| 67 |
connect(serialHelper, SIGNAL(Serial_ReceivedByte(char)), this, SIGNAL(Serial_ReceivedByte(char)));
|
67 |
connect(serialHelper, SIGNAL(ReceivedByte(QByteArray)), this, SIGNAL(ReceivedByte(QByteArray)));
|
| 68 |
|
68 |
|
| 69 |
connect(serialThread, SIGNAL(finished()), serialHelper, SLOT(deleteLater()));
|
69 |
connect(serialThread, SIGNAL(finished()), serialHelper, SLOT(deleteLater()));
|
| 70 |
serialThread->start();
|
70 |
serialThread->start();
|
| 71 |
|
71 |
|
| 72 |
connect(btnSerialConnect, SIGNAL(clicked()), this, SLOT(Serial_ConnectToggleBtn()));
|
72 |
connect(btnConnect, SIGNAL(clicked()), this, SLOT(ConnectToggleBtn()));
|
| 73 |
connect(btnSerialRefresh, SIGNAL(clicked()), this, SIGNAL(Serial_QueryParameters()));
|
73 |
connect(btnRefresh, SIGNAL(clicked()), this, SIGNAL(QueryParameters()));
|
| 74 |
|
74 |
|
| 75 |
emit Serial_QueryParameters();
|
75 |
emit QueryParameters();
|
| 76 |
Serial_LocalDisconnected();
|
76 |
LocalDisconnected();
|
| 77 |
}
|
77 |
}
|
| 78 |
|
78 |
|
| 79 |
SerialWidget::~SerialWidget()
|
79 |
SerialWidget::~SerialWidget()
|
| 80 |
{
|
80 |
{
|
| 81 |
serialThread->quit();
|
81 |
serialThread->quit();
|
| 82 |
}
|
82 |
}
|
| 83 |
|
83 |
|
| 84 |
void SerialWidget::Serial_UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
|
84 |
void SerialWidget::UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
|
| 85 |
QStringList stopBits, QStringList parity, QStringList flowControl)
|
85 |
QStringList stopBits, QStringList parity, QStringList flowControl)
|
| 86 |
{
|
86 |
{
|
| 87 |
QString currPort = cboxSerialPort->currentText();
|
87 |
QString currPort = cboxPort->currentText();
|
| 88 |
cboxSerialPort->clear();
|
88 |
cboxPort->clear();
|
| 89 |
cboxSerialPort->addItems(ports);
|
89 |
cboxPort->addItems(ports);
|
| 90 |
if (currPort != "" && ports.contains(currPort))
|
90 |
if (currPort != "" && ports.contains(currPort))
|
| 91 |
cboxSerialPort->setCurrentText(currPort);
|
91 |
cboxPort->setCurrentText(currPort);
|
| 92 |
|
92 |
|
| 93 |
QString currSpeed = cboxSerialSpeed->currentText();
|
93 |
QString currSpeed = cboxSpeed->currentText();
|
| 94 |
cboxSerialSpeed->clear();
|
94 |
cboxSpeed->clear();
|
| 95 |
cboxSerialSpeed->addItems(speeds);
|
95 |
cboxSpeed->addItems(speeds);
|
| 96 |
if (currSpeed != "") cboxSerialSpeed->setCurrentText(currSpeed);
|
96 |
if (currSpeed != "") cboxSpeed->setCurrentText(currSpeed);
|
| 97 |
|
97 |
|
| 98 |
int currData = cboxSerialDataBits->currentIndex();
|
98 |
int currData = cboxDataBits->currentIndex();
|
| 99 |
cboxSerialDataBits->clear();
|
99 |
cboxDataBits->clear();
|
| 100 |
cboxSerialDataBits->addItems(dataBits);
|
100 |
cboxDataBits->addItems(dataBits);
|
| 101 |
if (currData >= 0) cboxSerialDataBits->setCurrentIndex(currData);
|
101 |
if (currData >= 0) cboxDataBits->setCurrentIndex(currData);
|
| 102 |
|
102 |
|
| 103 |
int currStop = cboxSerialStopBits->currentIndex();
|
103 |
int currStop = cboxStopBits->currentIndex();
|
| 104 |
cboxSerialStopBits->clear();
|
104 |
cboxStopBits->clear();
|
| 105 |
cboxSerialStopBits->addItems(stopBits);
|
105 |
cboxStopBits->addItems(stopBits);
|
| 106 |
if (currStop >= 0) cboxSerialStopBits->setCurrentIndex(currStop);
|
106 |
if (currStop >= 0) cboxStopBits->setCurrentIndex(currStop);
|
| 107 |
|
107 |
|
| 108 |
int currParity = cboxSerialParity->currentIndex();
|
108 |
int currParity = cboxParity->currentIndex();
|
| 109 |
cboxSerialParity->clear();
|
109 |
cboxParity->clear();
|
| 110 |
cboxSerialParity->addItems(parity);
|
110 |
cboxParity->addItems(parity);
|
| 111 |
if (currParity >= 0) cboxSerialParity->setCurrentIndex(currParity);
|
111 |
if (currParity >= 0) cboxParity->setCurrentIndex(currParity);
|
| 112 |
|
112 |
|
| 113 |
int currFlow = cboxSerialFlowControl->currentIndex();
|
113 |
int currFlow = cboxFlowControl->currentIndex();
|
| 114 |
cboxSerialFlowControl->clear();
|
114 |
cboxFlowControl->clear();
|
| 115 |
cboxSerialFlowControl->addItems(flowControl);
|
115 |
cboxFlowControl->addItems(flowControl);
|
| 116 |
if (currFlow >= 0) cboxSerialFlowControl->setCurrentIndex(currFlow);
|
116 |
if (currFlow >= 0) cboxFlowControl->setCurrentIndex(currFlow);
|
| 117 |
}
|
117 |
}
|
| 118 |
|
118 |
|
| 119 |
void SerialWidget::Serial_LocalConnected()
|
119 |
void SerialWidget::LocalConnected()
|
| 120 |
{
|
120 |
{
|
| 121 |
btnSerialConnect->setText("&Disconnect");
|
121 |
btnConnect->setText("&Disconnect");
|
| 122 |
// cboxSerialPort->setEnabled(false);
|
122 |
// cboxSerialPort->setEnabled(false);
|
| 123 |
// cboxSerialSpeed->setEnabled(false);
|
123 |
// cboxSerialSpeed->setEnabled(false);
|
| 124 |
// cboxSerialDataBits->setEnabled(false);
|
124 |
// cboxSerialDataBits->setEnabled(false);
|
| 125 |
// cboxSerialStopBits->setEnabled(false);
|
125 |
// cboxSerialStopBits->setEnabled(false);
|
| 126 |
// cboxSerialParity->setEnabled(false);
|
126 |
// cboxSerialParity->setEnabled(false);
|
| 127 |
// cboxSerialFlowControl->setEnabled(false);
|
127 |
// cboxSerialFlowControl->setEnabled(false);
|
| 128 |
// btnSerialRefresh->setEnabled(false);
|
128 |
// btnSerialRefresh->setEnabled(false);
|
| 129 |
btnSerialRefresh->hide();
|
129 |
btnRefresh->hide();
|
| 130 |
labelSerialPort->hide();
|
130 |
labelPort->hide();
|
| 131 |
labelSerialSpeed->hide();
|
131 |
labelSpeed->hide();
|
| 132 |
labelSerialDataBits->hide();
|
132 |
labelDataBits->hide();
|
| 133 |
labelSerialStopBits->hide();
|
133 |
labelStopBits->hide();
|
| 134 |
labelSerialParity->hide();
|
134 |
labelParity->hide();
|
| 135 |
labelSerialFlowControl->hide();
|
135 |
labelFlowControl->hide();
|
| 136 |
cboxSerialPort->hide();
|
136 |
cboxPort->hide();
|
| 137 |
cboxSerialSpeed->hide();
|
137 |
cboxSpeed->hide();
|
| 138 |
cboxSerialDataBits->hide();
|
138 |
cboxDataBits->hide();
|
| 139 |
cboxSerialStopBits->hide();
|
139 |
cboxStopBits->hide();
|
| 140 |
cboxSerialParity->hide();
|
140 |
cboxParity->hide();
|
| 141 |
cboxSerialFlowControl->hide();
|
141 |
cboxFlowControl->hide();
|
| 142 |
}
|
142 |
}
|
| 143 |
|
143 |
|
| 144 |
void SerialWidget::Serial_LocalDisconnected()
|
144 |
void SerialWidget::LocalDisconnected()
|
| 145 |
{
|
145 |
{
|
| 146 |
btnSerialConnect->setText("&Connect");
|
146 |
btnConnect->setText("&Connect");
|
| 147 |
// cboxSerialPort->setEnabled(true);
|
147 |
// cboxSerialPort->setEnabled(true);
|
| 148 |
// cboxSerialSpeed->setEnabled(true);
|
148 |
// cboxSerialSpeed->setEnabled(true);
|
| 149 |
// cboxSerialDataBits->setEnabled(true);
|
149 |
// cboxSerialDataBits->setEnabled(true);
|
| 150 |
// cboxSerialStopBits->setEnabled(true);
|
150 |
// cboxSerialStopBits->setEnabled(true);
|
| 151 |
// cboxSerialParity->setEnabled(true);
|
151 |
// cboxSerialParity->setEnabled(true);
|
| 152 |
// cboxSerialFlowControl->setEnabled(true);
|
152 |
// cboxSerialFlowControl->setEnabled(true);
|
| 153 |
// btnSerialRefresh->setEnabled(true);
|
153 |
// btnSerialRefresh->setEnabled(true);
|
| 154 |
btnSerialRefresh->show();
|
154 |
btnRefresh->show();
|
| 155 |
labelSerialPort->show();
|
155 |
labelPort->show();
|
| 156 |
labelSerialSpeed->show();
|
156 |
labelSpeed->show();
|
| 157 |
labelSerialDataBits->show();
|
157 |
labelDataBits->show();
|
| 158 |
labelSerialStopBits->show();
|
158 |
labelStopBits->show();
|
| 159 |
labelSerialParity->show();
|
159 |
labelParity->show();
|
| 160 |
labelSerialFlowControl->show();
|
160 |
labelFlowControl->show();
|
| 161 |
cboxSerialPort->show();
|
161 |
cboxPort->show();
|
| 162 |
cboxSerialSpeed->show();
|
162 |
cboxSpeed->show();
|
| 163 |
cboxSerialDataBits->show();
|
163 |
cboxDataBits->show();
|
| 164 |
cboxSerialStopBits->show();
|
164 |
cboxStopBits->show();
|
| 165 |
cboxSerialParity->show();
|
165 |
cboxParity->show();
|
| 166 |
cboxSerialFlowControl->show();
|
166 |
cboxFlowControl->show();
|
| 167 |
}
|
167 |
}
|
| 168 |
|
168 |
|
| 169 |
void SerialWidget::Serial_ConnectToggleBtn()
|
169 |
void SerialWidget::ConnectToggleBtn()
|
| 170 |
{
|
170 |
{
|
| 171 |
if (serialHelper->connected) {
|
171 |
if (serialHelper->connected) {
|
| 172 |
emit Serial_Disconnect();
|
172 |
emit Disconnect();
|
| 173 |
} else {
|
173 |
} else {
|
| 174 |
if (cboxSerialPort->currentText() != "" && cboxSerialSpeed->currentText() != "") {
|
174 |
if (cboxPort->currentText() != "" && cboxSpeed->currentText() != "") {
|
| 175 |
emit Serial_Connect(cboxSerialPort->currentText(), cboxSerialSpeed->currentText(), cboxSerialDataBits->currentText(),
|
175 |
emit Connect(cboxPort->currentText(), cboxSpeed->currentText(), cboxDataBits->currentText(),
|
| 176 |
cboxSerialStopBits->currentText(), cboxSerialParity->currentText(), cboxSerialFlowControl->currentText());
|
176 |
cboxStopBits->currentText(), cboxParity->currentText(), cboxFlowControl->currentText());
|
| 177 |
}
|
177 |
}
|
| 178 |
}
|
178 |
}
|
| 179 |
}
|
179 |
}
|
| 180 |
|
180 |
|
| 181 |
//void SerialController::Serial_ProcessIncomingData()
|
181 |
//void SerialController::Serial_ProcessIncomingData()
|