1
|
// Modbus_Tcpc.h: Modbus_Tcpc DLL ??????ͷ?ļ?
|
2
|
//
|
3
|
|
4
|
#pragma once
|
5
|
|
6
|
#if !defined __MODBUS_TCPC_H__
|
7
|
#define __MODBUS_TCPC_H__
|
8
|
|
9
|
|
10
|
#if _MSC_VER > 1000
|
11
|
#pragma once
|
12
|
#endif // _MSC_VER > 1000
|
13
|
|
14
|
#include "daq/daq_protocol.h"
|
15
|
#include <string.h>
|
16
|
|
17
|
#if !defined(FALSE)
|
18
|
#define FALSE 0
|
19
|
#endif
|
20
|
#define MAX_BYTE_NUM 250
|
21
|
#define MAX_FUNC_TYPE 43
|
22
|
#define MAX_CNT_NUM 3
|
23
|
|
24
|
|
25
|
|
26
|
class CModbusTcpc : public CProtocol {
|
27
|
|
28
|
protected:
|
29
|
struct Data {
|
30
|
uint16 datauint16;
|
31
|
sint16 datasint16;
|
32
|
float32 datafloat;
|
33
|
sint32 datasint32;
|
34
|
uint32 datauint32;
|
35
|
};
|
36
|
|
37
|
struct map {
|
38
|
uint32 address;
|
39
|
uint32 pointnum;
|
40
|
uint8 m_type;
|
41
|
uint8 r_type;
|
42
|
Data data;
|
43
|
uint8 start;
|
44
|
uint8 end;
|
45
|
uint8 visited;
|
46
|
}*maplist;
|
47
|
|
48
|
|
49
|
struct cmd {
|
50
|
uint32 pointnum;
|
51
|
uint32 address;
|
52
|
uint8 m_type;
|
53
|
uint8 group;
|
54
|
uint8 func;
|
55
|
uint8 r_type;
|
56
|
uint8 va;
|
57
|
uint8 start;
|
58
|
uint8 end;
|
59
|
}*cmdlist;
|
60
|
|
61
|
sint64 m_LastSendTime; //?????ʱ??
|
62
|
sint64 m_RcvTimeOuts; //?????ij?ʱʱ??
|
63
|
sint32 **duqu;//??ȡ?????????ļ?
|
64
|
sint32 duqulength; //?????ļ?????
|
65
|
sint32 maplength; //???е?????
|
66
|
|
67
|
sint64 sleeptime; //ʹ???ٻ?ȫ???????ڵ?ֵ???????ͺ?λS
|
68
|
sint64 sleepstarttime;
|
69
|
bool readcfgflag; //??ȡ?????ļ???־
|
70
|
|
71
|
sint32 cmdlength;
|
72
|
|
73
|
sint32 m_SyncTime; //ͬ??ʱ????
|
74
|
uint16 cnt_sequence; //????????????Ϊ65535??2^16-1
|
75
|
|
76
|
ST_TRACK_ADDR m_cmdaddr; //?????ⲿ???ͨ???˱????????ⲿ?????ַ??Ϣ
|
77
|
// uint16 m_cmdsrc_rtu;
|
78
|
// PIPE_LABLE m_cmdsrc;
|
79
|
|
80
|
uint32 mapnum; //??¼???е??Ƿ????
|
81
|
uint32 mapIndex; //??¼??ϵͳ???ȡ??λ??
|
82
|
uint32 duquIndex; //??¼ÿһ?ζ?ȡ??λ??
|
83
|
uint8 WillSendType; //?????Ĺ???????
|
84
|
uint32 visitednum; //??¼??????Ƿ????
|
85
|
uint32 scopeDI; //??¼ÿһ??DI??ȡ????
|
86
|
uint32 scopeAI;
|
87
|
uint32 IndexDI; //??ǰ??ȡ????DI??ַ
|
88
|
uint32 IndexAI;
|
89
|
uint16 numDI; //???ζ?ȡ?ĵ?DI????
|
90
|
uint16 numAI;
|
91
|
|
92
|
bool err;
|
93
|
uint8 Policy; //????״̬?????л??߷?æ????policyΪ0ʱ????????ȡң??ң?⣬???Ϊ1???????ⲿ????
|
94
|
// ??д
|
95
|
bool startFlag; //?߳????????˳???־
|
96
|
public:
|
97
|
CModbusTcpc();
|
98
|
virtual ~CModbusTcpc();
|
99
|
|
100
|
virtual sint32 RxProc();
|
101
|
virtual sint32 TxProc();
|
102
|
virtual sint32 GetZfFlag() { return 0; };
|
103
|
virtual void Init(S_PROTOCOLCFG* pcfg);
|
104
|
|
105
|
protected:
|
106
|
uint8 OperateRegister(uint8 FuncNo, uint16 Address, sint16 Value);
|
107
|
uint8 OperateRegister(uint8 FuncNo, uint16 Address, uint16 Value);
|
108
|
uint8 Operate_16(uint16 Address, uint16 num, uint16 Value, uint8 func);
|
109
|
uint8 Operate_16(uint16 Address, uint16 num, sint16 Value, uint8 func);
|
110
|
uint8 ProcCmd();
|
111
|
void putYXYC();
|
112
|
void GetWillSendType();
|
113
|
int ComparePoint(uint16 YxYcId, uint8& value);
|
114
|
int ComparePoint_reg(uint16 YxYcId, uint8* buf, int i);
|
115
|
sint32 CheckFrameHeader(uint8* buff, sint32 len);
|
116
|
uint8 ErrorHandle(uint8 errfunc);
|
117
|
sint64 GetNowMilliSecond();
|
118
|
|
119
|
void ReadCfg();
|
120
|
};
|
121
|
#endif
|