-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
734 lines (648 loc) · 20 KB
/
mainwindow.cpp
File metadata and controls
734 lines (648 loc) · 20 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
#include "mainwindow.h"
#include "ui_mainwindow.h"
void stringTohexString(QString& str, QString& hexStr)
{
}
int hexStringToString(QString& hexStr, QString& str)
{
int ret = 0;
bool ok;
QByteArray retByte;
hexStr = hexStr.trimmed();
hexStr = hexStr.simplified();
QStringList sl = hexStr.split(" ");
foreach (QString s, sl)
{
if(!s.isEmpty())
{
char c = (s.toInt(&ok,16))&0xFF;
if (ok)
{
retByte.append(c);
}
else
{
ret = -1;
}
}
}
str = retByte;
return ret;
}
int hexStringToHexArray(QString& hexStr, QByteArray& arr)
{
int ret = 0;
bool ok;
hexStr = hexStr.trimmed();
hexStr = hexStr.simplified();
QStringList sl = hexStr.split(" ");
foreach (QString s, sl)
{
if(!s.isEmpty())
{
char c = (s.toInt(&ok,16))&0xFF;
if (ok)
{
arr.append(c);
}
else
{
ret = -1;
}
}
}
return ret;
}
int hexArrayToString(QByteArray& hexArr, QString& str)
{
int ret = 0;
str = hexArr.toHex(' ').toLower();
return ret;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
initMainWindow();
initStatusBar();
initWindow();
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
if (watched == m_stsExit) // 程序退出
{
//判断事件
if(event->type() == QEvent::MouseButtonPress)
{
// TODO:直接退出还是发信号?
emit sig_exit();
return true; // 事件处理完毕
}
else
{
return false;
}
}
else if (watched == m_stsResetCnt)
{
if(event->type() == QEvent::MouseButtonPress)
{
m_stsRx->setText("RX: 0");
m_stsTx->setText("TX: 0");
m_rxCnt = m_txCnt = 0;
return true;
}
else
{
return false;
}
}
else
{
return QWidget::eventFilter(watched, event);
}
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
//当鼠标左键点击时.
if (event->button() == Qt::LeftButton)
{
//记录鼠标的世界坐标
m_startPos = event->globalPos();
//记录窗体的世界坐标
m_windowPos = this->frameGeometry().topLeft();
m_pressMouse = 1;
}
else if(event->button() == Qt::RightButton)
{
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton)
{
if (m_pressMouse)
{
//移动中的鼠标位置相对于初始位置的相对位置
QPoint relativePos = event->globalPos() - m_startPos;
//然后移动窗体即可
this->move(m_windowPos + relativePos );
}
}
else if(event->button() == Qt::RightButton)
{
}
}
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
m_pressMouse = 0;
}
// 对主窗口的初始化
void MainWindow::initMainWindow()
{
setWindowTitle(tr("QtSerialPort"));
setMinimumSize(480, 320);
Qt::WindowFlags winFlags = Qt::Dialog;
winFlags = winFlags | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint;
setWindowFlags(winFlags);
}
void MainWindow::initWindow()
{
m_pressMouse = 0;
m_recvHex = 0;
m_sendHex = 0;
m_sendTimer = 0;
m_sendTimerId = 0;
m_showTimestamp = 0;
m_sendNewline = 0;
m_rxCnt = 0;
m_txCnt = 0;
/////////////////////////////////////////////////////////////
QStringList list;
list.clear();
list << "2400" << "4800" << "9600" << "14400" << \
"19200" << "38400" << "43000" << "57600" << "76800" << \
"115200" << "230400" << "256000" << "460800" << "921600";
ui->cbBaudrate->addItems(list);
ui->cbBaudrate->setCurrentText(tr("115200"));
list.clear();
list << "5" << "6" << "7" << "8";
ui->cbDatabit->addItems(list);
ui->cbDatabit->setCurrentText(tr("8"));
list.clear();
list << "1" << "1.5" << "2";
ui->cbStopbit->addItems(list);
ui->cbStopbit->setCurrentText(tr("1"));
list.clear();
list << "none" << "odd" << "even";
ui->cbParity->addItems(list);
ui->cbParity->setCurrentText(tr("none"));
list.clear();
list << "off" << "hardware" << "software";
ui->cbFlow->addItems(list);
ui->cbFlow->setCurrentText(tr("off"));
ui->btnOpen->setText(tr("打开串口"));
ui->btnOpen->setIconSize(ui->btnOpen->rect().size());
ui->btnOpen->setIcon(QIcon(":images/notopened.ico"));
//ui->ckRecvHex->setCheckState(Qt::Checked);
ui->txtInterval->setText("1000");
ui->txtRecv->setPlaceholderText("Receive data here");
ui->txtSend->setPlaceholderText("Send data here");
ui->txtSend->setPlainText("hello world");
//////////////////////////////////////////////////////////////
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
{
if (-1 == ui->cbPortName->findText(info.portName()))
ui->cbPortName->addItem(info.portName());
}
serial.close(); // try close
serial.setReadBufferSize(8192);
serial.setSettingsRestoredOnClose(false);
//连接信号和槽
QObject::connect(&serial, &QSerialPort::readyRead, this, &MainWindow::readyRead);
QObject::connect(this, &MainWindow::sig_deviceChanged, this, &MainWindow::on_deviceChanged);
// 注册各类设备,可根据要求删减
#if 01
static const GUID GUID_DEVINTERFACE_LIST[] =
{
// GUID_DEVINTERFACE_USB_DEVICE
{ 0xA5DCBF10, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } },
// GUID_DEVINTERFACE_DISK
{ 0x53f56307, 0xb6bf, 0x11d0, { 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b } },
// GUID_DEVINTERFACE_HID,
{ 0x4D1E55B2, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } },
// GUID_NDIS_LAN_CLASS
{ 0xad498944, 0x762f, 0x11d0, { 0x8d, 0xcb, 0x00, 0xc0, 0x4f, 0xc3, 0x35, 0x8c } }
//// GUID_DEVINTERFACE_COMPORT
//{ 0x86e0d1e0, 0x8089, 0x11d0, { 0x9c, 0xe4, 0x08, 0x00, 0x3e, 0x30, 0x1f, 0x73 } },
//// GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR
//{ 0x4D36E978, 0xE325, 0x11CE, { 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 } },
//// GUID_DEVINTERFACE_PARALLEL
//{ 0x97F76EF0, 0xF883, 0x11D0, { 0xAF, 0x1F, 0x00, 0x00, 0xF8, 0x00, 0x84, 0x5C } },
//// GUID_DEVINTERFACE_PARCLASS
//{ 0x811FC6A5, 0xF728, 0x11D0, { 0xA5, 0x37, 0x00, 0x00, 0xF8, 0x75, 0x3E, 0xD1 } }
};
//注册插拔事件
HDEVNOTIFY hDevNotify;
DEV_BROADCAST_DEVICEINTERFACE NotifacationFiler;
ZeroMemory(&NotifacationFiler,sizeof(DEV_BROADCAST_DEVICEINTERFACE));
NotifacationFiler.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotifacationFiler.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
for(int i=0;i<sizeof(GUID_DEVINTERFACE_LIST)/sizeof(GUID);i++)
{
NotifacationFiler.dbcc_classguid = GUID_DEVINTERFACE_LIST[i];//GetCurrentUSBGUID();//m_usb->GetDriverGUID();
hDevNotify = RegisterDeviceNotification((HANDLE)this->winId(),&NotifacationFiler,DEVICE_NOTIFY_WINDOW_HANDLE);
if(!hDevNotify)
{
DWORD Err = GetLastError();
//qDebug() << "注册失败" <<endl;
}
//else
}
#endif
on_btnOpen_clicked(); // todo
}
void MainWindow::initStatusBar()
{
// 状态栏分别为:
// 提示信息(可多个)
// RX、TX
// 版本信息(或版权声明)
// 退出图标
ui->statusbar->setMinimumHeight(22);
//ui->statusbar->setStyleSheet(QString("QStatusBar::item{border: 0px}")); // 不显示边框
ui->statusbar->setSizeGripEnabled(false);//去掉状态栏右下角的三角
m_stsDebugInfo = new QLabel();
m_stsRx = new QLabel();
m_stsTx = new QLabel();
m_stsResetCnt = new QLabel();
m_stsCopyright = new QLabel();
m_stsExit = new QLabel();
m_stsDebugInfo->setMinimumWidth(this->width()/2);
ui->statusbar->addWidget(m_stsDebugInfo);
m_stsRx->setMinimumWidth(64);
ui->statusbar->addPermanentWidget(m_stsRx);
m_stsRx->setText("RX: 0");
m_stsTx->setMinimumWidth(64);
ui->statusbar->addPermanentWidget(m_stsTx);
m_stsTx->setText("TX: 0");
m_stsResetCnt->installEventFilter(this);
m_stsResetCnt->setFrameStyle(QFrame::Plain);
m_stsResetCnt->setText("复位计数");
m_stsResetCnt->setMinimumWidth(100);
ui->statusbar->addPermanentWidget(m_stsResetCnt);
printDebugInfo("欢迎使用串口调试助手");
// 版权信息
m_stsCopyright->setFrameStyle(QFrame::NoFrame);
m_stsCopyright->setText(tr(" <a href=\"https://www.latelee.org\">技术主页</a> "));
m_stsCopyright->setOpenExternalLinks(true);
ui->statusbar->addPermanentWidget(m_stsCopyright);
// 退出图标
m_stsExit->installEventFilter(this); // 安装事件过滤,以便获取其单击事件
m_stsExit->setToolTip("Exit App");
m_stsExit->setMinimumWidth(32);
// 贴图
QPixmap exitIcon(":/images/exit.png");
m_stsExit->setPixmap(exitIcon);
ui->statusbar->addPermanentWidget(m_stsExit);
connect(this, &MainWindow::sig_exit, qApp, &QApplication::quit); // 直接关联到全局的退出槽
}
void MainWindow::printDebugInfo(const char* str)
{
QString tmp = str;
m_stsDebugInfo->setText(tmp);
}
void MainWindow::showMessage(const char* str)
{
QString tmp = str;
ui->statusbar->showMessage(tmp, 500);
}
void MainWindow::timerEvent(QTimerEvent *event)
{
//qDebug() << "Timer ID:" << event->timerId();
sendData();
}
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
MSG* msg = reinterpret_cast<MSG*>(message);
int msgType = msg->message;
if(msgType==WM_DEVICECHANGE) // 设备插入事件
{
//qDebug() << "Event DEVICECHANGE Happend" << endl;
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)msg->lParam;
switch (msg->wParam) {
case DBT_DEVICEARRIVAL:
if(lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
if(lpdbv->dbcv_flags == 0) //插入u盘
{
}
}
if(lpdb->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{
//PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)lpdb;
//QString strname = QString::fromWCharArray(pDevInf->dbcc_name,pDevInf->dbcc_size);
//qDebug() << "arrive" + strname;
showMessage("USB device arrive");
emit sig_deviceChanged(1);
}
break;
case DBT_DEVICEREMOVECOMPLETE: // 设备移除事件
if(lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
if(lpdbv->dbcv_flags == 0)
{
}
}
if(lpdb->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{
//PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)lpdb;
//QString strname = QString::fromWCharArray(pDevInf->dbcc_name,pDevInf->dbcc_size);
showMessage("USB device removed");
emit sig_deviceChanged(0);
}
break;
}
}
return false;
}
void MainWindow::sendData()
{
if (!serial.isOpen())
{
showMessage("serial port not opened.");
return;
}
QString sendStr = ui->txtSend->toPlainText().toLatin1().toLower();
QByteArray sendData;
QString showStr;
if (m_sendHex == 1)
{
hexStringToHexArray(sendStr, sendData);
}
else if (m_sendHex == 0)
{
sendData = sendStr.toLatin1();
}
if (m_sendNewline == 1)
{
sendData.append(0x0d);
sendData.append(0x0a);
}
//qDebug() << sendData;
m_txCnt += sendData.size();
m_stsTx->setText("TX: " + QString::number(m_txCnt));
serial.write(sendData);
}
void MainWindow::sendHexData(QString& tips, uint8_t* ibuf, uint8_t ilen)
{
QByteArray sendData;
for (int i = 0; i < ilen; i++)
{
sendData[i] = ibuf[i];
}
QString tmp = sendData.toHex(' ').toLower();
serial.write(sendData);
//ui->txtSend->appendPlainText(tips + tmp);
}
void MainWindow::readyRead()
{
QByteArray buffer = serial.readAll();
QString info;
QString tmpStr;
QString timeStr = "";
m_rxCnt += buffer.size();
m_stsRx->setText("RX: " + QString::number(m_rxCnt));
if (m_showTimestamp)
{
QDateTime dateTime(QDateTime::currentDateTime());
timeStr = "[" + dateTime.toString("yyyy-MM-dd HH:mm:ss.zzz") + "] ";
}
if (m_recvHex == 1)
{
info = buffer.toHex(' ').data();
// for (int i = 0; i < buffer.size(); i++)
// {
// tmpStr.sprintf("%02x ", buffer.at(i));
// qDebug() << buffer.at(i);
// info.append(tmpStr);
// }
}
else
{
info = QString(buffer);
}
ui->txtRecv->appendPlainText(timeStr + info);
// TODO
// 似乎直接用QByteArray无法直接取真正的值
// 这里先转为数组,再判断,需要优化
uint8_t *data = (uint8_t*)buffer.data();
uint8_t buf[255] = {0};
for (int i = 0; i < buffer.size(); i++)
{
buf[i] = data[i];
//qDebug("%x ", buf[i]);
}
// 根据值判断做逻辑处理,可做成函数
if (buf[0] == 0xaa && buf[1] == 0x55)
{
}
}
void MainWindow::on_deviceChanged(int flag)
{
if (flag == 1)
{
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
{
if (-1 == ui->cbPortName->findText(info.portName()))
ui->cbPortName->addItem(info.portName());
}
}
else
{
serial.close();
ui->btnOpen->setText(tr("打开串口"));
ui->btnOpen->setIcon(QIcon(":images/notopened.ico"));
}
}
void MainWindow::on_btnOpen_clicked()
{
if(ui->btnOpen->text()==QString("打开串口"))
{
// 串口设备
on_cbPortName_currentTextChanged(ui->cbPortName->currentText());
// 波特率(注:QtSerial支持的枚举不多,但设置了其它值也行)
on_cbBaudrate_currentTextChanged(ui->cbBaudrate->currentText());
//设置数据位
on_cbDatabit_currentTextChanged(ui->cbDatabit->currentText());
//设置停止位
on_cbStopbit_currentIndexChanged(ui->cbStopbit->currentIndex());
//设置奇偶校验
on_cbParity_currentIndexChanged(ui->cbParity->currentIndex());
//设置流控制
on_cbFlow_currentIndexChanged(ui->cbFlow->currentIndex());
// 打开串口
if(!serial.open(QIODevice::ReadWrite) && !serial.isOpen())
{
//QMessageBox::about(NULL, tr("info"), tr("open port failed."));
showMessage("open port failed.\n");
return;
}
showMessage("port opened.");
ui->btnOpen->setText(tr("关闭串口"));
ui->btnOpen->setIcon(QIcon(":images/opened.ico"));
}
else
{
serial.close();
showMessage("port closed.");
ui->btnOpen->setText(tr("打开串口"));
ui->btnOpen->setIcon(QIcon(":images/notopened.ico"));
}
}
void MainWindow::on_btnSaveRecv_clicked()
{
}
void MainWindow::on_btnClearRecv_clicked()
{
ui->txtRecv->clear();
}
void MainWindow::on_ckRecvHex_stateChanged(int arg1)
{
if (arg1 == Qt::Checked)
{
m_recvHex = 1;
}
else if (arg1 == Qt::Unchecked)
{
m_recvHex = 0;
}
}
void MainWindow::on_ckTimestamp_stateChanged(int arg1)
{
if (arg1 == Qt::Checked)
{
m_showTimestamp = 1;
}
else if (arg1 == Qt::Unchecked)
{
m_showTimestamp = 0;
}
}
void MainWindow::on_btnSend_clicked()
{
if (m_sendTimer)
{
if(ui->btnSend->text()==QString("发送"))
{
if (m_sendTimerId == 0)
m_sendTimerId = startTimer(ui->txtInterval->text().toInt());
ui->btnSend->setText(tr("停止发送"));
}
else
{
if (m_sendTimerId)
{
killTimer(m_sendTimerId);
m_sendTimerId = 0;
}
ui->btnSend->setText(tr("发送"));
}
}
else
{
sendData();
}
}
void MainWindow::on_btnClearSend_clicked()
{
ui->txtSend->clear();
}
void MainWindow::on_chSendHex_stateChanged(int arg1)
{
QString sendStr = ui->txtSend->toPlainText().toLatin1().toLower();
QByteArray sendData = sendStr.toLatin1();//ui->txtSend->toPlainText().toLatin1();
QString tmpStr;
QString showStr;
//qDebug() << sendStr;
//qDebug() << sendData;
if (arg1 == Qt::Checked)
{
m_sendHex = 1;
showStr = sendData.toHex(' ').data();
}
else if (arg1 == Qt::Unchecked)
{
m_sendHex = 0;
hexStringToString(sendStr, showStr); // 用string来转
}
ui->txtSend->setPlainText(showStr);
}
void MainWindow::on_ckSendTimer_stateChanged(int arg1)
{
if (arg1 == Qt::Checked)
{
m_sendTimer = 1;
}
else if (arg1 == Qt::Unchecked)
{
m_sendTimer = 0;
if (m_sendTimerId)
{
killTimer(m_sendTimerId);
m_sendTimerId = 0;
ui->btnSend->setText("发送");
}
}
}
void MainWindow::on_cbPortName_currentTextChanged(const QString &arg1)
{
serial.setPortName(arg1);
}
void MainWindow::on_cbBaudrate_currentTextChanged(const QString &arg1)
{
serial.setBaudRate(arg1.toInt());
}
void MainWindow::on_cbDatabit_currentTextChanged(const QString &arg1)
{
switch(arg1.toInt())
{
case 8: serial.setDataBits(QSerialPort::Data8); break;
case 7: serial.setDataBits(QSerialPort::Data7); break;
case 6: serial.setDataBits(QSerialPort::Data6); break;
case 5: serial.setDataBits(QSerialPort::Data5); break;
default: break;
}
}
void MainWindow::on_cbStopbit_currentIndexChanged(int index)
{
//qDebug()<< index;
//设置停止位
switch(index)
{
case 0: serial.setStopBits(QSerialPort::OneStop); break;
case 1: serial.setStopBits(QSerialPort::OneAndHalfStop); break;
case 2: serial.setStopBits(QSerialPort::TwoStop); break;
default: break;
}
}
void MainWindow::on_cbParity_currentIndexChanged(int index)
{
//设置奇偶校验
switch(index)
{
case 0: serial.setParity(QSerialPort::NoParity); break;
case 1: serial.setParity(QSerialPort::OddParity); break;
case 2: serial.setParity(QSerialPort::EvenParity); break;
default: break;
}
}
void MainWindow::on_cbFlow_currentIndexChanged(int index)
{
//设置流控制
switch(index)
{
case 0: serial.setFlowControl(QSerialPort::NoFlowControl); break;
case 1: serial.setFlowControl(QSerialPort::HardwareControl); break;
case 2: serial.setFlowControl(QSerialPort::SoftwareControl); break;
default: break;
}
}
void MainWindow::on_chSendNewline_stateChanged(int arg1)
{
if (arg1 == Qt::Checked)
{
m_sendNewline = 1;
}
else if (arg1 == Qt::Unchecked)
{
m_sendNewline = 0;
}
}