提交 | 用户 | age
|
418cb3
|
1 |
#pragma once
|
Q |
2 |
// 下列 ifdef 块是创建使从 DLL 导出更简单的
|
|
3 |
// 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 MDH_SOCKET_EXPORTS
|
|
4 |
// 符号编译的。在使用此 DLL 的
|
|
5 |
// 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
|
|
6 |
// MDH_SOCKET_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
|
|
7 |
// 符号视为是被导出的。
|
|
8 |
#ifdef KLINK_EXPORTS
|
|
9 |
#define KLINK1_API __declspec(dllexport)
|
|
10 |
#else
|
|
11 |
#define KLINK1_API __declspec(dllimport)
|
|
12 |
#endif
|
|
13 |
|
|
14 |
//#include "KDefine.h"
|
|
15 |
#include <functional>
|
|
16 |
/*
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
*/
|
|
21 |
#include "HvSerialPort.h"
|
|
22 |
//AFX_EXT_CLASS
|
|
23 |
// 此类是从KLink1.dll 导出的
|
|
24 |
class KLINK1_API KLink1 {
|
|
25 |
|
61deef
|
26 |
enum enServiceReqs
|
Q |
27 |
{
|
|
28 |
ReqNone,
|
|
29 |
ReqInit,
|
|
30 |
ReqReset,
|
|
31 |
ReqStop,
|
|
32 |
ReqRun,
|
|
33 |
ReqBlinkLED,
|
|
34 |
ReqStartDiag,
|
|
35 |
ReqStopDiag,
|
|
36 |
ReqPortChildInfo,
|
|
37 |
ReqPortChnInfo,
|
|
38 |
ReqUpdateFirm,
|
|
39 |
ReqUpdateFirmInfo,
|
|
40 |
|
|
41 |
ReqTransFirmware,
|
|
42 |
ReqTransCfg,
|
|
43 |
ReqTransProg,
|
|
44 |
ReqTransData,
|
|
45 |
ReqTransBlink,
|
|
46 |
ReqTransChild,
|
|
47 |
ReqTransInfo,
|
|
48 |
ReqTransOutBandData,
|
|
49 |
ReqRead1Bit,
|
|
50 |
ReqWrite1Bit,
|
|
51 |
ReqReadBits,
|
|
52 |
ReqWriteBits,
|
|
53 |
ReqReadData,
|
|
54 |
ReqWriteData,
|
|
55 |
ReqRemoteTran,
|
|
56 |
};
|
418cb3
|
57 |
|
Q |
58 |
typedef unsigned char UCHAR;
|
|
59 |
typedef unsigned short USHORT;
|
|
60 |
typedef unsigned int UINT;
|
|
61 |
|
|
62 |
public:
|
|
63 |
KLink1();
|
|
64 |
virtual ~KLink1();
|
|
65 |
|
|
66 |
HvSerialPort1 MySerPort1;
|
|
67 |
int m_bCommParamSet = 0;
|
61deef
|
68 |
int m_nPort=1;
|
Q |
69 |
int m_nBaudRate=115200;
|
|
70 |
CString m_Settings=_T("8,N,1");
|
|
71 |
/*
|
|
72 |
int m_nDefaultPort=1;
|
|
73 |
int m_nDefaultBaudRate=115200;
|
|
74 |
CString m_DefaultSettings=_T("8,N,1");
|
|
75 |
*/
|
418cb3
|
76 |
|
Q |
77 |
#define TYPECOIL 0x00
|
|
78 |
#define TYPEDATA 0x80
|
|
79 |
enum enKLCoilTypes
|
|
80 |
{
|
|
81 |
KLCoilTypeX = 0 | TYPECOIL, //X Input
|
|
82 |
KLCoilTypeY = 1 | TYPECOIL, //Y Output
|
|
83 |
KLCoilTypeR = 2 | TYPECOIL, //R register
|
|
84 |
KLCoilTypeLX = 3 | TYPECOIL, //Link register
|
|
85 |
KLCoilTypeLY = 4 | TYPECOIL, //Link register
|
|
86 |
KLCoilTypeT = 5 | TYPECOIL, //Timer
|
|
87 |
KLCoilTypeC = 6 | TYPECOIL, //Counter
|
|
88 |
KLCoilTypeLR = 7 | TYPECOIL, //Link register
|
|
89 |
KLCoilTypeSR = 8 | TYPECOIL, //Link register
|
|
90 |
|
|
91 |
|
|
92 |
};
|
|
93 |
enum enKLDataTypes
|
|
94 |
{
|
|
95 |
KLDataTypeDEC = 0 | TYPEDATA,
|
|
96 |
KLDataTypeHEX = 1 | TYPEDATA,
|
|
97 |
KLDataTypeFloat = 2 | TYPEDATA,
|
|
98 |
KLDataTypeWX = 3 | TYPEDATA,
|
|
99 |
KLDataTypeWY = 4 | TYPEDATA,
|
|
100 |
KLDataTypeWR = 5 | TYPEDATA,
|
|
101 |
KLDataTypeWLX = 6 | TYPEDATA,
|
|
102 |
KLDataTypeWLY = 7 | TYPEDATA,
|
|
103 |
KLDataTypeDT = 8 | TYPEDATA,
|
|
104 |
KLDataTypeSDT = 9 | TYPEDATA,
|
|
105 |
KLDataTypeWSR = 10 | TYPEDATA,
|
|
106 |
KLDataTypeSV = 11 | TYPEDATA,
|
|
107 |
KLDataTypeEV = 12 | TYPEDATA,
|
|
108 |
KLDataTypeLD = 13 | TYPEDATA,
|
|
109 |
KLDataSysCfg = 25 | TYPEDATA,
|
|
110 |
KLDataTypeFlash = 33 | TYPEDATA,
|
|
111 |
KLDataTypeWDT = 41 | TYPEDATA,
|
|
112 |
KLDataTypeKBD = 51 | TYPEDATA,
|
|
113 |
KLDataTypeKWLD = 52 | TYPEDATA,
|
|
114 |
KLDataTypeTest = 254 | TYPEDATA,
|
|
115 |
};
|
|
116 |
|
|
117 |
typedef struct tagKLTypeName
|
|
118 |
{
|
|
119 |
int nType;
|
|
120 |
const char * sName;
|
|
121 |
int nRange = 0;
|
|
122 |
}stKLTypeName;
|
|
123 |
|
|
124 |
static const stKLTypeName KLCoilTypeNames[];
|
|
125 |
static const stKLTypeName KLDataTypeNames[];
|
|
126 |
|
|
127 |
enum eKLResult
|
|
128 |
{
|
|
129 |
KL_ERR = -1,
|
|
130 |
KL_OK = 0,
|
|
131 |
KL_NG = 1,
|
|
132 |
KL_UNKNOWN = 2,
|
|
133 |
KL_TIMEOUT = 3,
|
|
134 |
KL_BCC_ERR = 4,
|
|
135 |
KL_PKG_ERR = 5,
|
|
136 |
KL_SEQ_ERR = 6,
|
|
137 |
KL_LENTH_EXCEED,
|
|
138 |
KL_NEED_PASS,
|
|
139 |
KL_NOT_SUPPORT,
|
|
140 |
};
|
|
141 |
|
61deef
|
142 |
static const char * GetErrDescStr(int nErrNo);
|
418cb3
|
143 |
|
Q |
144 |
enum
|
|
145 |
{
|
|
146 |
KLSignStart = '%',
|
|
147 |
KLSignReply = 'U',
|
|
148 |
KLSignEnd = 0x0D,
|
|
149 |
KLMaxPacketLength = 128,
|
|
150 |
|
|
151 |
};
|
|
152 |
enum ExtraDataType
|
|
153 |
{
|
|
154 |
KLExtTypeNone = 0,
|
|
155 |
KLExtTypeText = 1,
|
|
156 |
KLExtTypeCmd = 2,
|
|
157 |
KLExtTypePassTh = 3,
|
|
158 |
|
|
159 |
KLExtTypeTestData = 8,
|
|
160 |
};
|
|
161 |
|
|
162 |
enum enCMDs
|
|
163 |
{
|
|
164 |
// cmdOK = '1', //Reply OK
|
|
165 |
// cmdNG = '2', //Rplay NG
|
|
166 |
KLCmdNone = 0x00, //Nothing
|
|
167 |
KLCmdPing = 0x01, //Ping
|
|
168 |
KLCmdPingReply = 0x02, //PingReply
|
|
169 |
KLCmdGetInfo = 0x03, //GetInfo
|
|
170 |
KLCmdVerInfo = 0x04, //InfoReply
|
|
171 |
|
|
172 |
KLCmdRead = 0x05, //Read
|
|
173 |
KLCmdReadReply = 0x06, //ReadReply
|
|
174 |
KLCmdWrite = 0x07, //Write
|
|
175 |
KLCmdWriteReply = 0x08, //WriteReply
|
|
176 |
KLCmdSaveToFlash = 0x09, //Write
|
|
177 |
|
|
178 |
KLCmdExChgData = 0x0A, //ExChangeDate, = Wirte + Read
|
|
179 |
KLCmdExChgDataReply, //ExchangeData Reply
|
|
180 |
|
|
181 |
KLCmdSyncRead = 0x0D, //SyncRead
|
|
182 |
KLCmdSyncWrite, //SyncWrite
|
|
183 |
KLCmdSequenRead, //Sequence Read
|
|
184 |
KLCmdSyncTime, //SyncTime
|
|
185 |
|
|
186 |
KLCmdChgMode = 0x11,
|
|
187 |
KLCmdGetMode = 0x12,
|
|
188 |
|
|
189 |
KLCmdChkPass,
|
|
190 |
KLCmdSetPass,
|
|
191 |
KLCmdEraseAll,
|
|
192 |
KLCmdReadProgram,
|
|
193 |
KLCmdStartProgram,
|
|
194 |
KLCmdWriteProgram,
|
|
195 |
KLCmdFinishProgram,
|
61deef
|
196 |
KLCmdReadPLCAnno,
|
Q |
197 |
KLCmdStartPLCAnno,
|
|
198 |
KLCmdWritePLCAnno,
|
|
199 |
KLCmdFinishPLCAnno,
|
418cb3
|
200 |
|
Q |
201 |
KLCmdRead1Bit = 0x21, //ReadSingleBit
|
|
202 |
KLCmdWrite1Bit = 0x22, //WriteSingleBit
|
|
203 |
|
|
204 |
KLCmdReadBits = 0x23, //ReadBits n = 1 - 8
|
|
205 |
KLCmdWriteBits = 0x24, //ReadBits n = 1 - 8
|
|
206 |
|
|
207 |
KLCmdReadBitsByByte = 0x25, //ReadBitsByByte ,byteCount
|
|
208 |
KLCmdWriteBitsByByte = 0x26, //ReadBitsByByte ,ByteCount
|
|
209 |
|
|
210 |
KLCmdReadBitsByWord = 0x27, //ReadBitsByWord ,WordCount
|
|
211 |
KLCmdWriteBitsByWord = 0x28, //ReadBitsByWord ,WordCount
|
|
212 |
|
|
213 |
KLCmdReadDataByte = 0x31, //ByteCount
|
|
214 |
KLCmdWriteDataByte = 0x32,
|
|
215 |
|
|
216 |
KLCmdReadDataWord = 0x33, //WordCount
|
|
217 |
KLCmdWriteDataWord = 0x34,
|
|
218 |
|
|
219 |
KLCmdReadData = 0x35, //?Count
|
|
220 |
KLCmdWriteData = 0x36,
|
|
221 |
|
|
222 |
KLCmdStopBlinkLED = 0x4f,
|
|
223 |
KLCmdBlinkLED = 0x50,
|
|
224 |
|
|
225 |
KLCmdReadProg = 0x51,
|
|
226 |
KLCmdWriteProg,
|
|
227 |
KLCmdReadSysCfg,
|
|
228 |
KLCmdWriteSysCfg,
|
|
229 |
KLCmdSaveSysCfg,
|
|
230 |
KLCmdSaveRunStat,
|
|
231 |
KLCmdReadRunStat,
|
|
232 |
KLCmdClearRunStat,
|
|
233 |
|
|
234 |
KLCmdEraseFlashPage = 0x61,
|
|
235 |
KLCmdWriteToFlash = 0x62,
|
|
236 |
|
|
237 |
KLCmdGetEventLogCount,
|
|
238 |
KLCmdGetEventLog,
|
|
239 |
KLCmdClearEventLog,
|
|
240 |
KLCmdGetFactoryData,
|
|
241 |
KLCmdWriteFactoryData,
|
|
242 |
KLCmdResetMachine,
|
|
243 |
KLCmdGetUid,
|
|
244 |
KLCmdSetTime,
|
|
245 |
KLCmdGetSN,
|
|
246 |
|
|
247 |
|
|
248 |
KLCmdMC = 0x70,
|
|
249 |
KLCmdMD,
|
|
250 |
KLCmdMG,
|
61deef
|
251 |
|
Q |
252 |
KLCmdWriteFirmware,
|
|
253 |
KLCmdWriteFirmInfo,
|
|
254 |
KLCmdGetPortInfo,
|
|
255 |
KLCmdGetPortChnInfo,
|
|
256 |
KLCmdGetPortChildInfo,
|
|
257 |
KLCmdPortRemoteReq,
|
418cb3
|
258 |
KLCmdThrough,
|
Q |
259 |
|
|
260 |
KLCmdErrRply = 0xEE, //ERRORReply
|
|
261 |
};
|
|
262 |
|
|
263 |
typedef struct tagRunStat
|
|
264 |
{
|
|
265 |
unsigned short Sign1;
|
|
266 |
unsigned short Seq1;
|
|
267 |
volatile unsigned short PowerCount; //
|
|
268 |
volatile unsigned short Reserved1;
|
|
269 |
volatile unsigned int UpTime; //Seconds;
|
|
270 |
volatile unsigned int UserData1;
|
|
271 |
volatile unsigned short WorkMode;
|
|
272 |
volatile unsigned short WorkMode2;
|
|
273 |
volatile unsigned short nBinProgBank;
|
|
274 |
volatile unsigned short nBinProgSize;
|
df0321
|
275 |
unsigned short bLEDFlick;
|
Q |
276 |
unsigned short Reserved2[1];
|
418cb3
|
277 |
unsigned short CRC1;
|
Q |
278 |
unsigned short EndSign1;
|
|
279 |
}stRunStat, *pRunStat;
|
|
280 |
|
|
281 |
stRunStat KMRunStat;
|
|
282 |
|
|
283 |
enum enKeventType
|
|
284 |
{
|
|
285 |
EventTypeNone = 0,
|
|
286 |
EventTypePowerUp = 1,
|
|
287 |
EventTypePowerDown = 2,
|
|
288 |
EventTypePowerRecover = 3,
|
|
289 |
EventTypeConnected = 4,
|
|
290 |
EventTypeLostCon = 5,
|
|
291 |
EventTypeSetTime = 6,
|
|
292 |
EventTypeSysCfg = 7,
|
|
293 |
EventTypeProg = 8,
|
|
294 |
EventTypeForce = 9,
|
|
295 |
EventTypeClearEvent = 10,
|
|
296 |
|
|
297 |
EventType
|
|
298 |
};
|
|
299 |
|
|
300 |
typedef struct tagEventLog
|
|
301 |
{
|
|
302 |
unsigned short Sign1;
|
|
303 |
unsigned short Seq1;
|
|
304 |
unsigned int nTime;
|
|
305 |
unsigned short nType;
|
|
306 |
unsigned short nParam1;
|
|
307 |
unsigned int nParam2;
|
|
308 |
}stEventLog, *pEventLog;
|
|
309 |
|
|
310 |
|
|
311 |
typedef struct tagKLCmdName
|
|
312 |
{
|
|
313 |
const int nCmd;
|
|
314 |
const char * sName;
|
|
315 |
const char * sType;
|
|
316 |
|
|
317 |
}KLCmdName;
|
|
318 |
|
|
319 |
const KLCmdName KLCmdNames[42] =
|
|
320 |
{
|
|
321 |
{KLCmdNone,"None",""}, //==0 //Nothing
|
|
322 |
{KLCmdPing,"Ping"}, //=1 //Ping
|
|
323 |
{KLCmdPingReply,"PingReply"}, //2 //PingReply
|
|
324 |
{KLCmdGetInfo,"GetInfo"},//3 //GetInfo
|
|
325 |
{KLCmdVerInfo,"VerInfo"},// = 0x04, //InfoReply
|
|
326 |
|
|
327 |
{KLCmdRead,"Read","WX;WY;DT;SDT;EV;SV;LD;WL;CFG;FLASH;RAM"},// = 0x05, //Read
|
|
328 |
{KLCmdReadReply,"ReadReply"},// = 0x06, //ReadReply
|
|
329 |
{KLCmdWrite,"Write"},// = 0x07, //Write
|
|
330 |
{KLCmdWriteReply,"WriteReply"},// = 0x08, //WriteReply
|
|
331 |
{KLCmdSaveToFlash,"SaveToFlash"},// = 0x09, //Write
|
|
332 |
|
|
333 |
{KLCmdExChgData,"ExChgData"},// = 0x0A, //ExChangeDate, = Wirte + Read
|
|
334 |
{KLCmdExChgDataReply,"ExChgDataReply"},//, //ExchangeData Reply
|
|
335 |
|
|
336 |
{ KLCmdSyncRead,"SyncRead"},// = 0x0D, //SyncRead
|
|
337 |
{ KLCmdSyncWrite, "SyncWrite"},// //SyncWrite
|
|
338 |
{ KLCmdSequenRead,"SequenRead"},// //Sequence Read
|
|
339 |
{ KLCmdSyncTime,"SyncTime"},// //SyncTime
|
|
340 |
|
|
341 |
{ KLCmdGetMode,"GetMode"},// = 0x12,
|
|
342 |
|
|
343 |
{ KLCmdChkPass,"ChkPass"},//
|
|
344 |
{ KLCmdSetPass,"SetPass"},//
|
|
345 |
{ KLCmdEraseAll,"EraseAll"},//
|
|
346 |
{ KLCmdReadProgram,"ReadProgram"},//
|
|
347 |
{ KLCmdWriteProgram,"WriteProgram"},//
|
|
348 |
|
|
349 |
{ KLCmdRead1Bit,"Read1Bit"},// = 0x21, //ReadSingleBit
|
|
350 |
{ KLCmdWrite1Bit,"Write1Bit"},// = 0x22, //WriteSingleBit
|
|
351 |
|
|
352 |
{ KLCmdReadBits,"ReadBits"},// = 0x23, //ReadBits n = 1 - 8
|
|
353 |
{ KLCmdWriteBits,"WriteBits"},// = 0x24, //ReadBits n = 1 - 8
|
|
354 |
|
|
355 |
{ KLCmdReadBitsByByte,"ReadBitsByByte"},// = 0x25, //ReadBitsByByte
|
|
356 |
{ KLCmdWriteBitsByByte,"WriteBitsByByte"},// = 0x26, //ReadBitsByByte
|
|
357 |
|
|
358 |
{ KLCmdReadBitsByWord,"ReadBitsByWord"},// = 0x27, //ReadBitsByWord
|
|
359 |
{ KLCmdWriteBitsByWord,"WriteBitsByWord"},// = 0x28, //ReadBitsByWord
|
|
360 |
|
|
361 |
{ KLCmdReadDataByte,"ReadDataByte"},// = 0x31,
|
|
362 |
{ KLCmdWriteDataByte,"WriteDataByte"},// = 0x32,
|
|
363 |
|
|
364 |
{ KLCmdReadDataWord,"ReadDataWord"},// = 0x33,
|
|
365 |
{ KLCmdWriteDataWord,"WriteDataWord"},// = 0x34,
|
|
366 |
|
|
367 |
{ KLCmdReadData,"ReadData"},// = 0x35,
|
|
368 |
{ KLCmdWriteData,"WriteData"},// = 0x36,
|
|
369 |
|
|
370 |
{ KLCmdReadProg,"ReadProg"},// = 0x51,
|
|
371 |
{ KLCmdWriteProg,"WriteProg"},//
|
|
372 |
{ KLCmdReadSysCfg,"ReadSysCfg"},//
|
|
373 |
{ KLCmdWriteSysCfg,"WriteSysCfg"},//
|
|
374 |
|
|
375 |
{ KLCmdSaveSysCfg,"SaveSysCfg"},//
|
|
376 |
// KLCmdReadRunStat,
|
|
377 |
|
|
378 |
|
|
379 |
{ KLCmdErrRply,"ErrRply"}// = 0xEE, //ERRORReply
|
|
380 |
};
|
|
381 |
|
|
382 |
typedef struct tagKLExtDataFrame
|
|
383 |
{
|
|
384 |
UCHAR Dst;
|
|
385 |
UCHAR nType;
|
|
386 |
UCHAR Len2;
|
|
387 |
UCHAR Data[1];
|
|
388 |
}*pKLExtDataFrame;
|
|
389 |
|
|
390 |
|
|
391 |
typedef union tagKLStatDef
|
|
392 |
{
|
|
393 |
UCHAR StatByte;
|
|
394 |
struct {
|
|
395 |
UCHAR nSEQ : 4;
|
|
396 |
UCHAR HasExt : 1;
|
|
397 |
UCHAR HasErr : 1;
|
|
398 |
};
|
|
399 |
}unKLStat, *pKLStat;
|
|
400 |
|
|
401 |
int m_nSeq = 0;
|
|
402 |
int m_nRSeq = 0;
|
|
403 |
unsigned char m_Dst;
|
|
404 |
int m_nTotalSendCount = 0;
|
|
405 |
int m_nTotalRecvCount = 0;
|
|
406 |
int m_nTotalFailCount = 0;
|
|
407 |
int m_nSendCount = 0;
|
|
408 |
int m_nRecvCount = 0;
|
|
409 |
int m_nLastSendCount = 0;
|
|
410 |
int m_nLastRecvCount = 0;
|
|
411 |
int m_SendSpeed = 0;
|
|
412 |
int m_RecvSpeed = 0;
|
|
413 |
double LastTime = 0;
|
|
414 |
|
|
415 |
|
|
416 |
//unsigned char m_Stat;
|
|
417 |
|
|
418 |
unKLStat m_Stat1 = { 0 };
|
|
419 |
unKLStat m_DstStat;
|
|
420 |
|
|
421 |
typedef struct tagKLReqPacketDef
|
|
422 |
{
|
|
423 |
|
|
424 |
UCHAR StartSign;
|
|
425 |
UCHAR DstAddr;
|
|
426 |
UCHAR Stat;
|
|
427 |
UCHAR Cmd;
|
|
428 |
UCHAR Type1;
|
|
429 |
UCHAR Params[1];
|
|
430 |
}stKLReqPacket, *pKLReqPacket;
|
|
431 |
|
|
432 |
typedef struct tagKLRplyPktHdr
|
|
433 |
{
|
|
434 |
unsigned char RplyStSgn; //
|
|
435 |
unsigned char DstAddr; //
|
|
436 |
unsigned char nStatus; //
|
|
437 |
unsigned char nRplyCMD; //
|
|
438 |
unsigned char nSize1; //
|
|
439 |
unsigned char Datas[1]; //
|
|
440 |
}stKLRplyPktHdr, *pKLRplyPktHdr;
|
|
441 |
|
|
442 |
unsigned char m_Packetbuf[256];
|
|
443 |
unsigned char m_SendBuf[1024];
|
|
444 |
unsigned char m_RecvBuf[1024];
|
|
445 |
unsigned char m_DataBuf[1024];
|
|
446 |
|
|
447 |
typedef struct tagChnStat
|
|
448 |
{
|
61deef
|
449 |
unsigned short Stat;
|
Q |
450 |
unsigned short SendPackets;
|
|
451 |
unsigned short RecvPackets;
|
|
452 |
unsigned short LastSentTimeuS;
|
|
453 |
unsigned short LostPackets;
|
|
454 |
unsigned short CtnLstPkts;
|
|
455 |
unsigned short MaxCtnLstPkts;
|
|
456 |
unsigned short NotPkgErr;
|
|
457 |
unsigned short PkgLenErr;
|
|
458 |
unsigned short BCCErr;
|
|
459 |
unsigned short TimeOutErr;
|
|
460 |
unsigned short Delay;
|
|
461 |
unsigned short MaxDelay;
|
|
462 |
unsigned short SendTimeInterval;
|
418cb3
|
463 |
union
|
Q |
464 |
{
|
61deef
|
465 |
unsigned short ClientDatas[10];
|
418cb3
|
466 |
struct {
|
61deef
|
467 |
unsigned short ClientRecvPkts; //
|
Q |
468 |
unsigned short ClientSendPkts; //
|
|
469 |
unsigned short ClientNotPktErr; //
|
|
470 |
unsigned short ClientMisIdPkts; //
|
|
471 |
// unsigned int ClientNoEndErr; //
|
|
472 |
unsigned short ClientPkgLenErr; //
|
|
473 |
unsigned short ClientBccErr; //
|
|
474 |
unsigned short ClientTimeOutErr; //
|
418cb3
|
475 |
};
|
Q |
476 |
};
|
|
477 |
} stChnStat, *pChnStat;
|
61deef
|
478 |
|
418cb3
|
479 |
enum enKLDataCounts
|
Q |
480 |
{
|
|
481 |
KLDataWXCount = 16,
|
|
482 |
KLDataWYCount = 16,
|
|
483 |
KLDataWRCount = 16,
|
|
484 |
KLDataLDCount = 64,
|
|
485 |
KLDataWLCount = 8,
|
|
486 |
|
|
487 |
KLCoilXCount = KLDataWXCount * 16,
|
|
488 |
KLCoilYCount = KLDataWYCount * 16,
|
|
489 |
KLCoilRCount = KLDataWRCount * 16,
|
|
490 |
|
|
491 |
KLCoilTCount = 64,
|
|
492 |
KLCoilCCount = KLCoilTCount,
|
|
493 |
KLDataSVCount = KLCoilTCount,
|
|
494 |
KLDataEVCount = KLCoilTCount,
|
|
495 |
|
|
496 |
KLCoilLXCount = 128,
|
|
497 |
KLCoilLYCount = 128,
|
|
498 |
KLCoilLRCount = 128,
|
|
499 |
KLCoilSRCount = 128,
|
|
500 |
|
|
501 |
KLDataDTCount = 256,
|
|
502 |
KLDataSDTCount = 256,
|
|
503 |
KLDataWDTCount = 256,
|
|
504 |
};
|
|
505 |
struct tagMEM
|
|
506 |
{
|
|
507 |
union //tagWX
|
|
508 |
{
|
|
509 |
USHORT WX[64];
|
|
510 |
UCHAR WXB[128];
|
|
511 |
UINT WXD[32];
|
|
512 |
};
|
|
513 |
union //tagWY
|
|
514 |
{
|
|
515 |
USHORT WY[64];
|
|
516 |
UCHAR WYB[128];
|
|
517 |
UINT WYD[32];
|
61deef
|
518 |
};
|
Q |
519 |
union //tagWLX
|
|
520 |
{
|
|
521 |
USHORT WLX[64];
|
|
522 |
UCHAR WLXB[128];
|
|
523 |
UINT WLXD[32];
|
|
524 |
};
|
|
525 |
union //tagWLY
|
|
526 |
{
|
|
527 |
USHORT WLY[64];
|
|
528 |
UCHAR WLYB[128];
|
|
529 |
UINT WLYD[32];
|
418cb3
|
530 |
};
|
Q |
531 |
union //tagDT
|
|
532 |
{
|
|
533 |
USHORT DT[256];
|
|
534 |
UCHAR DTB[512];
|
|
535 |
UINT DTD[128];
|
|
536 |
};
|
|
537 |
union //tagWR
|
|
538 |
{
|
|
539 |
USHORT WR[64];
|
|
540 |
UCHAR WRB[128];
|
|
541 |
UINT WRD[32];
|
|
542 |
};
|
|
543 |
union //tagSDT
|
|
544 |
{
|
|
545 |
UCHAR SDB[512];
|
|
546 |
USHORT SDT[256];
|
|
547 |
UINT SDD[128];
|
|
548 |
struct {
|
|
549 |
unsigned int EffJumperSW;
|
|
550 |
unsigned int CurJumperSW;
|
|
551 |
unsigned int haltick;
|
|
552 |
unsigned int RunStat;
|
|
553 |
unsigned int ErrStat;
|
|
554 |
unsigned int nTickCount;
|
|
555 |
unsigned int TotalRunTime;
|
|
556 |
unsigned int ThisRunTime;
|
|
557 |
unsigned int PwrOnCount;
|
|
558 |
unsigned int LastScanTime;
|
|
559 |
unsigned int ScanTimeuS;
|
|
560 |
unsigned int MinScanTimeuS;
|
|
561 |
unsigned int MaxScanTimeuS;
|
|
562 |
unsigned short ADCValues[20];
|
|
563 |
};
|
|
564 |
};
|
|
565 |
//
|
|
566 |
union {
|
|
567 |
unsigned int WDD[KLDataWDTCount / 2];
|
|
568 |
unsigned short WDT[KLDataWDTCount];
|
|
569 |
unsigned char WDB[KLDataWDTCount * 2];
|
|
570 |
};
|
61deef
|
571 |
union
|
Q |
572 |
{
|
|
573 |
UCHAR KBDB[2048];
|
|
574 |
USHORT KBDT[1024];
|
|
575 |
UINT KBDD[512];
|
|
576 |
};
|
|
577 |
union {
|
|
578 |
UCHAR KWLB[256];
|
|
579 |
USHORT KWLT[128];
|
|
580 |
UINT KWLD[64];
|
|
581 |
};
|
|
582 |
|
418cb3
|
583 |
}MEM;
|
Q |
584 |
|
61deef
|
585 |
|
418cb3
|
586 |
CString m_resultStr;
|
Q |
587 |
|
|
588 |
static int xtoi(const char * hexstr, int len = 0);
|
|
589 |
unsigned char KLBCC(void * pData, int nSize);
|
|
590 |
|
|
591 |
int CalCRC(void * pBuf, int nSize);
|
|
592 |
|
|
593 |
/*
|
|
594 |
连接状态
|
|
595 |
开始连接(未定)-> 心跳包正常->已连接 -> 心跳包连续正常 -> 连接很好
|
|
596 |
|
|
597 |
连接很好 -> 心跳包 失败 / 数据包失败 -> 已连接 (有错误)
|
|
598 |
|
|
599 |
已连接 (有错误) -> 心跳包正常 -> 已连接
|
|
600 |
*/
|
|
601 |
int CalSpeed();
|
|
602 |
int fnTest1(int n);
|
|
603 |
|
|
604 |
int ParseReqPacket();
|
|
605 |
int MakeRplyPacket();
|
|
606 |
|
|
607 |
// typedef int(*pSend)(void *, int);
|
|
608 |
// typedef int(*pRecv)(void *, int);
|
|
609 |
// typedef int(*pOpen)(int);
|
|
610 |
// typedef int(*pClose)(int);
|
|
611 |
|
|
612 |
// pSend SendPkgFunc;
|
|
613 |
// pRecv RecvPkgFunc;
|
|
614 |
// pOpen OpenFunc;
|
|
615 |
// pClose CloseFunc;
|
|
616 |
/*
|
|
617 |
std::function<int(void *, int)> SendPkgFunc;
|
|
618 |
std::function<int(void *, int)> RecvPkgFunc;
|
|
619 |
std::function<int(int)> OpenFunc;
|
|
620 |
std::function<int(int)> CloseFunc;
|
|
621 |
*/
|
|
622 |
typedef struct tagCallBackFuncs
|
|
623 |
{
|
|
624 |
std::function<int(void)> OpenFunc;
|
|
625 |
std::function<int(void)> CloseFunc;
|
|
626 |
std::function<int(void)> ClearBufFunc;
|
|
627 |
std::function<int(void *, int)> SendPkgFunc;
|
|
628 |
std::function<int(void *, int)> RecvPkgFunc;
|
|
629 |
std::function<int(void)> OnConnect;
|
|
630 |
std::function<int(int ErrCode)> OnDisConnect;
|
|
631 |
std::function<int(int ErrCode)> OnError;
|
|
632 |
|
|
633 |
}stCallBackFuncs, *pCallBackFuncs;
|
|
634 |
|
|
635 |
stCallBackFuncs m_CallBackFuncs = {
|
|
636 |
std::bind(&HvSerialPort1::Open,&MySerPort1),
|
|
637 |
std::bind(&HvSerialPort1::Close,&MySerPort1),
|
|
638 |
std::bind(&HvSerialPort1::ClearBuf,&MySerPort1),
|
|
639 |
std::bind(&HvSerialPort1::Send,&MySerPort1, std::placeholders::_1, std::placeholders::_2),
|
|
640 |
std::bind(&HvSerialPort1::Recv,&MySerPort1, std::placeholders::_1, std::placeholders::_2)
|
|
641 |
};
|
|
642 |
|
|
643 |
int m_bSendCallBackSet = 1;
|
|
644 |
int m_bRecvCallBackSet = 1;
|
|
645 |
int m_bOpenCallBackSet = 1;
|
|
646 |
int m_bCloseCallBackSet = 1;
|
|
647 |
int m_bClearBufCallBackSet = 1;
|
|
648 |
int m_bOnConnectCallBackSet = 0;
|
|
649 |
int m_bOnDisConnectCallBackSet = 0;
|
|
650 |
int m_bOnErrorCallBackSet = 0;
|
|
651 |
|
|
652 |
bool m_bOpened = false;
|
|
653 |
/*
|
|
654 |
int SetSendCallBackFunc(std::function<int(void *, int)> pSendFunc);
|
|
655 |
int SetRecvCallBackFunc(std::function<int(void *, int)> pRecvFunc);
|
|
656 |
int SetOpenCallBackFunc(std::function<int(int)> pOpenFunc);
|
|
657 |
int SetCloseCallBackFunc(std::function<int(int)> pCloseFunc);
|
|
658 |
*/
|
|
659 |
|
|
660 |
int SetCommParam();
|
|
661 |
|
|
662 |
int SetCallBackFuncs(pCallBackFuncs pFuncSt);
|
|
663 |
|
|
664 |
int m_nErrCount = 0;
|
|
665 |
int m_nContinueErrCount = 0;
|
|
666 |
int Open(int OpenParam = 0);
|
|
667 |
int Close(int CloseParam = 0);
|
|
668 |
|
|
669 |
int Connect(int ConnectParam = 0);
|
|
670 |
int DisConnect(int DisConnectParam = 0);
|
|
671 |
|
61deef
|
672 |
int GotoCmdMode(int Param = 0);
|
Q |
673 |
int ExitCmdMode(int Param = 0);
|
|
674 |
|
418cb3
|
675 |
int DoHeartBeat(int nParam = 0);
|
Q |
676 |
|
|
677 |
void OnTimer();
|
|
678 |
|
|
679 |
int SendPacket(void * pBuf, int Len);
|
|
680 |
int RecvPacket(void * pBuf, int LenToRead, int ReTryCount = 3);
|
|
681 |
|
|
682 |
int GetNextSeq();
|
|
683 |
|
|
684 |
int MakeExtDataFrame(void * pBuf, UCHAR nDst, UCHAR nType, UCHAR len2, void * pData);
|
|
685 |
|
|
686 |
//int MakeReqPacket(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr = 0, USHORT nCount = 0, void * pData = NULL);
|
|
687 |
|
|
688 |
int MakeReqPacketEx(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr = 0, USHORT nCount = 0, void * pData = NULL, int ExtFrameLen = 0, void * pExtDataFrame = NULL);
|
61deef
|
689 |
int MakeRemoteReqPacketEx(void* pBuf, UCHAR nDst, UCHAR Stat, UCHAR nPort, UCHAR nChildId, UCHAR nCMD, UCHAR Param1, USHORT nAddr = 0, USHORT nCount = 0, void* pData = NULL, int ExtFrameLen = 0, void* pExtDataFrame = NULL);
|
418cb3
|
690 |
|
Q |
691 |
int CheckPackage(void * pBuf, int nSize);
|
|
692 |
int ProcessPacket(void *pBuf, int nLen);
|
|
693 |
int ParseRplyPacket(void *pBuf, int nPkgLen, UCHAR * nCmd, UCHAR * Status, USHORT* nCount, void * pData);
|
|
694 |
|
|
695 |
int GetInfo(UCHAR nDst, USHORT * nReadBytes, USHORT * Values);
|
|
696 |
int GetSN(UCHAR nDst, USHORT * nReadBytes, USHORT * Values);
|
|
697 |
int GetUID(UCHAR nDst, USHORT * nReadBytes, USHORT * Values);
|
|
698 |
int ReadFactoryData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values);
|
|
699 |
int WriteFactoryData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values);
|
|
700 |
|
61deef
|
701 |
int ReadSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values);
|
Q |
702 |
int WriteSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values);
|
418cb3
|
703 |
|
Q |
704 |
|
|
705 |
//int GetTime32(UCHAR nDst, int * nCount);
|
|
706 |
//int SetTime32(UCHAR nDst, int * nCount);
|
|
707 |
int GetDateTime32(UCHAR nDst, UINT * pValue);
|
|
708 |
int SetDateTime32(UCHAR nDst, UINT Value);
|
|
709 |
|
|
710 |
|
|
711 |
int GetEventLogCount(UCHAR nDst, int * nCount);
|
|
712 |
int GetEventLog(UCHAR nDst, int nStartIndex, int nCount, stEventLog * pEventLogs);
|
|
713 |
|
|
714 |
|
|
715 |
int ReadBit(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR * Value);//Read 1 Single bit
|
|
716 |
int WriteBit(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR Value);//Write 1 Single bit
|
|
717 |
int ReadBits(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR nBitCount, UCHAR * Values);
|
|
718 |
int WriteBits(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR nBitCount, UCHAR * Values);
|
|
719 |
int ReadBitsByWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT *Values);
|
|
720 |
int WriteBitsByWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT *Values);
|
|
721 |
|
|
722 |
int ReadDataByte(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, USHORT * nByteRead, UCHAR * Values);
|
|
723 |
int WriteDataByte(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR * Values);
|
|
724 |
|
|
725 |
int ReadDataWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * nByteRead, USHORT * Values);
|
|
726 |
int WriteDataWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
|
727 |
|
|
728 |
int ReadData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * nByteRead, USHORT * Values);
|
|
729 |
int WriteData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
|
730 |
|
df0321
|
731 |
int GetMode(UCHAR nDst, UCHAR nType, UCHAR* value);
|
418cb3
|
732 |
int ChangeMode(UCHAR nDst, UCHAR nType);
|
Q |
733 |
|
|
734 |
int BlinkLED(UCHAR nDst, UCHAR nSecond);
|
|
735 |
|
61deef
|
736 |
int ReadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
Q |
737 |
int StartDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgBytes,USHORT nCRC = 0);
|
|
738 |
int DownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, USHORT * Values);
|
|
739 |
int FinishDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgSteps, USHORT nCRC = 0);
|
418cb3
|
740 |
|
61deef
|
741 |
int ReadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
|
Q |
742 |
int StartDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nBytes, USHORT nCRC = 0);
|
|
743 |
int DownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
|
|
744 |
int FinishDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteSize, USHORT nCRC = 0);
|
|
745 |
|
418cb3
|
746 |
|
Q |
747 |
int ReadRunStat(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
|
748 |
|
61deef
|
749 |
|
418cb3
|
750 |
int ClearStatistics(UCHAR nDst, UCHAR nType);
|
Q |
751 |
|
61deef
|
752 |
int ResetDevice(UCHAR nDst, UCHAR nType);
|
Q |
753 |
|
|
754 |
int WriteFirmware(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
|
|
755 |
int WriteFirmInfo(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values);
|
|
756 |
|
|
757 |
int GetPortInfo(UCHAR nDst, UCHAR nType, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values);
|
|
758 |
|
|
759 |
int GetPortChildInfo(UCHAR nDst, UCHAR nType, UCHAR nChildId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values);
|
|
760 |
int GetPortChnInfo(UCHAR nDst, UCHAR nType, UCHAR nChnId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values);
|
|
761 |
|
|
762 |
int RunRemoteReq(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nReqId, UCHAR nParam, USHORT nByteAddr = 0, UCHAR nByteCount =0 ,void * pData = 0);
|
|
763 |
|
|
764 |
int RmoteBlinkLED(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nSecond);
|
|
765 |
|
418cb3
|
766 |
};
|
Q |
767 |
|