-
Notifications
You must be signed in to change notification settings - Fork 1
/
c_mb_tcp_master_trans.cpp
74 lines (63 loc) · 1.58 KB
/
c_mb_tcp_master_trans.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
#include "c_mb_tcp_master_trans.h"
int C_MB_tcp_master_trans::m_indexID = 0;
C_MB_tcp_master_trans::C_MB_tcp_master_trans(QObject *parent) : QObject(parent)
{
this->m_transID = ++C_MB_tcp_master_trans::m_indexID;
connect(&this->m_timer,&QTimer::timeout,this,&C_MB_tcp_master_trans::slot_timer);
}
void C_MB_tcp_master_trans::slot_timer()
{
MBRequestTransEx trans;
trans.trans = this->m_trans.trans;
trans.transID = this->m_transID;
emit sig_reuest(trans); // 定时发送总线请求信号
}
void C_MB_tcp_master_trans::setQueryTrans(const MBRequestTransInfo &trans)
{
this->m_trans = trans;
}
void C_MB_tcp_master_trans::start()
{
if(!this->m_timer.isActive())
{
this->m_timer.start(this->m_trans.timeGap*1000);
}
}
void C_MB_tcp_master_trans::stop()
{
if(this->m_timer.isActive())
{
this->m_timer.stop();
}
}
int C_MB_tcp_master_trans::transID()
{
return this->m_transID;
}
//正常应答
void C_MB_tcp_master_trans::replyProc(int transID, quint8 slaveAdr, enumMB_FuncCode fcode, MB_ReplyBody body)
{
if(transID!=this->m_transID)
{
return;
}
if(slaveAdr!=this->m_trans.trans.slaveAdr)
{
return;
}
if(fcode!=this->m_trans.trans.funcCode)
{
return;
}
// ... 解析数据
QString strT;
qDebug()<<"********"<<transID<<slaveAdr<<fcode;
body.reg.clear();
}
void C_MB_tcp_master_trans::replyErr(int transID, quint8 slaveAdr, enumMB_FuncCode fcode, RTU_Master_ErrCode errcode)
{
transID =transID;
slaveAdr =slaveAdr;
fcode = fcode;
errcode = errcode;
}