QuakeGod
2022-01-16 326d3e312c74726814c39c9d112faab03c4a167c
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
/*
 
 
 
*/
#pragma once
#include "KDefine.h"
#include "HvSerialPort.h"
#include <functional>
class KLink
{
    typedef unsigned char UCHAR;
    typedef unsigned short USHORT;
    typedef unsigned int UINT;
 
public:
    KLink();
    virtual ~KLink();
    HvSerialPort m_SerialPort;
#define TYPECOIL 0x00
#define TYPEDATA 0x80
    enum enKLCoilTypes
    {
        KLCoilTypeX = 0 | TYPECOIL,        //X Input
        KLCoilTypeY = 1 | TYPECOIL,        //Y Output
        KLCoilTypeR = 2 | TYPECOIL,        //R register
        KLCoilTypeLX = 3 | TYPECOIL,        //Link register
        KLCoilTypeLY = 4 | TYPECOIL,        //Link register
        KLCoilTypeT = 5 | TYPECOIL,        //Timer
        KLCoilTypeC = 6 | TYPECOIL,        //Counter
        KLCoilTypeLR = 7 | TYPECOIL,        //Link register
        KLCoilTypeSR = 8 | TYPECOIL,        //Link register
 
 
    };
    enum enKLDataTypes
    {
        KLDataTypeDEC = 0 | TYPEDATA,
        KLDataTypeHEX = 1 | TYPEDATA,
        KLDataTypeFloat = 2 | TYPEDATA,
        KLDataTypeWX = 3 | TYPEDATA,
        KLDataTypeWY = 4 | TYPEDATA,
        KLDataTypeWR = 5 | TYPEDATA,
        KLDataTypeWLX = 6 | TYPEDATA,
        KLDataTypeWLY = 7 | TYPEDATA,
        KLDataTypeDT = 8 | TYPEDATA,
        KLDataTypeSDT = 9 | TYPEDATA,
        KLDataTypeWSR = 10 | TYPEDATA,
        KLDataTypeSV = 11 | TYPEDATA,
        KLDataTypeEV = 12 | TYPEDATA,
        KLDataTypeLD = 13 | TYPEDATA,
        KLDataSysCfg = 25 | TYPEDATA,
        KLDataTypeFlash = 33 | TYPEDATA,
        KLDataTypeTest = 254 | TYPEDATA,
    };
    enum enKLDataCounts
    {
        KLDataDTCount = 256,
        KLDataSDTCount = 256,
 
        KLDataWXCount = 16,
        KLDataWYCount = 16,
        KLDataWRCount = 16,
        KLDataLDCount = 64,
        KLDataWLCount = 8,
 
        KLCoilXCount = KLDataWXCount * 16,
        KLCoilYCount = KLDataWYCount * 16,
        KLCoilRCount = KLDataWRCount * 16,
 
        KLCoilTCount = 64,
        KLCoilCCount = KLCoilTCount,
        KLDataSVCount = KLCoilTCount,
        KLDataEVCount = KLCoilTCount,
 
        KLCoilLXCount = 128,
        KLCoilLYCount = 128,
        KLCoilLRCount = 128,
        KLCoilSRCount = 128,
 
    };
    typedef struct tagKLTypeName
    {
        int nType;
        const char * sName;
        int nRange = 0;
    }stKLTypeName;
    static const stKLTypeName KLCoilTypeNames[];
    static const stKLTypeName KLDataTypeNames[];
 
enum eKLResult
{
    KL_ERR = -1,
    KL_OK = 0,
    KL_NG = 1,
    KL_UNKNOWN = 2,
    KL_TIMEOUT = 3,
    KL_BCC_ERR = 4,
    KL_PKG_ERR = 5,
    KL_SEQ_ERR = 6,
    KL_LENTH_EXCEED,
    KL_NEED_PASS,
    KL_NOT_SUPPORT,
};
const char * GetErrDescStr(int nErrNo);
enum
{
    KLSignStart = '%',
    KLSignReply = 'U',
    KLSignEnd = 0x0D,
    KLMaxPacketLength = 128,
 
};
enum ExtraDataType
{
    KLExtTypeNone = 0,
    KLExtTypeText = 1,
    KLExtTypeCmd = 2,
    KLExtTypePassTh = 3,
 
    KLExtTypeTestData = 8,
};
 
enum enCMDs
{
    //        cmdOK = '1',        //Reply OK
    //        cmdNG = '2',        //Rplay NG
    KLCmdNone = 0x00,        //Nothing
    KLCmdPing = 0x01,            //Ping
    KLCmdPingReply = 0x02,        //PingReply
    KLCmdGetInfo = 0x03,            //GetInfo
    KLCmdVerInfo = 0x04,            //InfoReply
 
    KLCmdRead = 0x05,            //Read
    KLCmdReadReply = 0x06,        //ReadReply
    KLCmdWrite = 0x07,            //Write
    KLCmdWriteReply = 0x08,    //WriteReply
    KLCmdSaveToFlash = 0x09,                //Write
 
    KLCmdExChgData = 0x0A,                //ExChangeDate, = Wirte + Read
    KLCmdExChgDataReply,            //ExchangeData Reply
 
    KLCmdSyncRead = 0x0D,                //SyncRead
    KLCmdSyncWrite,                        //SyncWrite
    KLCmdSequenRead,                    //Sequence Read
    KLCmdSyncTime,                        //SyncTime
 
    KLCmdChgMode = 0x11,
    KLCmdGetMode = 0x12,
 
    KLCmdChkPass,
    KLCmdSetPass,
    KLCmdEraseAll,
    KLCmdReadProgram,
    KLCmdStartProgram,
    KLCmdWriteProgram,
    KLCmdFinishProgram,
 
    KLCmdRead1Bit = 0x21,                //ReadSingleBit
    KLCmdWrite1Bit = 0x22,                //WriteSingleBit
 
    KLCmdReadBits = 0x23,                //ReadBits        n = 1 - 8
    KLCmdWriteBits = 0x24,                //ReadBits        n = 1 - 8
 
    KLCmdReadBitsByByte = 0x25,            //ReadBitsByByte    ,byteCount
    KLCmdWriteBitsByByte = 0x26,        //ReadBitsByByte    ,ByteCount
 
    KLCmdReadBitsByWord = 0x27,            //ReadBitsByWord    ,WordCount
    KLCmdWriteBitsByWord = 0x28,        //ReadBitsByWord    ,WordCount
 
    KLCmdReadDataByte = 0x31,            //ByteCount
    KLCmdWriteDataByte = 0x32,
 
    KLCmdReadDataWord = 0x33,            //WordCount
    KLCmdWriteDataWord = 0x34,
 
    KLCmdReadData = 0x35,                //?Count
    KLCmdWriteData = 0x36,
 
    KLCmdReadProg = 0x51,
    KLCmdWriteProg,
    KLCmdReadSysCfg,
    KLCmdWriteSysCfg,
    KLCmdSaveSysCfg,
    KLCmdSaveRunStat,
    KLCmdReadRunStat,
 
    KLCmdEraseFlashPage = 0x61,
    KLCmdWriteToFlash = 0x62,
 
    KLCmdGetEventLogCount,
    KLCmdGetEventLog,
    KLCmdClearEventLog,
    KLCmdGetFactoryData,
    KLCmdWriteFactoryData,
    KLCmdResetMachine,
    KLCmdGetUid,
    KLCmdSetTime,
 
    KLCmdMC,
    KLCmdMD,
    KLCmdMG,
 
    KLCmdErrRply = 0xEE,                //ERRORReply
};
 
typedef struct tagRunStat
{
    unsigned short Sign1;
    unsigned short Seq1;
    volatile unsigned short PowerCount;    //
    volatile unsigned short Reserved1;
    volatile unsigned int UpTime;        //Seconds;
    volatile unsigned int UserData1;
    volatile unsigned short WorkMode;
    volatile unsigned short WorkMode2;
    volatile unsigned short nBinProgBank;
    volatile unsigned short nBinProgSize;
    unsigned int Reserved2[1];
    unsigned short CRC1;
    unsigned short EndSign1;
}stRunStat, *pRunStat;
 
stRunStat KMRunStat;
 
enum enKeventType
{
    EventTypeNone = 0,
    EventTypePowerUp = 1,
    EventTypePowerDown = 2,
    EventTypePowerRecover = 3,
    EventTypeConnected = 4,
    EventTypeLostCon = 5,
    EventTypeSetTime = 6,
    EventTypeSysCfg = 7,
    EventTypeProg = 8,
    EventTypeForce = 9,
    EventTypeClearEvent = 10,
 
    EventType
};
 
typedef struct tagEventLog
{
    unsigned short Sign1;
    unsigned short Seq1;
    unsigned int nTime;
    unsigned short nType;
    unsigned short nParam1;
    unsigned int nParam2;
}stEventLog, *pEventLog;
 
 
typedef struct tagKLCmdName
{
    const int nCmd;
    const char * sName;
    const char * sType;
 
}KLCmdName;
 
const KLCmdName KLCmdNames[42] =
{
    {KLCmdNone,"None",""},    //==0    //Nothing
    {KLCmdPing,"Ping"},    //=1        //Ping
    {KLCmdPingReply,"PingReply"}, //2        //PingReply
    {KLCmdGetInfo,"GetInfo"},//3            //GetInfo
    {KLCmdVerInfo,"VerInfo"},// = 0x04,            //InfoReply
 
    {KLCmdRead,"Read","WX;WY;DT;SDT;EV;SV;LD;WL;CFG;FLASH;RAM"},// = 0x05,            //Read
    {KLCmdReadReply,"ReadReply"},// = 0x06,        //ReadReply
    {KLCmdWrite,"Write"},// = 0x07,            //Write
    {KLCmdWriteReply,"WriteReply"},// = 0x08,    //WriteReply
    {KLCmdSaveToFlash,"SaveToFlash"},// = 0x09,                //Write
 
    {KLCmdExChgData,"ExChgData"},// = 0x0A,                //ExChangeDate, = Wirte + Read
    {KLCmdExChgDataReply,"ExChgDataReply"},//,            //ExchangeData Reply
 
    {    KLCmdSyncRead,"SyncRead"},// = 0x0D,                //SyncRead
    {    KLCmdSyncWrite,    "SyncWrite"},//                     //SyncWrite
    {    KLCmdSequenRead,"SequenRead"},//                     //Sequence Read
    {    KLCmdSyncTime,"SyncTime"},//                         //SyncTime
 
    {    KLCmdGetMode,"GetMode"},//  = 0x12,
 
    {    KLCmdChkPass,"ChkPass"},// 
    {    KLCmdSetPass,"SetPass"},// 
    {    KLCmdEraseAll,"EraseAll"},// 
    {    KLCmdReadProgram,"ReadProgram"},// 
    {    KLCmdWriteProgram,"WriteProgram"},// 
 
    {    KLCmdRead1Bit,"Read1Bit"},//  = 0x21,                //ReadSingleBit
    {    KLCmdWrite1Bit,"Write1Bit"},//  = 0x22,                //WriteSingleBit
 
    {    KLCmdReadBits,"ReadBits"},//  = 0x23,                //ReadBits        n = 1 - 8
    {    KLCmdWriteBits,"WriteBits"},//  = 0x24,                //ReadBits        n = 1 - 8
 
    {    KLCmdReadBitsByByte,"ReadBitsByByte"},//  = 0x25,            //ReadBitsByByte
    {    KLCmdWriteBitsByByte,"WriteBitsByByte"},//  = 0x26,        //ReadBitsByByte
 
    {    KLCmdReadBitsByWord,"ReadBitsByWord"},//  = 0x27,            //ReadBitsByWord
    {    KLCmdWriteBitsByWord,"WriteBitsByWord"},//  = 0x28,        //ReadBitsByWord
 
    {    KLCmdReadDataByte,"ReadDataByte"},//  = 0x31,
    {    KLCmdWriteDataByte,"WriteDataByte"},//  = 0x32,
 
    {    KLCmdReadDataWord,"ReadDataWord"},//  = 0x33,
    {    KLCmdWriteDataWord,"WriteDataWord"},//  = 0x34,
 
    {    KLCmdReadData,"ReadData"},//  = 0x35,
    {    KLCmdWriteData,"WriteData"},//  = 0x36,
 
    {    KLCmdReadProg,"ReadProg"},//  = 0x51,
    {    KLCmdWriteProg,"WriteProg"},// 
    {    KLCmdReadSysCfg,"ReadSysCfg"},// 
    {    KLCmdWriteSysCfg,"WriteSysCfg"},// 
 
    {    KLCmdSaveSysCfg,"SaveSysCfg"},// 
//        KLCmdReadRunStat,
 
 
    {    KLCmdErrRply,"ErrRply"}//  = 0xEE,                //ERRORReply
};
 
typedef struct tagKLExtDataFrame
{
    UCHAR Dst;
    UCHAR nType;
    UCHAR Len2;
    UCHAR Data[1];
}*pKLExtDataFrame;
 
 
typedef union tagKLStatDef
{
    UCHAR StatByte;
    struct {
        UCHAR nSEQ : 4;
        UCHAR HasExt : 1;
        UCHAR HasErr : 1;
    };
}unKLStat, *pKLStat;
 
int m_nSeq = 0;
int m_nRSeq = 0;
unsigned char m_Dst;
 
//unsigned char m_Stat;
 
unKLStat m_Stat1 = { 0 };
unKLStat m_DstStat;
typedef struct tagKLReqPacketDef
{
 
    UCHAR StartSign;
    UCHAR DstAddr;
    UCHAR Stat;
    UCHAR Cmd;
    UCHAR Type1;
    UCHAR Params[1];
}stKLReqPacket, * pKLReqPacket;
 
typedef struct tagKLRplyPktHdr
{
    unsigned char RplyStSgn;    //
    unsigned char DstAddr;        //
    unsigned char nStatus;        //
    unsigned char nRplyCMD;        //
    unsigned char nSize1;            //
    unsigned char Datas[1];        //
}stKLRplyPktHdr, *pKLRplyPktHdr;
 
unsigned char m_Packetbuf[256];
unsigned char m_SendBuf[1024];
unsigned char m_RecvBuf[1024];
unsigned char m_DataBuf[1024];
 
typedef struct tagChnStat
{
    unsigned int Stat;
    unsigned int SendPackets;
    unsigned int RecvPackets;
    unsigned int LastSentTimeuS;
    unsigned int LostPackets;
    unsigned int CtnLstPkts;
    unsigned int MaxCtnLstPkts;
    unsigned int NotPkgErr;
    unsigned int PkgLenErr;
    unsigned int BCCErr;
    unsigned int TimeOutErr;
    unsigned int Delay;
    unsigned int MaxDelay;
    unsigned int SendTimeInterval;
    union
    {
        unsigned int ClientDatas[10];
        struct {
            unsigned int ClientRecvPkts;    //
            unsigned int ClientSendPkts;    //
            unsigned int ClientNotPktErr;    //
            unsigned int ClientMisIdPkts;    //
            unsigned int ClientPkgLenErr;    //
            unsigned int ClientBccErr;        //
            unsigned int ClientTimeOutErr;    //
        };
    };
} stChnStat, * pChnStat;
 
struct tagMEM
{
    union //tagWX
    {
        USHORT WX[64];
        UCHAR WXB[128];
        UINT WXD[32];
    };
    union //tagWY
    {
        USHORT WY[64];
        UCHAR WYB[128];
        UINT WYD[32];
    };
    union //tagDT
    {
        USHORT DT[256];
        UCHAR DTB[512];
        UINT DTD[128];
    };
    union //tagWR
    {
        USHORT WR[64];
        UCHAR WRB[128];
        UINT WRD[32];
    };
    union //tagSDT
    {
        UCHAR SDB[512];
        USHORT SDT[256];
        UINT SDD[128];
        struct {
            unsigned int EffJumperSW;
            unsigned int CurJumperSW;
            unsigned int haltick;
            unsigned int RunStat;
            unsigned int ErrStat;
            unsigned int nTickCount;
            unsigned int TotalRunTime;
            unsigned int ThisRunTime;
            unsigned int PwrOnCount;
            unsigned int LastScanTime;
            unsigned int ScanTimeuS;
            unsigned int MinScanTimeuS;
            unsigned int MaxScanTimeuS;
            unsigned short ADCValues[20];
        };
    };
}MEM;
 
CString m_resultStr;
 
static int xtoi(const char * hexstr, int len = 0);
unsigned char KLBCC(void * pData, int nSize);
 
int CalCRC(void * pBuf, int nSize);
 
/*
    Á¬½Ó״̬
    ¿ªÊ¼Á¬½Ó(䶨)-> ÐÄÌø°üÕý³£->ÒÑÁ¬½Ó -> ÐÄÌø°üÁ¬ÐøÕý³£ -> Á¬½ÓºÜºÃ
 
    Á¬½ÓºÜºÃ -> ÐÄÌø°ü Ê§°Ü / Êý¾Ý°üʧ°Ü -> ÒÑÁ¬½Ó (ÓдíÎó) 
 
    ÒÑÁ¬½Ó (ÓдíÎó) -> ÐÄÌø°üÕý³£ -> ÒÑÁ¬½Ó 
 
 
 
*/
 
int ParseReqPacket();
int MakeRplyPacket();
 
typedef int(*pSend)(void *, int);
typedef int(*pRecv)(void *, int);
typedef int(*pOpen)(int);
typedef int(*pClose)(int);
 
// pSend SendPkgFunc;
//  pRecv RecvPkgFunc;
//  pOpen OpenFunc;
//  pClose CloseFunc;
 
std::function<int (void *,int)> SendPkgFunc;
std::function<int(void *, int)> RecvPkgFunc;
std::function<int(int)> OpenFunc;
std::function<int(int)> CloseFunc;
 
 
 
int m_bSendCallBackSet = 0;
int m_bRecvCallBackSet = 0;
int m_bOpenCallBackSet = 0;
int m_bCloseCallBackSet = 0;
 
bool m_bOpened=false;
 
int SetSendCallBackFunc(std::function<int(void *, int)> pSendFunc);
int SetRecvCallBackFunc(std::function<int(void *, int)> pRecvFunc);
int SetOpenCallBackFunc(std::function<int(int)> pOpenFunc);
int SetCloseCallBackFunc(std::function<int(int)> pCloseFunc);
 
int m_nErrCount = 0;
int m_nContinueErrCount = 0;
int Open(int OpenParam=0)
{
    if (m_bOpenCallBackSet)
    {
        OpenFunc(OpenParam);
    }
    m_bOpened = true;
    return KL_OK;
};
int Close(int CloseParam=0)
{
    if (m_bCloseCallBackSet)
    {
        CloseFunc(CloseParam);
    }
    m_bOpened = false;
    return KL_OK;
};
int SendPacket(void * pBuf, int Len)
{
    if (m_bOpened && m_bSendCallBackSet) return SendPkgFunc(pBuf, Len);
    else return KL_ERR;
}
 
int RecvPacket(void * pBuf, int LenToRead, int ReTryCount=3)
{
    
    if (m_bOpened && m_bRecvCallBackSet)
    {
        int len2 = 0;
        char * pBufByte = (char *)pBuf;
        for (int i = 0; i < ReTryCount; i++)
        {
            int len1= RecvPkgFunc(pBufByte + len2, LenToRead - len2);
            len2 += len1;
            if (len2 >= LenToRead) break;
        }
        if (len2 >= LenToRead) {
            m_nContinueErrCount = 0;
            return len2;
        }
        else if (len2<=0) {
            m_nErrCount++;
            m_nContinueErrCount++;
            if (m_nContinueErrCount > 10)
            {
            //    Close(-1);
            }
            return KL_ERR;
        }
        else {
            return len2;
        }
    }
    else
    {
        return KL_ERR;
    }
}
int GetNextSeq();
 
int MakeExtDataFrame(void * pBuf, UCHAR nDst, UCHAR nType, UCHAR len2, void * pData);
 
//int MakeReqPacket(void * pBuf, UCHAR nDst, UCHAR Stat, UCHAR nCMD, UCHAR Type, USHORT nAddr = 0, USHORT nCount = 0, void * pData = NULL);
 
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);
 
int CheckPackage(void * pBuf, int nSize);
int ProcessPacket(void *pBuf, int nLen);
int ParseRplyPacket(void *pBuf, int nPkgLen, UCHAR * nCmd, UCHAR * Status, USHORT* nCount, void * pData);
 
int GetInfo(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
int GetSN(UCHAR nDst, int * nCount);
int GetUID(UCHAR nDst, int * nCount);
//int GetTime32(UCHAR nDst, int * nCount);
//int SetTime32(UCHAR nDst, int * nCount);
int GetDateTime32(UCHAR nDst, UINT * pValue);
int SetDateTime32(UCHAR nDst, UINT Value);
 
 
int GetEventLogCount(UCHAR nDst, int * nCount);
int GetEventLog(UCHAR nDst, int nStartIndex, int nCount , stEventLog * pEventLogs);
 
 
int ReadBit(UCHAR nDst, UCHAR nType,USHORT nBitAddr, UCHAR * Value);//Read 1 Single bit
int WriteBit(UCHAR nDst, UCHAR nType,USHORT nBitAddr, UCHAR Value);//Write 1 Single bit
int ReadBits(UCHAR nDst, UCHAR nBitCount, UCHAR nType, USHORT nBitAddr, UCHAR * Values);
int WriteBits(UCHAR nDst, UCHAR nBitCount, UCHAR nType, USHORT nBitAddr, UCHAR * Values);
int ReadBitsByWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT *Values);
int WriteBitsByWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT *Values);
 
int ReadDataByte(UCHAR nDst, UCHAR nByteCount, UCHAR nType, USHORT nByteAddr, UCHAR * Values);
int WriteDataByte(UCHAR nDst, UCHAR nByteCount, UCHAR nType, USHORT nByteAddr, UCHAR * Values);
 
int ReadDataWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
int WriteDataWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
 
int ReadData(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
int WriteData(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values);
 
int GetMode(UCHAR nDst, UCHAR nType);
int ChangeMode(UCHAR nDst,  UCHAR nType);
 
 
int ReadProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
 
int StartProgram(UCHAR nDst, UCHAR nType);
int WriteProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
int FinishProgram(UCHAR nDst, UCHAR nType, USHORT nStepSize);
 
int ReadRunStat(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
 
 
};