使用Socket读取modbusTCP

ModbusTcp.h

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
#ifndef MODBUSTCP_H
#define MODBUSTCP_H

#include <QTimer>
#include <QQueue>
#include <QThread>
#include <QTcpSocket>
#include <QByteArray>
#include <QDebug>
#include <QObject>
#include <cmath>

#include <functional>
#include <iostream>

#include <QSharedPointer>

enum RType
{
//MBAP报文头((适用于TCP))
TAGMatterHi, //事务标识符Hi 1byte
TAGMatterLo, //事务标识符Lo 1byte
TAGProtocol, //协议标识符 2byte
NumLength, //需要的长度 2byte(从本字节下一个到最后)
TAGElement, //单元标识符 1byte

GetType, //要数类型(功能码)1byte
ByteLength, //需要读取的数据字节个数
ReadData, //需要读取数据 2byte * n

};

struct MDBTData{
//MBAP报文头(适用于TCP)
quint8 TAGMatterHi; //事务标识符Hi 1byte
quint8 TAGMatterLo; //事务标识符Lo 1byte
quint16 TAGProtocol; //协议标识符 2byte
quint16 NumLength; //需要的长度 2byte(从本字节下一个到最后)
char TAGElement; //单元标识符 1byte
//PDU报文体
char AddressCode; //地址码(适用于RTU) 1byte
char GetType; //要数类型(功能码)1byte
quint16 ByteLength; //偏移量offset(读取数据的开始位置),两个字节
QByteArray ReadData; //读取数量,两个字节
quint16 Crc; //crc校验(适用于RTU) 2byte
MDBTData(){
TAGMatterHi = 0; //事务标识符Hi 1byte
TAGMatterLo = 0; //事务标识符Lo 1byte
TAGProtocol = 0; //协议标识符 2byte
NumLength = 0; //需要的长度 2byte(从本字节下一个到最后)
TAGElement = 0; //单元标识符 1byte
//PDU报文体
AddressCode = 0; //地址码(适用于RTU) 1byte
GetType = 0; //要数类型(功能码)1byte
ByteLength = 0; //偏移量offset(读取数据的开始位置),两个字节
ReadData = QByteArray(2, 0); //读取数量,两个字节
Crc = 0; //crc校验(适用于RTU) 2byte
}
};

typedef struct Read_Value{
QByteArray Read_Data;
QByteArray Before_Data;
std::function<void(QByteArray Arrary)> callback;
}RV_t;

//=============================================================

struct readData{
float angle_set;
float speed_set;
float angle_pv;
float speed_pv;
float angle_pause;
float jia_speed_set;
float hand_speed_set;
float weight;



bool check1;
bool check2;
bool start;
bool pause;

bool xiaojing;

short v1;
short v2;
short v3;
};


struct ReciveData8{
short _model;
short _time;
};

struct ReciveData10{
short _Model_Flag;
ushort _Scheduling_PV;
ushort _Scheduling_SV;
ushort _Timing_PV;
ushort _Timing_SV;
};

struct _BagT{
int PID_ENA_D_P; // 15500 袋 p 开关
int PID_ENA_D_I; // 15501
int PID_ENA_D_D; // 15502
int Te_Start; //温度启动 415438 int
float Te_Z_PV; //袋温反馈值 415407 real
float Te_Z_SV; //袋温设定值 415409 real
float Te_Z_P; //袋温P值 415411 real
float Te_Z_I; //袋温I值 415413 real
float Te_Z_D; //袋温D值 415415 real
float Te_Z_Dead_z; //袋温正死区设定值 415417 real
float Te_Z_Dead_f; //袋温负死区设定值 415419 real
float Te_Z_Iqrd; //袋温积分切入值 415421 real
short Te_Z_HL_ENA; //袋温报警上限使能 415440 int
float Te_Z_HL; //袋温报警上限设定值 415441 real
short Te_Z_LL_ENA; //袋温报警下限使能 415443 int
float Te_Z_LL; //袋温报警下限设定值 415445 real
short Te_Z_HL_ALM; //袋温上限报警 415444 int
short Te_Z_LL_ALM; //袋温下限报警 415447 int
short Te_Z_OFF_Line; //袋温断线报警 415456 int
float Te_Z_OP; //袋温PID输出%(0-100) 415459 real
float Te_Z_OFFEST; //袋温零点补偿值 415465 real
short Te_Z_OFFSET_ENA; //袋温断线使能 415496 int
};

struct _HeatT{
int PID_ENA_T_P; // 15503 袋 p 开关
int PID_ENA_T_I; // 15504
int PID_ENA_T_D; // 15505
float Te_F_PV; //加热毯温度反馈值 415423 real
float Te_F_SV; //加热毯温度设定值 415425 real
float Te_F_P; //加热毯温度P值 415427 real
float Te_F_I; //加热毯温度I值 415429 real
float Te_F_D; //加热毯温度D值 415431 real
float Te_F_Dead_z; //加热毯温度正死区设定值 415433 real
float Te_F_Dead_f; //加热毯温度负死区设定值 415435 real
float Te_F_Iqrd; //加热毯温度积分切入值 415437 real
short Te_F_HL_ENA; //加热毯温度报警上限使能 415448 int
float Te_F_HL; //加热毯温度报警上限设定值 415449 real
short Te_F_LL_ENA; //加热毯温度报警下限使能 415451 int
float Te_F_LL; //加热毯温度报警下限设定值 415453 real
short Te_F_HL_ALM; //加热毯温度上限报警 415452 int
short Te_F_LL_ALM; //加热毯温度下限报警 415455 int
short Te_F_OFF_Line; //加热毯温度断线报警 415457 int
float Te_F_OP; //加热毯温度PID输出%(0-100) 415461 real
float Te_F_OFFEST; //加热毯温度零点补偿值 415467 real
float Te_F_SV_LIMIT; //加热毯输出保护设定值 415463 real
short Te_F_OFFSET_ENA; //加热毯断线使能 415497 int

};

struct _Weigh{
float WT_PV; //称重实际值 415469 real
float WT_LP_SP; //称重两点校准第一点设定值 415471 real
float WT_HP_SP; //称重两点校准第二点设定重 415473 real
float WT_1P_SP; //称重单点校准设定重 415475 real
float WT_HL_SP; //称重上限设定值 415477 real
float WT_LL_SP; //称重下限设定值 415479 real
short WT_LP_EN; //称重两点校准第一点使能 415481 int
short WT_HP_EN; //称重两点校准第二点使能 415482 int
short WT_1P_EN; //称重单点校准使能 415483 int
short WT_1P_UNEN; //称重单点校准取消使能 415484 int
short WT_HL_EN; //称重上限使能 415485 int
short WT_LL_EN; //称重下限使能 415486 int
short WT_ENAQP_EN; //称重去皮使能 415487 int
short WT_UNENAQP_EN; //称重取消去皮使能 415488 int
short WT_HL_AL; //称重上限报警 415489 int
short WT_LL_AL; //称重下限报警 415490 int
short WT_OFFLINE_AL; //称重断线报警 415491 int
short WT_LP_Sta; //称重两点校准第一点状态(0无 1成功 2失败) 415492 int
short WT_HP_STA; //称重两点校准第二点状态(0无 1成功 2失败) 415493 int
short WT_1P_STA; //称重单点校准状态(0无 1成功 2失败) 415494 int
short WT_ENAQP; //称重去皮状态(0无 1成功 2失败) 415495 int
short WT_OFFLINE_ENA; //称重断线使能 415498 int
};





#define MdbsTCP ModbusTcp::returnMTCP()

class ModbusTcp : public QObject
{
Q_OBJECT
public:
ModbusTcp(QObject *parent = nullptr);
static ModbusTcp *returnMTCP();

QByteArray floatBigendian(float input);
QByteArray shortBigendian(short input);
float floatFromBigEndian(QByteArray data);
short shortFromBigEndian(const QByteArray &data);
ushort ushortFromBigEndian(const QByteArray &data);
long longFromBigEndian(const QByteArray &data);

short toShort(QByteArray ary);
float toFloat(QByteArray ary);
QByteArray floatToByte(float input);
QByteArray shortToByte(short input);
QByteArray doubleBigendian(double input);


void Init_QTcpSocket();
//==========================================
void Set_JiTing(bool flag); //.3
void Set_GuanGuan(bool flag); //.4
void Set_XiaoJing(bool flag); // .5


void Manage_10000(QByteArray ary);
void Manage_10125(QByteArray ary);
void Manage_10250(QByteArray ary);
void Manage_10375(QByteArray ary);
void Manage_10500(QByteArray ary);
void Manage_10625(QByteArray ary);
void Manage_10750(QByteArray ary);
void Manage_10875(QByteArray ary);
void Manage_15000(QByteArray ary);
void Manage_15125(QByteArray ary);
void Manage_15250(QByteArray ary);
void Manage_15375(QByteArray ary);
void Manage_15500(QByteArray ary);
void Manage_15625(QByteArray ary);
void Manage_15750(QByteArray ary);
void Manage_15875(QByteArray ary);
void Manage_16000(QByteArray ary);
void Manage_16125(QByteArray ary);
void Manage_16250(QByteArray ary);
void Manage_16375(QByteArray ary);
void Manage_16500(QByteArray ary);
void Manage_16625(QByteArray ary);
void Manage_16750(QByteArray ary);
void Manage_16875(QByteArray ary);
void Manage_20000(QByteArray ary);
void Manage_20125(QByteArray ary);



_BagT BagT;
_HeatT HeatT;
_Weigh Weigh;

readData Read_Data_15002;
ReciveData8 Read_Data_10000;
ReciveData10 Read_Data_30800;


QByteArray alarm_arrary_10010; // 报警点位
QByteArray xiaojing_array; // 消警点位
QByteArray start_array; // 启停点位 30064.3
QByteArray reset_array; // 复位点位
QByteArray zero_array; // 零点点位 10019.1
QByteArray sifu_array; // 伺服点位 1000


void Init_Read();

void
Init_Read(QByteArray Array,int ids,int stw);
//===========================================
bool Get_Connect();

bool Write(char feature, ushort startAdiss, QByteArray array, ushort sized = 0,quint8 tAGMatterHi=0xff, quint8 tAGMatterLo=0xff);

void Write_Bool(char feature, ushort startAdiss,QByteArray Ary,int offset,bool Flag);

bool Init_Read(char feature,ushort startAdiss,quint16 number,std::function<void(QByteArray Arrary)> callback);

void Execute_Callback(QByteArray Data);

QByteArray Get_QByteArray(char feature, ushort startAdiss, QByteArray & array, ushort sized = 0,quint8 tAGMatterHi=0, quint8 tAGMatterLo=0);

void Start_Read(int Sec=100);

void Start_Queue(int Sec=20);

void Thread_Rcv();

void Set_IP(QString ip){_ip = ip;}

public slots:
bool QByte_ReadData();

bool QByte_WriteData();

void ReadError(QAbstractSocket::SocketError);

public:

QString _ip;

QTimer * _timing;

QTimer * _timing_map;

QTcpSocket * _tcpClient;


QQueue<QByteArray> * _wirteMsg;

bool _client_flag;

QByteArray _buffer; //用于存储

RType _read_index; //用于确认标识

int _toReadlen; //用于确认需要读取的长度

QMap<quint16,RV_t> Modbus_TCP_Read_Map;

QSharedPointer<MDBTData> code;
};



#endif // MODBUSTCP_H

ModbusTcp.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
#include <globalconstant.h>
#include <global_api.h>
#include "modbustcp.h"

ModbusTcp::ModbusTcp(QObject *parent) : QObject(parent)
{
_client_flag = false;
_ip = "172.16.13.10";
// _ip = "172.22.80.1";

_wirteMsg = new QQueue<QByteArray>();

_read_index = TAGMatterHi;

_tcpClient = new QTcpSocket();
connect(_tcpClient, SIGNAL(readyRead()), this, SLOT(QByte_ReadData()));
connect(_tcpClient, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(ReadError(QAbstractSocket::SocketError)));

_timing = new QTimer(this);
connect(_timing,&QTimer::timeout, this,&ModbusTcp::QByte_WriteData);


_timing_map = new QTimer(this);
connect(_timing_map,&QTimer::timeout, this,[=](){
for(auto it = Modbus_TCP_Read_Map.begin() ;it != Modbus_TCP_Read_Map.end(); it++){
_wirteMsg->enqueue(it.value().Read_Data);
}
});

code = QSharedPointer<MDBTData>(new MDBTData());

}

ModbusTcp *ModbusTcp::returnMTCP()
{
static ModbusTcp tcp;
return &tcp;
}

bool ModbusTcp::Get_Connect()
{

if(_tcpClient->waitForConnected(300)) //会阻塞函数直到新的数据出现
{
_client_flag = true;
return true;
}

_tcpClient->abort(); //取消原有连接
_tcpClient->connectToHost(_ip,502);
_client_flag = _tcpClient->waitForConnected(1000);

qDebug() << _ip << "2通讯状态::" << _client_flag;
return _client_flag;
}

void ModbusTcp::Set_JiTing(bool flag)
{
if(Get_Connect() == false){return;}

QByteArray data;
if(flag){
data.append(MdbsTCP->xiaojing_array.at(0));
data.append(MdbsTCP->xiaojing_array.at(1) | 0x8);
}else{
data.append(MdbsTCP->xiaojing_array.at(0));
data.append(MdbsTCP->xiaojing_array.at(1) & 0xF7);
}
Write(0x06,0x3c29,data);
}

void ModbusTcp::Set_GuanGuan(bool flag)
{
if(Get_Connect() == false){return;}

QByteArray data;
if(flag){
data.append(MdbsTCP->xiaojing_array.at(0));
data.append(MdbsTCP->xiaojing_array.at(1) | 0x10);
}else{
data.append(MdbsTCP->xiaojing_array.at(0));
data.append(MdbsTCP->xiaojing_array.at(1) & 0xEF);
}
Write(0x06,0x3c29,data);
}

void ModbusTcp::Set_XiaoJing(bool flag)
{
if(Get_Connect() == false){return;}

QByteArray data;
if(flag){
data.append(MdbsTCP->xiaojing_array.at(0));
data.append(MdbsTCP->xiaojing_array.at(1) | 0x20);
}else{
data.append(MdbsTCP->xiaojing_array.at(0));
data.append(MdbsTCP->xiaojing_array.at(1) & 0xDF);
}
Write(0x06,0x3c29,data);
}


bool ModbusTcp::Write(char feature, ushort startAdiss, QByteArray array, ushort sized, quint8 tAGMatterHi, quint8 tAGMatterLo)
{
if(_timing->isActive()){

}else{
Start_Queue();
}

QByteArray ary = Get_QByteArray(feature,startAdiss,array,sized,tAGMatterHi,tAGMatterLo);

if(ary.isEmpty()){
return false;
}else{
_wirteMsg->enqueue(ary);
}

}

void ModbusTcp::Write_Bool(char feature, ushort startAdiss, QByteArray Ary,int offset, bool Flag)
{

QByteArray data;
char c = Ary[0];
c = c | 0x00;
data.append(c);
char h = Flag ? pow(2, offset) : (255 - pow(2, offset));
h = h | Ary[1];
data.append(h);

Write(feature,startAdiss,data);
}

bool ModbusTcp::Init_Read(char feature, ushort startAdiss, quint16 number, std::function<void (QByteArray)> callback)
{
static quint16 Index = 256;

QByteArray array;
array.append(static_cast<char>((number >> 8) & 0xFF));
array.append(static_cast<char>(number & 0xFF));
QByteArray ary = Get_QByteArray(feature,startAdiss,array,0x00,static_cast<char>((Index >> 8) & 0xFF),static_cast<char>(Index & 0xFF));
if(ary.isEmpty()){return false;}


RV_t Read_Value;
Read_Value.Read_Data = ary;
Read_Value.callback = callback;

Modbus_TCP_Read_Map.insert(Index,Read_Value);
Index++;
return true;
}

void ModbusTcp::Execute_Callback(QByteArray Data)
{
quint16 Index = Data.mid(0,2).toHex().toUShort(nullptr,16); //头
quint16 fcd = Data.mid(7,1).toHex().toUShort(nullptr,16); //功能码

// qDebug()<<"Size::"<<Data.size() << "Data::" << Data;
// qDebug() << Index << "头" << fcd << "功能码";

if(Modbus_TCP_Read_Map.contains(Index)){
if(Modbus_TCP_Read_Map[Index].Before_Data != Data){
Modbus_TCP_Read_Map[Index].callback(Data);
Modbus_TCP_Read_Map[Index].Before_Data = Data;
}
}

}

QByteArray ModbusTcp::Get_QByteArray(char feature, ushort startAdiss, QByteArray &array, ushort sized, quint8 tAGMatterHi, quint8 tAGMatterLo)
{
ushort lenth = static_cast<ushort>(array.size());

if( lenth < 2) return "";

// QSharedPointer<MDBTData> code = QSharedPointer<MDBTData>(new MDBTData());

// code->ReadData.clear();
code->ReadData = { };
code->TAGMatterHi = tAGMatterHi;
code->TAGMatterLo = tAGMatterLo;
code->TAGProtocol = 0x0000;
code->TAGElement = 0x01;



switch (feature) {
case 0x01:
{//读线圈
code->NumLength = (0x06); //需要的长度 2byte(从本字节下一个到最后)
code->GetType = 0x01;//要数类型(功能码)1byte
code->ByteLength = startAdiss;//读取数据的开始位置2byte
code->ReadData.append(array,2);//读输入寄存器数量,2个字节
}
break;
case 0x02:
{//读离散输入
code->NumLength = (0x06); //需要的长度 2byte(从本字节下一个到最后)
code->GetType = 0x02;//要数类型(功能码)1byte
code->ByteLength = startAdiss;//读取数据的开始位置2byte
code->ReadData.append(array,2);//读输入寄存器数量,2个字节
}
break;
case 0x03:
{//读保持寄存器


code->NumLength = (0x06); //需要的长度 2byte(从本字节下一个到最后)
code->GetType = 0x03;//要数类型(功能码)1byte
code->ByteLength = startAdiss;//读取数据的开始位置2byte
code->ReadData.append(array,2);//读输入寄存器数量,2个字节 26个
}
break;
case 0x04:
{//读输入寄存器
code->NumLength = (0x06); //需要的长度 2byte(从本字节下一个到最后)
code->GetType = 0x04;//要数类型(功能码)1byte
code->ByteLength = startAdiss;//读取数据的开始位置2byte
code->ReadData.append(array,2);//读输入寄存器数量,2个字节
}
break;
case 0x05:
{//写单个线圈
code->NumLength = (0x06); //需要的长度 2byte(从本字节下一个到最后)
code->GetType = 0x05;//要数类型(功能码)1byte
code->ByteLength = startAdiss;//读取数据的开始位置2byte
code->ReadData.append(array,2);//写入数据
}
break;
case 0x06:
{//写单个保持寄存器
code->NumLength = (0x06); //需要的长度 2byte(从本字节下一个到最后)
code->GetType = 0x06;//要数类型(功能码)1byte
code->ByteLength = startAdiss;//读取数据的开始位置2byte
code->ReadData.append(array,2);//保持寄存器数据,n个字节
}
break;
case 0x0f:
{//写多个线圈
code->NumLength = (0x07 + lenth); //需要的长度 2byte(从本字节下一个到最后)
code->GetType = 0x0f;//要数类型(功能码)1byte
code->ByteLength = startAdiss;//读取数据的开始位置2byte
code->ReadData.append(sized);//要写入的数量,两个字节
code->ReadData.append(lenth);//数据长度(字节数),一个字节
code->ReadData.append(array,lenth);//保持寄存器数据,n个字节
}
break;
case 0x10:
{//写多个保持寄存器(此处的寄存器地址必须是连续的)
code->NumLength = (0x07 + lenth); //需要的长度 2byte(从本字节下一个到最后)
code->GetType = 0x10;//要数类型(功能码)1byte
code->ByteLength = startAdiss;//读取数据的开始位置2byte <--
ushort l = lenth / 2;
code->ReadData.append(l>>8);//要写入的数量,两个字节h
code->ReadData.append(l);//要写入的数量,两个字节l
code->ReadData.append(lenth);//数据长度(字节数),一个字节
code->ReadData.append(array,lenth);//保持寄存器数据,n个字节
}
break;
default:
qDebug()<<"erre: 功能码 不存在";
return "";
}

// =======================================
QByteArray ary;
ary.append(code->TAGMatterHi);
ary.append(code->TAGMatterLo);

ary.append((code->TAGProtocol & 0xFF00)>>8);
ary.append((code->TAGProtocol & 0x00FF));

ary.append((code->NumLength & 0xFF00)>>8);
ary.append((code->NumLength & 0x00FF));

ary.append(code->TAGElement);

ary.append(code->GetType);

ary.append((code->ByteLength & 0xFF00)>>8);
ary.append((code->ByteLength & 0x00FF));


ary.append(code->ReadData);

if(!ary.isEmpty()) {
return ary;
}
return "";
}

void ModbusTcp::Start_Read(int Sec)
{
_timing_map->start(Sec);
}

void ModbusTcp::Start_Queue(int Sec)
{
_timing->start(Sec);
}

void ModbusTcp::Thread_Rcv()
{
Start_Queue();
Start_Read();
}

bool ModbusTcp::QByte_ReadData()
{
QByteArray Data = _tcpClient->readAll();

if(!Data.isEmpty()){
int index = 0;
int netNum = 0;
while(index < Data.size())
{
const char Char = Data.at(index);

switch (_read_index){
case TAGMatterHi: {
++ index;
if (Char){
if(!_buffer.isEmpty()){_buffer.clear();}
_buffer.append(Char);
_read_index = TAGMatterLo;
}
continue;
}
case TAGMatterLo: {
_buffer.append(Char);
index ++;
_read_index = TAGProtocol;
continue;
}
case TAGProtocol: {
++ index;
++ netNum;
_buffer.append(Char);
if(netNum == 2){netNum = 0;_read_index = NumLength;}
continue;
}
case NumLength : {
++ index;
++ netNum;
_buffer.append(Char);
if(netNum == 2){netNum = 0;_read_index = TAGElement;}
continue;
}
case TAGElement: {
_buffer.append(Char);
index ++;
_read_index = GetType;
continue;
}
case GetType: {
_buffer.append(Char);
index ++;
_read_index = ByteLength;
continue;
}
case ByteLength: {
_buffer.append(Char);
index ++;
_toReadlen = static_cast<uchar>(Char);
_read_index = ReadData;
continue;
}
case ReadData: {
const int Count = Data.length() - index;

if (Count >= _toReadlen){
_buffer.append(Data.mid(index, _toReadlen));
index += _toReadlen;
_toReadlen = 0;
_read_index = TAGMatterHi; //先处理再清空
Execute_Callback(_buffer);
_buffer.clear();
continue;
}else{
_buffer.append(Data.mid(index, Count));
index += Count;
_toReadlen -= Count;
}
continue;
}
}

}
return true;
}
return false;
}

bool ModbusTcp::QByte_WriteData()
{
if(_wirteMsg->isEmpty() || !Get_Connect()){return false;}

return _tcpClient->write(_wirteMsg->dequeue());
}

void ModbusTcp::ReadError(QAbstractSocket::SocketError)
{
_tcpClient->disconnectFromHost();
}


//float 转字节数组
QByteArray ModbusTcp::floatBigendian(float input)
{
QByteArray data;
char p[4], q[4];
memcpy(p, &input, sizeof(input)); //cd ab abcd bcda 0123 2301 3201 3210 abcd 1032 cdab
q[0] = p[1];
q[1] = p[0];
q[2] = p[3];
q[3] = p[2];
data.append(QByteArray(q,4));
return data;
}

QByteArray ModbusTcp::doubleBigendian(double input)
{
QByteArray data;
char p[4], q[4];
memcpy(p, &input, sizeof(input));
q[0] = p[7];
q[1] = p[6];
q[2] = p[5];
q[3] = p[4];
q[4] = p[3];
q[5] = p[2];
q[6] = p[1];
q[7] = p[0];
data.append(QByteArray(q,8));
return data;
}

void ModbusTcp::Init_QTcpSocket()
{
if(_tcpClient == nullptr){
_tcpClient = new QTcpSocket();
connect(_tcpClient, SIGNAL(readyRead()), this, SLOT(QByte_ReadData()));
connect(_tcpClient, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(ReadError(QAbstractSocket::SocketError)));
}

}

void ModbusTcp::Init_Read()
{

Init_Read(0x03,10000,125,[=](QByteArray ary){MdbsTCP->Manage_10000(ary);});
Init_Read(0x03,10125,125,[=](QByteArray ary){MdbsTCP->Manage_10125(ary);});
Init_Read(0x03,10250,125,[=](QByteArray ary){MdbsTCP->Manage_10250(ary);});
Init_Read(0x03,10375,125,[=](QByteArray ary){MdbsTCP->Manage_10375(ary);});
Init_Read(0x03,10500,125,[=](QByteArray ary){MdbsTCP->Manage_10500(ary);});
Init_Read(0x03,10625,125,[=](QByteArray ary){MdbsTCP->Manage_10625(ary);});

Init_Read(0x03,15000,122,[=](QByteArray ary){MdbsTCP->Manage_15000(ary);});
Init_Read(0x03,15122,122,[=](QByteArray ary){MdbsTCP->Manage_15125(ary);});
Init_Read(0x03,15244,122,[=](QByteArray ary){MdbsTCP->Manage_15250(ary);});
Init_Read(0x03,15366,122,[=](QByteArray ary){MdbsTCP->Manage_15375(ary);});
Init_Read(0x03,15488,122,[=](QByteArray ary){MdbsTCP->Manage_15500(ary);});
Init_Read(0x03,15610,122,[=](QByteArray ary){MdbsTCP->Manage_15625(ary);});
Init_Read(0x03,15732,122,[=](QByteArray ary){MdbsTCP->Manage_15750(ary);});
Init_Read(0x03,15854,122,[=](QByteArray ary){MdbsTCP->Manage_15875(ary);});

Init_Read(0x03,16000,122,[=](QByteArray ary){MdbsTCP->Manage_16000(ary);});
Init_Read(0x03,16122,122,[=](QByteArray ary){MdbsTCP->Manage_16125(ary);});
Init_Read(0x03,16244,122,[=](QByteArray ary){MdbsTCP->Manage_16250(ary);});
Init_Read(0x03,16366,122,[=](QByteArray ary){MdbsTCP->Manage_16375(ary);});
Init_Read(0x03,16488,122,[=](QByteArray ary){MdbsTCP->Manage_16500(ary);});
Init_Read(0x03,16610,122,[=](QByteArray ary){MdbsTCP->Manage_16625(ary);});
Init_Read(0x03,16732,122,[=](QByteArray ary){MdbsTCP->Manage_16750(ary);});
Init_Read(0x03,16854,122,[=](QByteArray ary){MdbsTCP->Manage_16875(ary);});

Init_Read(0x03,20000,122,[=](QByteArray ary){MdbsTCP->Manage_20000(ary);});
Init_Read(0x03,20122,60,[=](QByteArray ary){MdbsTCP->Manage_20125(ary);});
}

void ModbusTcp::Manage_10000(QByteArray ary){
// Init_Read(ary,10000,9);

int startPoint = 10000;
int startIndex = 9;
for (int i = 0; i < 125; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(startPoint + 400001) << ":" << QString::number(shortFromBigEndian(ary.mid(startIndex,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(startPoint + 400001) << ":" << QString::number(floatFromBigEndian(ary.mid(startIndex,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(startPoint + 400001) << ":" << QString::number(longFromBigEndian(ary.mid(startIndex,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_10125(QByteArray ary){
// Init_Read(ary,10125,9);

int startPoint = 10125;
int startIndex = 9;
for (int i = 0; i < 125; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_10250(QByteArray ary){
// Init_Read(ary,10250,9);

int startPoint = 10250;
int startIndex = 9;
for (int i = 0; i < 125; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_10375(QByteArray ary){
// Init_Read(ary,10375,9);

int startPoint = 10375;
int startIndex = 9;
for (int i = 0; i < 125; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_10500(QByteArray ary){
// Init_Read(ary,10500,9);

int startPoint = 10500;
int startIndex = 9;
for (int i = 0; i < 125; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_10625(QByteArray ary){
// Init_Read(ary,10625,9);

int startPoint = 10625;
int startIndex = 9;
for (int i = 0; i < 125; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_10750(QByteArray ary){
// Init_Read(ary,10750,9);

int startPoint = 10750;
int startIndex = 9;
for (int i = 0; i < 125; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_10875(QByteArray ary){
// Init_Read(ary,10875,9);

int startPoint = 10875;
int startIndex = 9;
for (int i = 0; i < 125; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_15000(QByteArray ary){
// Init_Read(ary,15000,9);

int startPoint = 15000;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_15125(QByteArray ary){
// Init_Read(ary,15122,9);

int startPoint = 15122;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_15250(QByteArray ary){
// Init_Read(ary,15244,9);

int startPoint = 15244;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_15375(QByteArray ary){
// Init_Read(ary,15366,9);

int startPoint = 15366;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_15500(QByteArray ary){
// Init_Read(ary,15488,9);

int startPoint = 15488;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_15625(QByteArray ary){
// Init_Read(ary,15610,9);

int startPoint = 15610;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(startPoint + 400001) << ":" << QString::number(shortFromBigEndian(ary.mid(startIndex,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(startPoint + 400001) << ":" << QString::number(floatFromBigEndian(ary.mid(startIndex,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(startPoint + 400001) << ":" << QString::number(longFromBigEndian(ary.mid(startIndex,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_15750(QByteArray ary){
// Init_Read(ary,15732,9);

int startPoint = 15732;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_15875(QByteArray ary){
// Init_Read(ary,15854,9);

int startPoint = 15854;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_16000(QByteArray ary){
// Init_Read(ary,16000,9);

int startPoint = 16000;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_16125(QByteArray ary){
// Init_Read(ary,16122,9);

int startPoint = 16122;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_16250(QByteArray ary){
// Init_Read(ary,16244,9);

int startPoint = 16244;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_16375(QByteArray ary){
// Init_Read(ary,16366,9);

int startPoint = 16366;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_16500(QByteArray ary){
// Init_Read(ary,16488,9);

int startPoint = 16488;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_16625(QByteArray ary){
// Init_Read(ary,16610,9);

int startPoint = 16610;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_16750(QByteArray ary){
// Init_Read(ary,16732,9);

int startPoint = 16732;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
};
void ModbusTcp::Manage_16875(QByteArray ary){
// Init_Read(ary,16854,9);

int startPoint = 16854;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
}
void ModbusTcp::Manage_20000(QByteArray ary){
// Init_Read(ary,20000,9);

int startPoint = 20000;
int startIndex = 9;
for (int i = 0; i < 122; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
}
void ModbusTcp::Manage_20125(QByteArray ary){
int startPoint = 20122;
int startIndex = 9;
for (int i = 0; i < 60; ++i) {
if (startIndex + 2 >= ary.size()){
break;
}

if (_POINT_TYPE.contains(startPoint + 400001)){
int l = _POINT_TYPE.value(startPoint + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(shortFromBigEndian(ary.mid(startIndex,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
startIndex = startIndex + 2;
startPoint = startPoint + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(floatFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(startPoint + 400001), QString::number(longFromBigEndian(ary.mid(startIndex,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
startIndex = startIndex + 4;
startPoint = startPoint + 2;
}else{
startPoint = startPoint + 1;
}
} else{
startPoint = startPoint + 1;
startIndex = startIndex + 2;
}
}
}

void ModbusTcp::Init_Read(QByteArray Array,int ids,int stw)
{
for (int i = 0; i < 125; ++i) {
if (stw + 2 >= Array.size()){
break;
}
if (_POINT_TYPE.contains(ids + 400001)){
int l = _POINT_TYPE.value(ids + 400001);
if (l == 1){
GLOBAL->point_value.insert(QString::number(ids + 400001), QString::number(shortFromBigEndian(Array.mid(stw,2))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(shortFromBigEndian(Array.mid(stw,2)));
stw = stw + 2;
ids = ids + 1;
}
else if (l == 2){
GLOBAL->point_value.insert(QString::number(ids + 400001), QString::number(floatFromBigEndian(Array.mid(stw,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(floatFromBigEndian(Array.mid(stw,4)));
stw = stw + 4;
ids = ids + 2;
}
else if (l == 3){
GLOBAL->point_value.insert(QString::number(ids + 400001), QString::number(longFromBigEndian(Array.mid(stw,4))));
// qDebug() << QString::number(ids + 400001) << ":" << QString::number(longFromBigEndian(Array.mid(stw,4)));
stw = stw + 4;
ids = ids + 2;
}else{
ids = ids + 1;
}
} else{
ids = ids + 1;
stw = stw + 2;
}
}
}




QByteArray ModbusTcp::shortBigendian(short input)
{
QByteArray data;
char p[2], q[2];
memcpy(p, &input, sizeof(input));
q[0] = p[1];
q[1] = p[0];
data.append(QByteArray(q,2));
return data;
}
//字节数组转 float// huichuan shun xu bu dui
float ModbusTcp::floatFromBigEndian(QByteArray data)
{
if (data.size() < 4) {
return 0.0f;
}

// 使用CDAB格式将4个字节拼接为32位整数
quint32 intRepresentation =
(static_cast<quint8>(data[2]) << 24) | // C -> 高位
(static_cast<quint8>(data[3]) << 16) | // D
(static_cast<quint8>(data[0]) << 8) | // A
(static_cast<quint8>(data[1])); // B -> 低位

// 将32位整数转换为float
float result;
memcpy(&result, &intRepresentation, sizeof(result));
return result;
}


short ModbusTcp::shortFromBigEndian(const QByteArray &data)
{
if (data.size() < 2){
return 0;
}
// 使用静态转换和移位操作来替换 memcpy
short _short = static_cast<short>((static_cast<quint8>(data[0]) << 8) | static_cast<quint8>(data[1]));
return _short;
}

ushort ModbusTcp::ushortFromBigEndian(const QByteArray &data)
{
char q[2];
ushort _short;
q[0] = data[1];
q[1] = data[0];
memcpy(&_short, q, sizeof(ushort));
return _short;
}

long ModbusTcp::longFromBigEndian(const QByteArray &data)
{
if (data.size() < 4) {
return 0;
}

// 使用移位和按位或将4个字节拼接为32位整数
// 使用CDAB格式将4个字节拼接为32位整数
qint32 result =
(static_cast<quint8>(data[2]) << 24) | // C -> 高位
(static_cast<quint8>(data[3]) << 16) | // D
(static_cast<quint8>(data[0]) << 8) | // A
(static_cast<quint8>(data[1])); // B -> 低位


return result;
}


short ModbusTcp::toShort(QByteArray ary)
{
if(ary.size() < 2) return 0;
int b = ary[0];
short a = 0;
a = a | (b<<8);
b = ary[1];
a = a | b;

return a;
}

float ModbusTcp::toFloat(QByteArray ary)
{
char q[4];
float _float;
q[0] = ary[0];
q[1] = ary[1];
q[2] = ary[2];
q[3] = ary[3];
memcpy(&_float, q, sizeof(float));
return _float;
}

QByteArray ModbusTcp::floatToByte(float input)
{
QByteArray data;

char p[4], q[4];
memcpy(p, &input, sizeof(input));
q[0] = p[0];
q[1] = p[1];
q[2] = p[2];
q[3] = p[3];
data.append(QByteArray(q,4));

return data;
}
QByteArray ModbusTcp::shortToByte(short input)
{
QByteArray data;

char p[2], q[2];
memcpy(p, &input, sizeof(input));
q[0] = p[0];
q[1] = p[1];
data.append(QByteArray(q,2));

return data;
}

-------------本文结束感谢您的阅读-------------