| | |
| | | */
|
| | | #pragma once
|
| | | #include "KDefine.h"
|
| | | #include "HvSerialPort.h"
|
| | | #include <functional>
|
| | | class KLink
|
| | | {
|
| | |
| | | public:
|
| | | KLink();
|
| | | virtual ~KLink();
|
| | | HvSerialPort m_SerialPort;
|
| | | #define TYPECOIL 0x00
|
| | | #define TYPEDATA 0x80
|
| | | enum enKLCoilTypes
|
| | |
| | | KLCmdResetMachine,
|
| | | KLCmdGetUid,
|
| | | KLCmdSetTime,
|
| | | KLCmdGetSN,
|
| | |
|
| | | KLCmdMC,
|
| | |
|
| | | KLCmdMC = 0x70, |
| | | KLCmdMD,
|
| | | KLCmdMG,
|
| | |
|
| | |
| | | // 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;
|
| | | typedef struct tagCallBackFuncs
|
| | | {
|
| | | std::function<int(void)> OpenFunc;
|
| | | std::function<int(void)> CloseFunc;
|
| | | std::function<int(void)> ClearBufFunc;
|
| | | std::function<int(void *, int)> SendPkgFunc;
|
| | | std::function<int(void *, int)> RecvPkgFunc;
|
| | | }stCallBackFuncs, *pCallBackFuncs;
|
| | |
|
| | |
|
| | | stCallBackFuncs m_CallBackFuncs;
|
| | |
|
| | | int m_bSendCallBackSet = 0;
|
| | | int m_bRecvCallBackSet = 0;
|
| | | int m_bOpenCallBackSet = 0;
|
| | | int m_bCloseCallBackSet = 0;
|
| | | int m_bClearBufCallBackSet = 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 SetCallBackFuncs(pCallBackFuncs pFuncSt);
|
| | |
|
| | | int m_nErrCount = 0;
|
| | | int m_nContinueErrCount = 0;
|
| | |
| | | {
|
| | | if (m_bOpenCallBackSet)
|
| | | {
|
| | | OpenFunc(OpenParam);
|
| | | m_CallBackFuncs.OpenFunc();
|
| | | }
|
| | | m_bOpened = true;
|
| | | return KL_OK;
|
| | |
| | | {
|
| | | if (m_bCloseCallBackSet)
|
| | | {
|
| | | CloseFunc(CloseParam);
|
| | | m_CallBackFuncs.CloseFunc();
|
| | | }
|
| | | m_bOpened = false;
|
| | | return KL_OK;
|
| | | };
|
| | | int SendPacket(void * pBuf, int Len)
|
| | | {
|
| | | if (m_bOpened && m_bSendCallBackSet) return SendPkgFunc(pBuf, Len);
|
| | | if (m_bOpened && m_bSendCallBackSet)
|
| | | { |
| | | if (m_bClearBufCallBackSet) m_CallBackFuncs.ClearBufFunc();
|
| | | return m_CallBackFuncs.SendPkgFunc(pBuf, Len);
|
| | | }
|
| | | else return KL_ERR;
|
| | | }
|
| | |
|
| | | int RecvPacket(void * pBuf, int LenToRead, int ReTryCount=3)
|
| | | int RecvPacket(void * pBuf, int LenToRead, int ReTryCount=1)
|
| | | {
|
| | |
|
| | | if (m_bOpened && m_bRecvCallBackSet)
|
| | |
| | | char * pBufByte = (char *)pBuf;
|
| | | for (int i = 0; i < ReTryCount; i++)
|
| | | {
|
| | | int len1= RecvPkgFunc(pBufByte + len2, LenToRead - len2);
|
| | | int len1= m_CallBackFuncs.RecvPkgFunc(pBufByte + len2, LenToRead - len2);
|
| | | if (len1 <= 0 || len1 > 256) {
|
| | | continue;
|
| | | }
|
| | | len2 += len1;
|
| | | if (len2 >= LenToRead) break;
|
| | | }
|
| | |
| | | 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 GetInfo(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
| | | int GetSN(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
| | | int GetUID(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
| | | int GetFactoryData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
| | | int WriteFactoryData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
| | |
|
| | | //int GetTime32(UCHAR nDst, int * nCount);
|
| | | //int SetTime32(UCHAR nDst, int * nCount);
|
| | | int GetDateTime32(UCHAR nDst, UINT * pValue);
|
| | |
| | |
|
| | | 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 ReadBits(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR nBitCount, UCHAR * Values);
|
| | | int WriteBits(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR nBitCount, UCHAR * Values);
|
| | | int ReadBitsByWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT *Values);
|
| | | int WriteBitsByWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, 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 ReadDataByte(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR * Values);
|
| | | int WriteDataByte(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, 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 ReadDataWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
| | | int WriteDataWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, 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 ReadData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
| | | int WriteData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values);
|
| | |
|
| | | int GetMode(UCHAR nDst, UCHAR nType);
|
| | | int ChangeMode(UCHAR nDst, UCHAR nType);
|