提交 | 用户 | age
|
418cb3
|
1 |
/*
|
Q |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
*/
|
|
7 |
#pragma once
|
|
8 |
|
|
9 |
#define TYPECOIL 0x00
|
|
10 |
#define TYPEDATA 0x80
|
|
11 |
|
|
12 |
#define TOTAL_WDFS (16) //Total DF Count
|
|
13 |
#define TOTAL_CurVAL (16) //
|
|
14 |
|
|
15 |
//extern unsigned short X[256];
|
|
16 |
//extern unsigned short Y[256];
|
|
17 |
//extern unsigned short R[256];
|
|
18 |
|
|
19 |
#define TOTALTIMERS (64)
|
|
20 |
#define TICK_OF_MS (10) //1ms
|
|
21 |
#define TICK_OF_RS (100) //10mS
|
|
22 |
#define TICK_OF_XS (1000) //100mS
|
|
23 |
#define TICK_OF_YS (10000) //1S
|
|
24 |
|
|
25 |
|
|
26 |
enum enKLCoilTypes
|
|
27 |
{
|
|
28 |
KLCoilTypeX = 0 | TYPECOIL, //X Input
|
|
29 |
KLCoilTypeY = 1 | TYPECOIL, //Y Output
|
|
30 |
KLCoilTypeR = 2 | TYPECOIL, //R register
|
|
31 |
KLCoilTypeLX = 3 | TYPECOIL, //Link register
|
|
32 |
KLCoilTypeLY = 4 | TYPECOIL, //Link register
|
|
33 |
KLCoilTypeT = 5 | TYPECOIL, //Timer
|
|
34 |
KLCoilTypeC = 6 | TYPECOIL, //Counter
|
|
35 |
KLCoilTypeLR = 7 | TYPECOIL, //Link register
|
|
36 |
KLCoilTypeSR = 8 | TYPECOIL, //Link register
|
|
37 |
|
|
38 |
};
|
|
39 |
enum enKLDataTypes
|
|
40 |
{
|
|
41 |
KLDataTypeDEC = 0 | TYPEDATA,
|
|
42 |
KLDataTypeHEX = 1 | TYPEDATA,
|
|
43 |
KLDataTypeFloat = 2 | TYPEDATA,
|
|
44 |
KLDataTypeWX = 3 | TYPEDATA,
|
|
45 |
KLDataTypeWY = 4 | TYPEDATA,
|
|
46 |
KLDataTypeWR = 5 | TYPEDATA,
|
|
47 |
KLDataTypeWLX = 6 | TYPEDATA,
|
|
48 |
KLDataTypeWLY = 7 | TYPEDATA,
|
|
49 |
KLDataTypeDT = 8 | TYPEDATA,
|
|
50 |
KLDataTypeSDT = 9 | TYPEDATA,
|
|
51 |
KLDataTypeWSR = 10 | TYPEDATA,
|
|
52 |
KLDataTypeSV = 11 | TYPEDATA,
|
|
53 |
KLDataTypeEV = 12 | TYPEDATA,
|
|
54 |
KLDataTypeLD = 13 | TYPEDATA,
|
|
55 |
KLDataSysCfg = 25 | TYPEDATA,
|
|
56 |
KLDataTypeFlash = 33 | TYPEDATA,
|
|
57 |
KLDataTypeWDT = 41 | TYPEDATA,
|
|
58 |
KLDataTypeKBD = 51 | TYPEDATA,
|
|
59 |
KLDataTypeTest = 254 | TYPEDATA,
|
|
60 |
};
|
|
61 |
enum enKLDataCounts
|
|
62 |
{
|
|
63 |
KLDataDTCount = 256,
|
|
64 |
KLDataSDTCount = 256,
|
|
65 |
|
|
66 |
KLDataWXCount = 16,
|
|
67 |
KLDataWYCount = 16,
|
|
68 |
KLDataWRCount = 16,
|
|
69 |
KLDataLDCount = 64,
|
|
70 |
KLDataWLCount = 8,
|
|
71 |
|
|
72 |
KLCoilXCount = KLDataWXCount * 16,
|
|
73 |
KLCoilYCount = KLDataWYCount * 16,
|
|
74 |
KLCoilRCount = KLDataWRCount * 16,
|
|
75 |
|
|
76 |
KLCoilTCount = 64,
|
|
77 |
KLCoilCCount = KLCoilTCount,
|
|
78 |
KLDataSVCount = KLCoilTCount,
|
|
79 |
KLDataEVCount = KLCoilTCount,
|
|
80 |
|
|
81 |
KLCoilLXCount = 128,
|
|
82 |
KLCoilLYCount = 128,
|
|
83 |
KLCoilLRCount = 128,
|
|
84 |
KLCoilSRCount = 128,
|
|
85 |
|
|
86 |
|
|
87 |
};
|
|
88 |
|
|
89 |
enum enInputFilter
|
|
90 |
{
|
|
91 |
InputFilter_None = 0,
|
|
92 |
InputFilter_1mS = 1,
|
|
93 |
InputFilter_2mS = 2,
|
|
94 |
InputFilter_4mS = 3,
|
|
95 |
InputFilter_8mS = 4,
|
|
96 |
InputFilter_16mS = 5,
|
|
97 |
InputFilter_32mS = 6,
|
|
98 |
InputFilter_64mS = 7,
|
|
99 |
InputFilter_128mS = 8,
|
|
100 |
InputFilter_256mS = 9,
|
|
101 |
};
|
|
102 |
|
|
103 |
enum enOutputHold
|
|
104 |
{
|
|
105 |
Output_Hold = 0,
|
|
106 |
Output_Set_0 = 1,
|
|
107 |
Output_Set_1 = 2,
|
|
108 |
};
|
|
109 |
|
|
110 |
enum enPortType
|
|
111 |
{
|
|
112 |
PortType_Com = 0, //¼ÆËã»úͨѶ
|
|
113 |
PortType_Gen = 1, //ͨÓÃͨѶ£¬×ÔÓÉ¿Ú
|
|
114 |
PortType_KLink = 2, //KlinkͨѶ
|
|
115 |
PortType_KBus = 3, //KBusͨѶ
|
|
116 |
PortType_KNet = 4, // KNetͨѶ
|
|
117 |
PortType_ModbusRTU = 5, //Modbus RTU ͨѶ
|
|
118 |
};
|
|
119 |
|
|
120 |
enum enKeventType
|
|
121 |
{
|
|
122 |
EventTypeNone = 0,
|
|
123 |
EventTypePowerUp = 1,
|
|
124 |
EventTypePowerDown = 2,
|
|
125 |
EventTypePowerRecover = 3,
|
|
126 |
EventTypeConnected = 4,
|
|
127 |
EventTypeLostCon = 5,
|
|
128 |
EventTypeSetTime = 6,
|
|
129 |
EventTypeSysCfg = 7,
|
|
130 |
EventTypeProg = 8,
|
|
131 |
EventTypeForce = 9,
|
|
132 |
EventTypeClearEvent = 10,
|
|
133 |
|
|
134 |
|
|
135 |
EventType
|
|
136 |
};
|
|
137 |
|
|
138 |
typedef struct tagInfoBlock // 20 bytes
|
|
139 |
{
|
|
140 |
// USHORT nBlockLenth;
|
|
141 |
USHORT nDeviceTypeVer; //device type x.y
|
|
142 |
// UCHAR nDevierVer;
|
|
143 |
USHORT nProgVer; //prog version x.y
|
|
144 |
USHORT nKLinkVer; //x.y
|
|
145 |
USHORT nKBusVer; //x.y
|
|
146 |
// USHORT nKNetVer; //x.y
|
|
147 |
// USHORT nKWLVer; //x.y
|
|
148 |
|
|
149 |
UCHAR nCapacity1; // ? K
|
|
150 |
UCHAR nCapacity2; // ? k
|
|
151 |
|
|
152 |
UCHAR nDInput;
|
|
153 |
UCHAR nDOutput;
|
|
154 |
UCHAR nAInput;
|
|
155 |
UCHAR nAOutput;
|
|
156 |
UCHAR nHInput;
|
|
157 |
UCHAR nHOutput;
|
|
158 |
UCHAR nExt1;
|
|
159 |
UCHAR nExt2;
|
|
160 |
UCHAR nLogSize;
|
|
161 |
UCHAR nPorts;
|
|
162 |
UCHAR nManSize;
|
|
163 |
UCHAR nAbility;
|
|
164 |
UCHAR nSwitchBits;
|
|
165 |
|
|
166 |
}stKMInfoBlock, *pKMInfoBlock;
|
|
167 |
|
|
168 |
typedef struct tagFactoryData //¹¤³§Á¿²ú²ÎÊý£¬Êý¾Ý
|
|
169 |
{
|
|
170 |
USHORT Sign1;
|
|
171 |
USHORT Seq1;
|
|
172 |
USHORT nModelNo;
|
|
173 |
USHORT nModelVer;
|
|
174 |
UINT nLotNo;
|
|
175 |
UINT nProductDateTime;
|
|
176 |
UINT SN1;
|
|
177 |
UINT nProtocalVer;
|
|
178 |
UINT nDefaultFunc;
|
|
179 |
UCHAR ModelStr[16];
|
|
180 |
UCHAR LOT_NO[16]; //
|
|
181 |
UCHAR SNStr[16];
|
|
182 |
unsigned short CRC1;
|
|
183 |
unsigned short EndSign1;
|
|
184 |
|
|
185 |
}stFactoryData, *pFactoryData;
|
|
186 |
|
|
187 |
|
|
188 |
typedef struct tagKMFuncParam
|
|
189 |
{
|
|
190 |
USHORT EnablePLC : 1; //使能内部PLC功能
|
|
191 |
USHORT RunMode; //工作模式
|
|
192 |
}stKMFuncParam;
|
|
193 |
|
|
194 |
//输入输出地址映射
|
|
195 |
typedef struct tagAddrMapping
|
|
196 |
{
|
|
197 |
USHORT InputAddr;
|
|
198 |
USHORT OutputAddr;
|
|
199 |
USHORT WRAddr;
|
|
200 |
USHORT DTAddr;
|
|
201 |
}stAddrMapping;
|
|
202 |
|
|
203 |
typedef struct tagComPortParam //4 Bytes
|
|
204 |
{
|
|
205 |
USHORT WorkMode; /* 0-5=Default,KLink,KBus,KNet,RTU,Com,Gen */
|
|
206 |
USHORT Station; /* 0=From jumper */
|
|
207 |
USHORT BaudRate; /* =*100 Baudrate at which running */
|
|
208 |
USHORT ByteSize : 2; /* 0-1=Number of bits/byte, 7-8 */
|
|
209 |
USHORT Parity : 4; /* 0-4=None,Odd,Even,Mark,Space */
|
|
210 |
USHORT StopBits : 2; /* 0,1,2 = 1, 1.5, 2 */
|
|
211 |
USHORT EndType : 2; /* 0=ByChar, 1= ByTime */
|
|
212 |
USHORT EofChar : 4; /* 0,1,2 = None, CR, CR+LF, ETX; End of character */
|
|
213 |
USHORT SofChar : 2; /* 0,1,2 = None, STX */
|
|
214 |
USHORT EndTime; /*(*0.01mS) */
|
|
215 |
USHORT RecvAddr;
|
|
216 |
USHORT RecvSize;
|
|
217 |
|
|
218 |
}stComPortParam, *pstComPortParam;
|
|
219 |
|
|
220 |
|
|
221 |
typedef struct tagInputFilterParam
|
|
222 |
{
|
|
223 |
BYTE Filter0 : 4;
|
|
224 |
BYTE Filter1 : 4;
|
|
225 |
|
|
226 |
}stInputFilterParam;
|
|
227 |
|
|
228 |
typedef struct tagOutputHoldParam
|
|
229 |
{
|
|
230 |
BYTE Hold1 : 4;
|
|
231 |
BYTE Hold2 : 4;
|
|
232 |
}stOutputHoldParam;
|
|
233 |
// 硬件描述文件
|
|
234 |
|
|
235 |
//#pragma pack(2)
|
|
236 |
typedef struct tagKMSysCfg //120 Bytes total
|
|
237 |
{
|
|
238 |
USHORT Version; // SC0 // 2 Bytes
|
|
239 |
USHORT workmode; // SC1 // 2 Bytes 0=From jumper
|
|
240 |
USHORT SwitchFunc; // SC2 // 2 Bytes
|
|
241 |
USHORT Space1; // 2 bytes
|
|
242 |
|
|
243 |
stComPortParam PortParams[2]; // 28 Bytes
|
|
244 |
stInputFilterParam InputParams[16]; //8 Bytes
|
|
245 |
stOutputHoldParam OutputParams[16]; //16 Bytes
|
|
246 |
USHORT OutMappings[6]; //12 Bytes //输出映射
|
|
247 |
|
|
248 |
UINT Space2[12]; //48 bytes
|
|
249 |
|
|
250 |
}stKMSysCfg, *pKMSysCfg;
|
|
251 |
|
|
252 |
|
|
253 |
typedef struct tagTimer
|
|
254 |
{
|
|
255 |
unsigned int LastActTime;
|
|
256 |
union {
|
|
257 |
unsigned short StatByte;
|
|
258 |
struct
|
|
259 |
{
|
|
260 |
unsigned short nScale : 2; //Time Scale, 0:1ms 1:10ms 2:100ms 3:1S
|
|
261 |
unsigned short nType : 1; //0 : timer 1 : counter ;
|
|
262 |
unsigned short nDir : 1; //0 : count down. 1 count up;
|
|
263 |
unsigned short nInited : 1;
|
|
264 |
unsigned short bSet : 1;
|
|
265 |
unsigned short bTon : 1;
|
|
266 |
|
|
267 |
};
|
|
268 |
// stTimerStat Stat;
|
|
269 |
};
|
|
270 |
}stTimer;
|
|
271 |
|
|
272 |
typedef struct tagKMem
|
|
273 |
{
|
|
274 |
unsigned short WDFs[TOTAL_WDFS];
|
|
275 |
unsigned char CurVALs[TOTAL_CurVAL];
|
|
276 |
unsigned char CurVAL;
|
|
277 |
|
|
278 |
stTimer Timers[TOTALTIMERS];
|
|
279 |
|
|
280 |
unsigned short WX[KLDataWXCount]; //
|
|
281 |
unsigned short WY[KLDataWYCount]; //
|
|
282 |
unsigned short WR[KLDataWRCount];
|
|
283 |
unsigned short WT[16];
|
|
284 |
|
|
285 |
unsigned short WC[16];
|
|
286 |
unsigned short EV[KLDataEVCount];
|
|
287 |
unsigned short SV[KLDataSVCount];
|
|
288 |
|
|
289 |
unsigned short WLX[16]; //
|
|
290 |
unsigned short WLY[16];
|
|
291 |
unsigned short WLR[16];
|
|
292 |
unsigned short WSR[16];
|
|
293 |
unsigned short DT[KLDataDTCount];
|
|
294 |
|
|
295 |
union {
|
|
296 |
unsigned int SDD[KLDataSDTCount / 2];
|
|
297 |
unsigned short SDT[KLDataSDTCount];
|
|
298 |
unsigned char SDB[KLDataSDTCount * 2];
|
|
299 |
struct {
|
|
300 |
unsigned int EffJumperSW;
|
|
301 |
unsigned int CurJumperSW;
|
|
302 |
unsigned int haltick;
|
|
303 |
unsigned int nRunCount;
|
|
304 |
unsigned int RunStat;
|
|
305 |
unsigned int ErrStat;
|
|
306 |
unsigned int PwrOnCount;
|
|
307 |
unsigned int ThisRunTime;
|
|
308 |
unsigned int TotalRunTime;
|
|
309 |
unsigned int CurTimeSec;
|
|
310 |
unsigned int PwrFailCount;
|
|
311 |
unsigned int LastPwrFailTime;
|
|
312 |
unsigned int LastScanTime;
|
|
313 |
unsigned int ScanTimeuS;
|
|
314 |
unsigned int MinScanTimeuS;
|
|
315 |
unsigned int MaxScanTimeuS;
|
|
316 |
unsigned int nEventCount;
|
|
317 |
unsigned int nEventMinIndex;
|
|
318 |
unsigned int nEventMaxIndex;
|
|
319 |
unsigned int Rev2[5];
|
|
320 |
unsigned short ADCValues[20];
|
|
321 |
};
|
|
322 |
};
|
|
323 |
int Reserverd5[1024];
|
|
324 |
}stKMem;
|
|
325 |
|
|
326 |
|
|
327 |
enum enOpType
|
|
328 |
{
|
|
329 |
OP_NONE = 0,
|
|
330 |
OP_NOP = 0,
|
|
331 |
OP_ST = 1, //
|
|
332 |
OP_ST_ = 2, //
|
|
333 |
OP_AN = 3, //
|
|
334 |
OP_AN_ = 4, //
|
|
335 |
OP_OR = 5, //
|
|
336 |
OP_OR_ = 6, //
|
|
337 |
OP_NOT = 7, //
|
|
338 |
OP_ANS = 8, //
|
|
339 |
OP_ORS = 9, //
|
|
340 |
|
|
341 |
OP_PSHS = 10, //
|
|
342 |
OP_RDS = 11, //
|
|
343 |
OP_POPS = 12, //
|
|
344 |
|
|
345 |
OP_OUT = 16, //
|
|
346 |
OP_SET = 17, //
|
|
347 |
OP_RESET = 18, //
|
|
348 |
OP_DF = 19, //
|
|
349 |
OP_DF_ = 20, //
|
|
350 |
|
|
351 |
OP_ST_EQ, //
|
|
352 |
OP_ST_LT, //
|
|
353 |
OP_ST_GT, //
|
|
354 |
OP_ST_LE, //
|
|
355 |
OP_ST_GE, //
|
|
356 |
OP_ST_NE, //
|
|
357 |
OP_AN_EQ, //
|
|
358 |
OP_AN_LT, //
|
|
359 |
OP_AN_GT,
|
|
360 |
OP_AN_LE,
|
|
361 |
OP_AN_GE,
|
|
362 |
OP_AN_NE,
|
|
363 |
OP_OR_EQ,
|
|
364 |
OP_OR_LT,
|
|
365 |
OP_OR_GT,
|
|
366 |
OP_OR_LE,
|
|
367 |
OP_OR_GE,
|
|
368 |
OP_OR_NE,
|
|
369 |
|
|
370 |
|
|
371 |
OP_MV = 51,
|
|
372 |
OP_INC = 52,
|
|
373 |
OP_ADD2 = 53,
|
|
374 |
OP_ADD3 = 54,
|
|
375 |
OP_DEC = 55,
|
|
376 |
OP_SUB2 = 56,
|
|
377 |
OP_SUB3 = 57,
|
|
378 |
OP_MUL = 58,
|
|
379 |
OP_DIV = 59,
|
|
380 |
OP_BKMV = 60,
|
|
381 |
OP_COPY = 61,
|
|
382 |
OP_CLR = 62,
|
|
383 |
|
|
384 |
OP_BRK,
|
|
385 |
OP_PAUSE,
|
|
386 |
OP_JP,
|
|
387 |
OP_CALL,
|
|
388 |
|
|
389 |
OP_TML = 0xC8, //
|
|
390 |
OP_TMR = 0xDC, //
|
|
391 |
OP_TMX = 0xDD, //
|
|
392 |
OP_TMY = 0xFA, //
|
|
393 |
|
|
394 |
};
|
|
395 |
|
|
396 |
typedef struct stBinProg1
|
|
397 |
{
|
|
398 |
unsigned char nOp;
|
|
399 |
unsigned char nParamType;
|
|
400 |
unsigned short nParamAddr;
|
|
401 |
}stBinProg1;
|
|
402 |
typedef struct stBinProg15
|
|
403 |
{ //定时器
|
|
404 |
//单参数高级指令
|
|
405 |
unsigned char nOp;
|
|
406 |
unsigned char nOpNum;
|
|
407 |
unsigned short nParamAddr1;
|
|
408 |
unsigned char nParamType1;
|
|
409 |
unsigned char resvr1;
|
|
410 |
unsigned short resvr2;
|
|
411 |
}stBinProg15;
|
|
412 |
typedef struct stBinProg2
|
|
413 |
{ //比较指令
|
|
414 |
//双参数高级指令
|
|
415 |
unsigned char nOp;
|
|
416 |
unsigned char nOpNum;
|
|
417 |
unsigned short nParamAddr1;
|
|
418 |
unsigned char nParamType1;
|
|
419 |
unsigned char nParamType2;
|
|
420 |
unsigned short nParamAddr2;
|
|
421 |
}stBinProg2;
|
|
422 |
typedef struct stBinProg3
|
|
423 |
{ //三参数高级指令
|
|
424 |
unsigned char nOp;
|
|
425 |
unsigned char nOpNum;
|
|
426 |
unsigned short nParamAddr1;
|
|
427 |
unsigned char nParamType1;
|
|
428 |
unsigned char nParamType2;
|
|
429 |
unsigned short nParamAddr2;
|
|
430 |
unsigned char resvr1;
|
|
431 |
unsigned char nParamType3;
|
|
432 |
unsigned short nParamAddr3;
|
|
433 |
}stBinProg3;
|
|
434 |
|