-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainwidget.cpp
1895 lines (1664 loc) · 88.4 KB
/
mainwidget.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
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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwidget.h"
#include <QApplication>
using namespace std;
string MainWidget::getDate()
{
time_t timep;
time (&timep);
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y-%m-%d",localtime(&timep) );
return tmp;
}
string MainWidget::getTime()
{
time_t timep;
time (&timep);
char tmp[64];
strftime(tmp, sizeof(tmp), "%H:%M:%S",localtime(&timep) );
return tmp;
}
int xinlv1=0,huxi1=0,xinlv2=0,huxi2=0,xinlv3=0,huxi3=0,xinlv4=0,huxi4=0;
bool MainWidget::OpenDatabase()
{
db = QSqlDatabase::addDatabase("QODBC"); //数据库驱动类型为SQL Server
qDebug()<<"ODBC driver?"<<db.isValid();
QString dsn = QString::fromLocal8Bit("kqq"); //数据源名称
db.setHostName("10.1.149.15"); //选择本地主机,127.0.1.1
db.setDatabaseName(dsn); //设置数据源名称
db.setUserName("sa"); //登录用户
db.setPassword("123456"); //密码
if(!db.open()) //打开数据库
{
qDebug()<<db.lastError().text();
QMessageBox::critical(0, QObject::tr("Database error"), db.lastError().text());
return false; //打开失败
}
else
{
qDebug()<<"database open success!";
QSqlQuery query(db); //查询表并输出,测试能否正常操作数据库
query.exec("select * from 雷达阈值信息_info where 床位ID=1 or 床位ID=2 or 床位ID=3 or 床位ID=4");
if (query.next())
{
xinlv1=query.value(1).toInt();
huxi1=query.value(2).toInt();
}
if (query.next())
{
xinlv2=query.value(1).toInt();
huxi2=query.value(2).toInt();
}
if (query.next())
{
xinlv3=query.value(1).toInt();
huxi3=query.value(2).toInt();
}
if (query.next())
{
xinlv4=query.value(1).toInt();
huxi4=query.value(2).toInt();
}
return true; //打开成功
}
}
MainWidget::MainWidget(QWidget *parent)
: QWidget(parent), settings("TurnMeOn", "SerialAsst")
{
//初始化各参数列表
isOpenDataBase = OpenDatabase(); //首先判断数据库是否打开
if(isOpenDataBase){
QMessageBox::information(this, QString::fromUtf8("提示"),QString::fromUtf8("数据库打开成功"));
}
else {
QMessageBox::information(this, QString::fromUtf8("提示"),QString::fromUtf8("数据库打开失败"));
}
BaudrateList << "256000"
<< "230400"
<< "128000"
<< "115200"
<< "76800"
<< "57600"
<< "43000"
<< "38400"
<< "19200"
<< "14400"
<< "9600"
<< "4800"
<< "2400"
<< "1200";
StopbitsList << "1"
<< "1.5"
<< "2";
DatabitsList << "8"
<< "7"
<< "6"
<< "5";
ParityList << tr("无") << tr("奇校验") << tr("偶校验");
//初始化ComboBox以及波特率信息的复选框
COMBox1 = new QComboBox();
COMBox2 = new QComboBox();
COMBox3 = new QComboBox();
COMBox4 = new QComboBox();
BaudrateBox = new QComboBox();
BaudrateBox->addItems(BaudrateList);
BaudrateBox->setCurrentIndex(settings.value("Baud rate", 0).toInt());
StopbitsBox = new QComboBox();
StopbitsBox->addItems(StopbitsList);
StopbitsBox->setCurrentIndex(settings.value("Stop bits", 0).toInt());
DatabitsBox = new QComboBox();
DatabitsBox->addItems(DatabitsList);
DatabitsBox->setCurrentIndex(settings.value("Data bits", 0).toInt());
ParityBox = new QComboBox();
ParityBox->addItems(ParityList);
ParityBox->setCurrentIndex(settings.value("Parity", 0).toInt());
//初始化label
QPalette palLabel;
palLabel.setColor(QPalette::WindowText,Qt::yellow);
//初始化字体
QFont ft;
ft.setFamily("宋体");
//设置文字大小为50像素
ft.setPixelSize(16);
//设置文字为粗体
ft.setBold(true); //封装的setWeight函数
//第1个串口号的所选Com口号显示
COMLabel1 = new QLabel(tr("串口号 : 无 "));
COMLabel1->setMinimumWidth(130); //设置最小宽度
COMLabel1->setPalette(palLabel); //字体颜色
COMLabel1->setFont(ft); //设置字体
COMLabel1->setStyleSheet("background-color:blue"); //底色
//第2个串口号的所选Com口号显示
COMLabel2 = new QLabel(tr("串口号 : 无 "));
COMLabel2->setMinimumWidth(130);
COMLabel2->setPalette(palLabel); //字体颜色
COMLabel2->setFont(ft); //设置字体
COMLabel2->setStyleSheet("background-color:blue"); //底色
//第3个串口号的所选Com口号显示
COMLabel3 = new QLabel(tr("串口号 : 无 "));
COMLabel3->setMinimumWidth(130);
COMLabel3->setPalette(palLabel); //字体颜色
COMLabel3->setFont(ft); //设置字体
COMLabel3->setStyleSheet("background-color:blue"); //底色
//第4个串口号的所选Com口号显示
COMLabel4 = new QLabel(tr("串口号 : 无 "));
COMLabel4->setMinimumWidth(130);
COMLabel4->setPalette(palLabel); //字体颜色
COMLabel4->setFont(ft); //设置字体
COMLabel4->setStyleSheet("background-color:blue"); //底色
BaudrateLabel = new QLabel(tr("波特率"));
StopbitsLabel = new QLabel(tr("停止位"));
DatabitsLabel = new QLabel(tr("数据位"));
ParityLabel = new QLabel(tr("校验位"));
/*******************下面的信息每一个床位的相关信息标签**************************/
BedLabel1 = new QLabel(tr(" 1号床位\n\n : 离床"));
BedLabel1->setPalette(palLabel); //字体颜色
BedLabel1->setFont(ft); //设置字体
BedLabel1->setStyleSheet("background-color:blue"); //底色
LightLabel1 = new QLabel(tr(" "));
LightLabel1->setPalette(palLabel); //字体颜色
LightLabel1->setFont(ft); //设置字体
LightLabel1->setStyleSheet("background-color:red"); //底色
HeartRateLabel1 = new QLabel(tr(" 心率\n\n 无"));
HeartRateLabel1->setPalette(palLabel); //字体颜色
HeartRateLabel1->setFont(ft); //设置字体
HeartRateLabel1->setStyleSheet("background-color:blue"); //底色
BreathingLabel1 = new QLabel(tr(" 呼吸\n\n 无"));
BreathingLabel1->setPalette(palLabel); //字体颜色
BreathingLabel1->setFont(ft); //设置字体
BreathingLabel1->setStyleSheet("background-color:blue"); //底色
BedLabel2 = new QLabel(tr(" 2号床位\n\n : 离床"));
BedLabel2->setPalette(palLabel); //字体颜色
BedLabel2->setFont(ft); //设置字体
BedLabel2->setStyleSheet("background-color:blue"); //底色
LightLabel2 = new QLabel(tr(" "));
LightLabel2->setPalette(palLabel); //字体颜色
LightLabel2->setFont(ft); //设置字体
LightLabel2->setStyleSheet("background-color:red"); //底色
HeartRateLabel2 = new QLabel(tr(" 心率\n\n 无"));
HeartRateLabel2->setPalette(palLabel); //字体颜色
HeartRateLabel2->setFont(ft); //设置字体
HeartRateLabel2->setStyleSheet("background-color:blue"); //底色
BreathingLabel2 = new QLabel(tr(" 呼吸\n\n 无"));
BreathingLabel2->setPalette(palLabel); //字体颜色
BreathingLabel2->setFont(ft); //设置字体
BreathingLabel2->setStyleSheet("background-color:blue"); //底色
BedLabel3 = new QLabel(tr(" 3号床位\n\n : 离床"));
BedLabel3->setPalette(palLabel); //字体颜色
BedLabel3->setFont(ft); //设置字体
BedLabel3->setStyleSheet("background-color:blue"); //底色
LightLabel3 = new QLabel(tr(" "));
LightLabel3->setPalette(palLabel); //字体颜色
LightLabel3->setFont(ft); //设置字体
LightLabel3->setStyleSheet("background-color:red"); //底色
HeartRateLabel3 = new QLabel(tr(" 心率\n\n 无"));
HeartRateLabel3->setPalette(palLabel); //字体颜色
HeartRateLabel3->setFont(ft); //设置字体
HeartRateLabel3->setStyleSheet("background-color:blue"); //底色
BreathingLabel3 = new QLabel(tr(" 呼吸\n\n 无"));
BreathingLabel3->setPalette(palLabel); //字体颜色
BreathingLabel3->setFont(ft); //设置字体
BreathingLabel3->setStyleSheet("background-color:blue"); //底色
BedLabel4 = new QLabel(tr(" 4号床位\n\n : 离床"));
BedLabel4->setPalette(palLabel); //字体颜色
BedLabel4->setFont(ft); //设置字体
BedLabel4->setStyleSheet("background-color:blue"); //底色
LightLabel4 = new QLabel(tr(" "));
LightLabel4->setPalette(palLabel); //字体颜色
LightLabel4->setFont(ft); //设置字体
LightLabel4->setStyleSheet("background-color:red"); //底色
HeartRateLabel4 = new QLabel(tr(" 心率\n\n 无"));
HeartRateLabel4->setPalette(palLabel); //字体颜色
HeartRateLabel4->setFont(ft); //设置字体
HeartRateLabel4->setStyleSheet("background-color:blue"); //底色
BreathingLabel4 = new QLabel(tr(" 呼吸\n\n 无"));
BreathingLabel4->setPalette(palLabel); //字体颜色
BreathingLabel4->setFont(ft); //设置字体
BreathingLabel4->setStyleSheet("background-color:blue"); //底色
/************************上面的信息每一个床位的相关信息标签*********************************/
/*******************下面的信息是定义每一个床位的绘制心率和呼吸的容器**************************/
//1号床位的心率数据波形
plotHeartRate1 = new QCustomPlot();
plotHeartRate1->addGraph(); // 添加一个图表
// 设置关键点的显示效果
plotHeartRate1->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(QColor(41,138,220), 2), QBrush(QColor(5,189,251)), 10));
// 设置x轴显示时间
plotHeartRate1->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plotHeartRate1->xAxis->setDateTimeFormat("mm:ss"); //设置横坐标的显示时间的格式
plotHeartRate1->xAxis->setAutoTickStep(false); //禁止横坐标自动设置刻度间距
plotHeartRate1->xAxis->setTickStep(6); //设置横坐标的刻度间距
plotHeartRate1->yAxis->setRange(0,250); //设置纵坐标的显示范围
plotHeartRate1->yAxis->setAutoTickStep(false);//设置是否自动分配刻度间距
plotHeartRate1->yAxis->setTickStep(50); //设置刻度间距
// 设置轴的标题
plotHeartRate1->xAxis->setLabel("时间");
plotHeartRate1->yAxis->setLabel("心率");
//1号床位的呼吸数据波形
plotBreathing1 = new QCustomPlot();
plotBreathing1->addGraph(); // 添加一个图表
// 设置关键点的显示效果
plotBreathing1->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(QColor(41,138,220), 2), QBrush(QColor(5,189,251)), 10));
// 设置x轴显示时间
plotBreathing1->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plotBreathing1->xAxis->setDateTimeFormat("mm:ss");
plotBreathing1->xAxis->setAutoTickStep(false);
plotBreathing1->xAxis->setTickStep(4);
plotBreathing1->yAxis->setRange(0,250);
plotBreathing1->yAxis->setAutoTickStep(false);//设置是否自动分配刻度间距
plotBreathing1->yAxis->setTickStep(50); //设置刻度间距
// 设置轴的标题
plotBreathing1->xAxis->setLabel("时间");
plotBreathing1->yAxis->setLabel("呼吸");
//2号床位的心率数据波形
plotHeartRate2 = new QCustomPlot();
plotHeartRate2->addGraph(); // 添加一个图表
// 设置关键点的显示效果
plotHeartRate2->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(QColor(41,138,220), 2), QBrush(QColor(5,189,251)), 10));
// 设置x轴显示时间
plotHeartRate2->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plotHeartRate2->xAxis->setDateTimeFormat("mm:ss");
plotHeartRate2->xAxis->setAutoTickStep(false);
plotHeartRate2->xAxis->setTickStep(6);
plotHeartRate2->yAxis->setRange(0,250);
plotHeartRate2->yAxis->setAutoTickStep(false);//设置是否自动分配刻度间距
plotHeartRate2->yAxis->setTickStep(50); //设置刻度间距
// 设置轴的标题
plotHeartRate2->xAxis->setLabel("时间");
plotHeartRate2->yAxis->setLabel("心率");
//2号床位的呼吸数据波形
plotBreathing2 = new QCustomPlot();
plotBreathing2->addGraph(); // 添加一个图表
// 设置关键点的显示效果
plotBreathing2->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(QColor(41,138,220), 2), QBrush(QColor(5,189,251)), 10));
// 设置x轴显示时间
plotBreathing2->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plotBreathing2->xAxis->setDateTimeFormat("mm:ss");
plotBreathing2->xAxis->setAutoTickStep(false);
plotBreathing2->xAxis->setTickStep(4);
plotBreathing2->yAxis->setRange(0,250);
plotBreathing2->yAxis->setAutoTickStep(false);//设置是否自动分配刻度间距
plotBreathing2->yAxis->setTickStep(50); //设置刻度间距
// 设置轴的标题
plotBreathing2->xAxis->setLabel("时间");
plotBreathing2->yAxis->setLabel("呼吸");
//3号床位的心率数据波形
plotHeartRate3 = new QCustomPlot();
plotHeartRate3->addGraph(); // 添加一个图表
// 设置关键点的显示效果
plotHeartRate3->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(QColor(41,138,220), 2), QBrush(QColor(5,189,251)), 10));
// 设置x轴显示时间
plotHeartRate3->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plotHeartRate3->xAxis->setDateTimeFormat("mm:ss");
plotHeartRate3->xAxis->setAutoTickStep(false);
plotHeartRate3->xAxis->setTickStep(6);
plotHeartRate3->yAxis->setRange(0,250);
plotHeartRate3->yAxis->setAutoTickStep(false);//设置是否自动分配刻度间距
plotHeartRate3->yAxis->setTickStep(50); //设置刻度间距
// 设置轴的标题
plotHeartRate3->xAxis->setLabel("时间");
plotHeartRate3->yAxis->setLabel("心率");
//3号床位的呼吸数据波形
plotBreathing3 = new QCustomPlot();
plotBreathing3->addGraph(); // 添加一个图表
// 设置关键点的显示效果
plotBreathing3->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(QColor(41,138,220), 2), QBrush(QColor(5,189,251)), 10));
// 设置x轴显示时间
plotBreathing3->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plotBreathing3->xAxis->setDateTimeFormat("mm:ss");
plotBreathing3->xAxis->setAutoTickStep(false);
plotBreathing3->xAxis->setTickStep(4);
plotBreathing3->yAxis->setRange(0,250);
plotBreathing3->yAxis->setAutoTickStep(false);//设置是否自动分配刻度间距
plotBreathing3->yAxis->setTickStep(50); //设置刻度间距
// 设置轴的标题
plotBreathing3->xAxis->setLabel("时间");
plotBreathing3->yAxis->setLabel("呼吸");
//4号床位的心率数据波形
plotHeartRate4 = new QCustomPlot();
plotHeartRate4->addGraph(); // 添加一个图表
// 设置关键点的显示效果
plotHeartRate4->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(QColor(41,138,220), 2), QBrush(QColor(5,189,251)), 10));
// 设置x轴显示时间
plotHeartRate4->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plotHeartRate4->xAxis->setDateTimeFormat("mm:ss");
plotHeartRate4->xAxis->setAutoTickStep(false);
plotHeartRate4->xAxis->setTickStep(6);
plotHeartRate4->yAxis->setRange(0,250);
plotHeartRate4->yAxis->setAutoTickStep(false);//设置是否自动分配刻度间距
plotHeartRate4->yAxis->setTickStep(50); //设置刻度间距
// 设置轴的标题
plotHeartRate4->xAxis->setLabel("时间");
plotHeartRate4->yAxis->setLabel("心率");
//4号床位的呼吸数据波形
plotBreathing4 = new QCustomPlot();
plotBreathing4->addGraph(); // 添加一个图表
// 设置关键点的显示效果
plotBreathing4->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(QColor(41,138,220), 2), QBrush(QColor(5,189,251)), 10));
// 设置x轴显示时间
plotBreathing4->xAxis->setTickLabelType(QCPAxis::ltDateTime);
plotBreathing4->xAxis->setDateTimeFormat("mm:ss");
plotBreathing4->xAxis->setAutoTickStep(false);
plotBreathing4->xAxis->setTickStep(4);
plotBreathing4->yAxis->setRange(0,250);
plotBreathing4->yAxis->setAutoTickStep(false);//设置是否自动分配刻度间距
plotBreathing4->yAxis->setTickStep(50); //设置刻度间距
// 设置轴的标题
plotBreathing4->xAxis->setLabel("时间");
plotBreathing4->yAxis->setLabel("呼吸");
/*******************上面的信息是定义每一个床位的绘制心率和呼吸的容器**************************/
//图表画图计时器初始化
QTimer dataTimer1;
connect(&dataTimer1, SIGNAL(timeout()), this, SLOT(realtimeDataSlotCom1(double,double)));
dataTimer1.start(0); // Interval 0 means to refresh as fast as possible
QTimer dataTimer2;
connect(&dataTimer2, SIGNAL(timeout()), this, SLOT(realtimeDataSlotCom2(double,double)));
dataTimer2.start(0); // Interval 0 means to refresh as fast as possible
QTimer dataTimer3;
connect(&dataTimer3, SIGNAL(timeout()), this, SLOT(realtimeDataSlotCom3(double,double)));
dataTimer3.start(0); // Interval 0 means to refresh as fast as possible
QTimer dataTimer4;
connect(&dataTimer4, SIGNAL(timeout()), this, SLOT(realtimeDataSlotCom4(double,double)));
dataTimer4.start(0); // Interval 0 means to refresh as fast as possible
//每个串口的打开按钮
OpenButton1 = new QPushButton(tr("打开串口"));
OpenButton2 = new QPushButton(tr("打开串口"));
OpenButton3 = new QPushButton(tr("打开串口"));
OpenButton4 = new QPushButton(tr("打开串口"));
//每个串口数据的清除按钮
ClearRecvButton1 = new QPushButton(tr("清除接收"));
ClearRecvButton2 = new QPushButton(tr("清除接收"));
ClearRecvButton3 = new QPushButton(tr("清除接收"));
ClearRecvButton4 = new QPushButton(tr("清除接收"));
//设置“打开串口”按钮出发信号发生时的接收器以及接收响应函数
connect(OpenButton1, QPushButton::clicked, this, OpenSerialCom1);
connect(OpenButton2, QPushButton::clicked, this, OpenSerialCom2);
connect(OpenButton3, QPushButton::clicked, this, OpenSerialCom3);
connect(OpenButton4, QPushButton::clicked, this, OpenSerialCom4);
//设置“清除数据”按钮出发信号发生时的接收器以及接收响应函数
connect(ClearRecvButton1, QPushButton::clicked, this, ClearRecvCom1); //清除显示区数据
connect(ClearRecvButton2, QPushButton::clicked, this, ClearRecvCom2); //清除显示区数据
connect(ClearRecvButton3, QPushButton::clicked, this, ClearRecvCom3); //清除显示区数据
connect(ClearRecvButton4, QPushButton::clicked, this, ClearRecvCom4); //清除显示区数据
//复选框
RTSBox = new QCheckBox(tr("RTS"));
DTRBox = new QCheckBox(tr("DTR"));
//绑定复选框信号
connect(RTSBox, QCheckBox::stateChanged, this, RTSControl);
connect(DTRBox, QCheckBox::stateChanged, this, DTRControl);
//初始化左侧容器的布局
leftLlayout = new QFormLayout();
leftLlayout->addRow(BaudrateLabel, BaudrateBox);
leftLlayout->addRow(StopbitsLabel, StopbitsBox);
leftLlayout->addRow(DatabitsLabel, DatabitsBox);
leftLlayout->addRow(ParityLabel, ParityBox);
leftLlayout->addRow(RTSBox,DTRBox);
leftLlayout->setMargin(10); //控件与窗体的左右边距
leftLlayout->setHorizontalSpacing(10); //控件与控件之间的左右边距
leftLlayout->setVerticalSpacing(30); //控件与控件之间的上下边距
paramGroup = new QGroupBox();
paramGroup->setLayout(leftLlayout);
paramGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
/*******************下面的信息是定义左右两个QVBoxLayout容器*************************
********************每一个分别纵向放置5个QGridLayout容器,装载床位的信息**************/
//定义左侧QVBoxLayout容器
cvlayout = new QVBoxLayout();
BedLayout1= new QGridLayout();
BedLayout1->setVerticalSpacing(20); //控件之间的纵向间距
BedLayout1->addWidget(OpenButton1,0,0); //0行0列
BedLayout1->addWidget(COMLabel1,1,0); //1行0列
BedLayout1->addWidget(COMBox1,2,0); //2行0列
BedLayout1->addWidget(ClearRecvButton1,3,0); //3行0列
BedLayout1->addWidget(BedLabel1,0,1,5,1); //0行1列,并占据5行1列的空间大小
BedLayout1->addWidget(LightLabel1,0,2,5,1); //0行1列,并占据5行1列的空间大小
BedLayout1->addWidget(plotHeartRate1, 0,3,5,1); //0行2列,并占据5行1列的空间大小
BedLayout1->addWidget(HeartRateLabel1,0,4,5,1); //0行3列,并占据5行1列的空间大小
BedLayout1->addWidget(plotBreathing1, 0,5,5,1); //0行4列,并占据5行1列的空间大小
BedLayout1->addWidget(BreathingLabel1,0,6,5,1); //0行5列,并占据5行1列的空间大小
//设置每一列的所占空间的比例,同理可以设置每一行所占空间的比例
BedLayout1->setColumnStretch(0, 2);
BedLayout1->setColumnStretch(1, 2);
BedLayout1->setColumnStretch(2, 1);
BedLayout1->setColumnStretch(3, 6);
BedLayout1->setColumnStretch(4, 2);
BedLayout1->setColumnStretch(5, 6);
BedLayout1->setColumnStretch(6, 2);
cvlayout->addLayout(BedLayout1); //往cvlayout内部添加BedLayout1
BedLayout2= new QGridLayout();
BedLayout2->setVerticalSpacing(20);
BedLayout2->addWidget(OpenButton2,0,0);
BedLayout2->addWidget(COMLabel2,1,0);
BedLayout2->addWidget(COMBox2,2,0);
BedLayout2->addWidget(ClearRecvButton2,3,0);
BedLayout2->addWidget(BedLabel2,0,1,5,1);
BedLayout2->addWidget(LightLabel2,0,2,5,1);
BedLayout2->addWidget(plotHeartRate2, 0,3,5,1);
BedLayout2->addWidget(HeartRateLabel2,0,4,5,1);
BedLayout2->addWidget(plotBreathing2, 0,5,5,1);
BedLayout2->addWidget(BreathingLabel2,0,6,5,1);
BedLayout2->setColumnStretch(0, 2);
BedLayout2->setColumnStretch(1, 2);
BedLayout2->setColumnStretch(2, 1);
BedLayout2->setColumnStretch(3, 6);
BedLayout2->setColumnStretch(4, 2);
BedLayout2->setColumnStretch(5, 6);
BedLayout2->setColumnStretch(6, 2);
cvlayout->addLayout(BedLayout2); //往cvlayout内部添加BedLayout1
BedLayout3= new QGridLayout();
BedLayout3->setVerticalSpacing(20);
BedLayout3->addWidget(OpenButton3,0,0);
BedLayout3->addWidget(COMLabel3,1,0);
BedLayout3->addWidget(COMBox3,2,0);
BedLayout3->addWidget(ClearRecvButton3,3,0);
BedLayout3->addWidget(BedLabel3,0,1,5,1);
BedLayout3->addWidget(LightLabel3,0,2,5,1);
BedLayout3->addWidget(plotHeartRate3, 0,3,5,1);
BedLayout3->addWidget(HeartRateLabel3,0,4,5,1);
BedLayout3->addWidget(plotBreathing3, 0,5,5,1);
BedLayout3->addWidget(BreathingLabel3,0,6,5,1);
BedLayout3->setColumnStretch(0, 2);
BedLayout3->setColumnStretch(1, 2);
BedLayout3->setColumnStretch(2, 1);
BedLayout3->setColumnStretch(3, 6);
BedLayout3->setColumnStretch(4, 2);
BedLayout3->setColumnStretch(5, 6);
BedLayout3->setColumnStretch(6, 2);
cvlayout->addLayout(BedLayout3); //往cvlayout内部添加BedLayout1
BedLayout4= new QGridLayout();
BedLayout4->setVerticalSpacing(20);
BedLayout4->addWidget(OpenButton4,0,0);
BedLayout4->addWidget(COMLabel4,1,0);
BedLayout4->addWidget(COMBox4,2,0);
BedLayout4->addWidget(ClearRecvButton4,3,0);
BedLayout4->addWidget(BedLabel4,0,1,5,1);
BedLayout4->addWidget(LightLabel4,0,2,5,1);
BedLayout4->addWidget(plotHeartRate4, 0,3,5,1);
BedLayout4->addWidget(HeartRateLabel4,0,4,5,1);
BedLayout4->addWidget(plotBreathing4, 0,5,5,1);
BedLayout4->addWidget(BreathingLabel4,0,6,5,1);
BedLayout4->setColumnStretch(0, 2);
BedLayout4->setColumnStretch(1, 2);
BedLayout4->setColumnStretch(2, 1);
BedLayout4->setColumnStretch(3, 6);
BedLayout4->setColumnStretch(4, 2);
BedLayout4->setColumnStretch(5, 6);
BedLayout4->setColumnStretch(6, 2);
cvlayout->addLayout(BedLayout4); //往cvlayout内部添加BedLayout1
//定义centralLayout容器,一共包含3个子容器
centralLayout = new QGridLayout(this);
centralLayout->addWidget(paramGroup, 0, 0, 1, 1); //位置在0行0列,且占据1行1列
centralLayout->addLayout(cvlayout, 0, 1, 1, 1); //位置在0行1列,且占据1行1列
centralLayout->setColumnMinimumWidth(0, 150); //centralLayout第一列至少150像素
centralLayout->setColumnMinimumWidth(1, 100); //centralLayout第二列至少100像素
//设置两个子容器在centralLayout占据列的比例
centralLayout->setColumnStretch(0, 0);
centralLayout->setColumnStretch(1, 1);
setLayout(centralLayout); //把centralLayout设置为主容器
//设置主窗口的背景颜色
QPalette palWidget;
palWidget.setColor(QPalette::Background,QColor(192,253,123));
setAutoFillBackground(true);
setPalette(palWidget);
//串口1的计时器初始化
CheckTimer1 = new QTimer(this);
CheckTimer1->start(1000);
SendTimer1 = new QTimer(this);
connect(CheckTimer1, QTimer::timeout, this, CheckSerialsCom1);
//串口2的计时器初始化
CheckTimer2 = new QTimer(this);
CheckTimer2->start(1000);
SendTimer2 = new QTimer(this);
connect(CheckTimer2, QTimer::timeout, this, CheckSerialsCom2);
//串口3的计时器初始化
CheckTimer3 = new QTimer(this);
CheckTimer3->start(1000);
SendTimer3 = new QTimer(this);
connect(CheckTimer3, QTimer::timeout, this, CheckSerialsCom3);
//串口4的计时器初始化
CheckTimer4 = new QTimer(this);
CheckTimer4->start(1000);
SendTimer4 = new QTimer(this);
connect(CheckTimer4, QTimer::timeout, this, CheckSerialsCom4);
//初始化串口列表
CheckSerialsCom1();
CheckSerialsCom2();
CheckSerialsCom3();
CheckSerialsCom4();
//开始串口1进程
serialControllerCom1 = new SerialController;
serialControllerCom1->moveToThread(&SerialThrCom1);
SerialThrCom1.start();
//开始串口2进程
serialControllerCom2 = new SerialController;
serialControllerCom2->moveToThread(&SerialThrCom2);
SerialThrCom2.start();
//开始串口3进程
serialControllerCom3 = new SerialController;
serialControllerCom3->moveToThread(&SerialThrCom3);
SerialThrCom3.start();
//开始串口4进程
serialControllerCom4 = new SerialController;
serialControllerCom4->moveToThread(&SerialThrCom4);
SerialThrCom4.start();
//connect开关串口1控制信号 以及是否成功的返回信号
connect(this, requestOpenCom1, serialControllerCom1, SerialController::openSerial);
connect(this, requestCloseCom1, serialControllerCom1, SerialController::closeSerial);
connect(serialControllerCom1, SerialController::openSuccess, this, serialOpenedCom1); //绑定串口打开成功信号发出时的接收方以及响应函数
connect(serialControllerCom1, SerialController::openFailed, this, serialNotOpenedCom1); //绑定串口打开失败信号发出时的接收方以及响应函数
connect(serialControllerCom1, SerialController::closeSuccess, this, serialClosedCom1); //绑定串口关闭成功信号发出时的接收方以及响应函数
//connect波特率等参数的控制信号
connect(this, setBaudRate, serialControllerCom1, SerialController::getBaudrate);
connect(this, setStopBits, serialControllerCom1, SerialController::getStopbits);
connect(this, setDataBits, serialControllerCom1, SerialController::getDatabits);
connect(this, setParity, serialControllerCom1, SerialController::getParity);
connect(BaudrateBox, QComboBox::currentTextChanged, serialControllerCom1, SerialController::getBaudrate);
connect(StopbitsBox, QComboBox::currentTextChanged, serialControllerCom1, SerialController::getStopbits);
connect(DatabitsBox, QComboBox::currentTextChanged, serialControllerCom1, SerialController::getDatabits);
connect(ParityBox, QComboBox::currentTextChanged, serialControllerCom1, SerialController::getParity);
connect(this, changeRTS, serialControllerCom1, SerialController::contrloRTS);
connect(this, changeDTR, serialControllerCom1, SerialController::controlDTR);
connect(serialControllerCom1, SerialController::recvData, this, getRecvCom1); //绑定串口1发出数据的信号以及接收方的响应函数
//connect开关串口2控制信号 以及是否成功的返回信号
connect(this, requestOpenCom2, serialControllerCom2, SerialController::openSerial);
connect(this, requestCloseCom2, serialControllerCom2, SerialController::closeSerial);
connect(serialControllerCom2, SerialController::openSuccess, this, serialOpenedCom2);
connect(serialControllerCom2, SerialController::openFailed, this, serialNotOpenedCom2);
connect(serialControllerCom2, SerialController::closeSuccess, this, serialClosedCom2);
//connect波特率等参数的控制信号
connect(this, setBaudRate, serialControllerCom2, SerialController::getBaudrate);
connect(this, setStopBits, serialControllerCom2, SerialController::getStopbits);
connect(this, setDataBits, serialControllerCom2, SerialController::getDatabits);
connect(this, setParity, serialControllerCom2, SerialController::getParity);
connect(BaudrateBox, QComboBox::currentTextChanged, serialControllerCom2, SerialController::getBaudrate);
connect(StopbitsBox, QComboBox::currentTextChanged, serialControllerCom2, SerialController::getStopbits);
connect(DatabitsBox, QComboBox::currentTextChanged, serialControllerCom2, SerialController::getDatabits);
connect(ParityBox, QComboBox::currentTextChanged, serialControllerCom2, SerialController::getParity);
connect(this, changeRTS, serialControllerCom2, SerialController::contrloRTS);
connect(this, changeDTR, serialControllerCom2, SerialController::controlDTR);
connect(serialControllerCom2, SerialController::recvData, this, getRecvCom2);
//connect开关串口3控制信号 以及是否成功的返回信号
connect(this, requestOpenCom3, serialControllerCom3, SerialController::openSerial);
connect(this, requestCloseCom3, serialControllerCom3, SerialController::closeSerial);
connect(serialControllerCom3, SerialController::openSuccess, this, serialOpenedCom3);
connect(serialControllerCom3, SerialController::openFailed, this, serialNotOpenedCom3);
connect(serialControllerCom3, SerialController::closeSuccess, this, serialClosedCom3);
//connect波特率等参数的控制信号
connect(this, setBaudRate, serialControllerCom3, SerialController::getBaudrate);
connect(this, setStopBits, serialControllerCom3, SerialController::getStopbits);
connect(this, setDataBits, serialControllerCom3, SerialController::getDatabits);
connect(this, setParity, serialControllerCom3, SerialController::getParity);
connect(BaudrateBox, QComboBox::currentTextChanged, serialControllerCom3, SerialController::getBaudrate);
connect(StopbitsBox, QComboBox::currentTextChanged, serialControllerCom3, SerialController::getStopbits);
connect(DatabitsBox, QComboBox::currentTextChanged, serialControllerCom3, SerialController::getDatabits);
connect(ParityBox, QComboBox::currentTextChanged, serialControllerCom3, SerialController::getParity);
connect(this, changeRTS, serialControllerCom3, SerialController::contrloRTS);
connect(this, changeDTR, serialControllerCom3, SerialController::controlDTR);
connect(serialControllerCom3, SerialController::recvData, this, getRecvCom3);
//connect开关串口4控制信号 以及是否成功的返回信号
connect(this, requestOpenCom4, serialControllerCom4, SerialController::openSerial);
connect(this, requestCloseCom4, serialControllerCom4, SerialController::closeSerial);
connect(serialControllerCom4, SerialController::openSuccess, this, serialOpenedCom4);
connect(serialControllerCom4, SerialController::openFailed, this, serialNotOpenedCom4);
connect(serialControllerCom4, SerialController::closeSuccess, this, serialClosedCom4);
//connect波特率等参数的控制信号
connect(this, setBaudRate, serialControllerCom4, SerialController::getBaudrate);
connect(this, setStopBits, serialControllerCom4, SerialController::getStopbits);
connect(this, setDataBits, serialControllerCom4, SerialController::getDatabits);
connect(this, setParity, serialControllerCom4, SerialController::getParity);
connect(BaudrateBox, QComboBox::currentTextChanged, serialControllerCom4, SerialController::getBaudrate);
connect(StopbitsBox, QComboBox::currentTextChanged, serialControllerCom4, SerialController::getStopbits);
connect(DatabitsBox, QComboBox::currentTextChanged, serialControllerCom4, SerialController::getDatabits);
connect(ParityBox, QComboBox::currentTextChanged, serialControllerCom4, SerialController::getParity);
connect(this, changeRTS, serialControllerCom4, SerialController::contrloRTS);
connect(this, changeDTR, serialControllerCom4, SerialController::controlDTR);
connect(serialControllerCom4, SerialController::recvData, this, getRecvCom4);
}
ostream &os = cout;
/*****************************************************************************
*********************** 这里比较重要: 检测串口 **************************
******************************************************************************/
void MainWidget::CheckSerialsCom1()
{
//不断检查可用串口列表,并与当前列表进行比较,若发生变化则重新生成列表
emit sendDateTime(QDateTime::currentDateTime().toString());//更新状态栏时间
QList<QSerialPortInfo> SerialList1 = QSerialPortInfo::availablePorts(); //获取可用的串口号
if (!SerialList1.isEmpty()) //获取的串口号不为空
{
QStringList TmpComList1, TmpPortNameList1, TmpDesList1;
for (QSerialPortInfo serial : SerialList1)
{
TmpComList1 << serial.portName() + " " + serial.description(); //获得每一个可用串口的名称和描述
TmpPortNameList1<< serial.portName();
TmpDesList1 << serial.description();
}
if (COMList1 != TmpComList1)
{
//TODO: 可用串口发生改变却不为空时,保持串口打开状态,及其他细节的处理
//只在串口发生变化时刷新ComboBox
COMList1 = TmpComList1;
PortNameList1 = TmpPortNameList1;
DescList1 = TmpDesList1;
COMBox1->setDisabled(false);
COMBox1->clear();
COMBox1->addItems(PortNameList1);
OpenButton1->setDisabled(false);
for (int i = 0; i < COMList1.count(); i++) //为串口列表增加ToolTip
{
COMBox1->setItemData(i, DescList1[i], Qt::ToolTipRole);
//os<<PortNameList1[i].toLatin1().data()<<endl; //cout: USB-SERIAL CH340
}
}
}
else //可用串口为空时发送关闭串口信号
{
COMBox1->clear();
COMList1.clear();
COMBox1->addItem(tr("(空)"));
COMBox1->setDisabled(true);
OpenButton1->setDisabled(true);
emit CloseSerialCom1();
isOpened1 = false;
}
//os<<PortNameList1[COMBox1->currentIndex()].toLatin1().data()<<endl; //获取当前的串口号
COMLabel1->setText(QString("串口号 : ")+PortNameList1[COMBox1->currentIndex()]); //串口号显示标签中显示被选中的串口号
}
void MainWidget::CheckSerialsCom2()
{
//不断检查可用串口列表,并与当前列表进行比较,若发生变化则重新生成列表
emit sendDateTime(QDateTime::currentDateTime().toString());//更新状态栏时间
QList<QSerialPortInfo> SerialList2 = QSerialPortInfo::availablePorts();
if (!SerialList2.isEmpty())
{
QStringList TmpComList2, TmpPortNameList2, TmpDesList2;
for (QSerialPortInfo serial : SerialList2)
{
TmpComList2 << serial.portName() + " " + serial.description();
TmpPortNameList2<< serial.portName();
TmpDesList2 << serial.description();
}
if (COMList2 != TmpComList2)
{
//TODO: 可用串口发生改变却不为空时,保持串口打开状态,及其他细节的处理
//只在串口发生变化时刷新ComboBox
COMList2 = TmpComList2;
PortNameList2 = TmpPortNameList2;
DescList2 = TmpDesList2;
COMBox2->setDisabled(false);
COMBox2->clear();
COMBox2->addItems(PortNameList2);
OpenButton2->setDisabled(false);
for (int i = 0; i < COMList2.count(); i++) //为串口列表增加ToolTip
{
COMBox2->setItemData(i, DescList2[i], Qt::ToolTipRole);
//os<<PortNameList1[i].toLatin1().data()<<endl; //cout: USB-SERIAL CH340
}
}
}
else //可用串口为空时发送关闭串口信号
{
COMBox2->clear();
COMList2.clear();
COMBox2->addItem(tr("(空)"));
COMBox2->setDisabled(true);
OpenButton2->setDisabled(true);
emit CloseSerialCom2();
isOpened2 = false;
}
//os<<PortNameList2[COMBox2->currentIndex()].toLatin1().data()<<endl; //获取当前的串口号
COMLabel2->setText(QString("串口号 : ")+PortNameList2[COMBox2->currentIndex()]);
}
void MainWidget::CheckSerialsCom3()
{
//不断检查可用串口列表,并与当前列表进行比较,若发生变化则重新生成列表
emit sendDateTime(QDateTime::currentDateTime().toString());//更新状态栏时间
QList<QSerialPortInfo> SerialList3 = QSerialPortInfo::availablePorts();
if (!SerialList3.isEmpty())
{
QStringList TmpComList3, TmpPortNameList3, TmpDesList3;
for (QSerialPortInfo serial : SerialList3)
{
TmpComList3 << serial.portName() + " " + serial.description();
TmpPortNameList3<< serial.portName();
TmpDesList3 << serial.description();
}
if (COMList3 != TmpComList3)
{
//TODO: 可用串口发生改变却不为空时,保持串口打开状态,及其他细节的处理
//只在串口发生变化时刷新ComboBox
COMList3 = TmpComList3;
PortNameList3 = TmpPortNameList3;
DescList3 = TmpDesList3;
COMBox3->setDisabled(false);
COMBox3->clear();
COMBox3->addItems(PortNameList3);
OpenButton3->setDisabled(false);
for (int i = 0; i < COMList3.count(); i++) //为串口列表增加ToolTip
{
COMBox3->setItemData(i, DescList3[i], Qt::ToolTipRole);
//os<<PortNameList1[i].toLatin1().data()<<endl; //cout: USB-SERIAL CH340
}
}
}
else //可用串口为空时发送关闭串口信号
{
COMBox3->clear();
COMList3.clear();
COMBox3->addItem(tr("(空)"));
COMBox3->setDisabled(true);
OpenButton3->setDisabled(true);
emit CloseSerialCom3();
isOpened3 = false;
}
//os<<PortNameList1[COMBox1->currentIndex()].toLatin1().data()<<endl; //获取当前的串口号
COMLabel3->setText(QString("串口号 : ")+PortNameList3[COMBox3->currentIndex()]);
}
void MainWidget::CheckSerialsCom4()
{
//不断检查可用串口列表,并与当前列表进行比较,若发生变化则重新生成列表
emit sendDateTime(QDateTime::currentDateTime().toString());//更新状态栏时间
QList<QSerialPortInfo> SerialList4 = QSerialPortInfo::availablePorts();
if (!SerialList4.isEmpty())
{
QStringList TmpComList4, TmpPortNameList4, TmpDesList4;
for (QSerialPortInfo serial : SerialList4)
{
TmpComList4 << serial.portName() + " " + serial.description();
TmpPortNameList4<< serial.portName();
TmpDesList4 << serial.description();
}
if (COMList4 != TmpComList4)
{
//TODO: 可用串口发生改变却不为空时,保持串口打开状态,及其他细节的处理
//只在串口发生变化时刷新ComboBox
COMList4 = TmpComList4;
PortNameList4 = TmpPortNameList4;
DescList4 = TmpDesList4;
COMBox4->setDisabled(false);
COMBox4->clear();
COMBox4->addItems(PortNameList4);
OpenButton4->setDisabled(false);
for (int i = 0; i < COMList4.count(); i++) //为串口列表增加ToolTip
{
COMBox4->setItemData(i, DescList4[i], Qt::ToolTipRole);
//os<<PortNameList1[i].toLatin1().data()<<endl; //cout: USB-SERIAL CH340
}
}
}
else //可用串口为空时发送关闭串口信号
{
COMBox4->clear();
COMList4.clear();
COMBox4->addItem(tr("(空)"));
COMBox4->setDisabled(true);
OpenButton4->setDisabled(true);
emit CloseSerialCom4();
isOpened4 = false;
}
//os<<PortNameList1[COMBox1->currentIndex()].toLatin1().data()<<endl; //获取当前的串口号
COMLabel4->setText(QString("串口号 : ")+PortNameList4[COMBox4->currentIndex()]);
}
MainWidget::~MainWidget()
{
SerialThrCom1.terminate();
//SerialThrCom2.terminate();
//SerialThrCom3.terminate();
//SerialThrCom4.terminate();
settings.setValue("Baud rate", BaudrateBox->currentIndex());
settings.setValue("Stop bits", StopbitsBox->currentIndex());
settings.setValue("Data bits", DatabitsBox->currentIndex());
settings.setValue("Parity", ParityBox->currentIndex());
}
void MainWidget::RTSControl(int state)
{
if(isOpened1||isOpened2||isOpened3||isOpened4)
{
if(state == 2)
emit changeRTS(true);
else if(state == 0)
emit changeRTS(false);
}
}
void MainWidget::DTRControl(int state)
{
if(isOpened1||isOpened2||isOpened3||isOpened4)
{
if(state == 2)
emit changeDTR(true);
else if(state == 0)
emit changeDTR(false);
}
}
//串口1打开成功的信号发出时的接收响应函数
void MainWidget::serialOpenedCom1()
{
isOpened1= true; //串口1打开标志位为真
//串口复选框显示当前Com口
int portIndex = COMBox1->currentIndex();
emit sendStatus(QString(PortNameList1[portIndex] + tr(" ") + DescList1[portIndex]));
//串口关闭时无法设置RTS,DTR信号(但此时checkbox仍然是可操作的),串口打开时发送stateChanged信号来应用改变
emit RTSBox->stateChanged(RTSBox->checkState());
emit DTRBox->stateChanged(DTRBox->checkState());
//相应控件可用性做出改变(setDisabled)
ACtionAttachToSerialCom1(true);
}
//串口1打开失败的信号发出时的接收响应函数
void MainWidget::serialNotOpenedCom1()
{
//设置状态栏 并发出警告音
//TODO: 此处应有更容易察觉的提示
emit sendStatus(tr("串口打开失败"));
QApplication::beep();
}
//串口1关闭成功的信号发出时的接收响应函数
void MainWidget::serialClosedCom1()
{
isOpened1 = false;
//相应控件可用性做出改变(setDisabled)
ACtionAttachToSerialCom1(false);
emit sendStatus(tr("串口已关闭"));
}
//触发“打开串口”按钮后的调用函数: 主要获取当前可用串口1的相关信息
void MainWidget::OpenSerialCom1()
{
QString portName = COMBox1->currentText();
emit requestOpenCom1(portName); //判断所选信号是否可用
emit setBaudRate(BaudrateBox->currentText());
emit setStopBits(StopbitsBox->currentText());
emit setDataBits(DatabitsBox->currentText());
emit setParity(ParityBox->currentText());
}
void MainWidget::CloseSerialCom1()