| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | int KLink::SetSendCallBackFunc(std::function<int(void *, int)> pSendFunc)
|
| | | int KLink::SetCallBackFuncs(pCallBackFuncs pFuncSt)
|
| | | {
|
| | | SendPkgFunc = pSendFunc;
|
| | | m_bSendCallBackSet = 1;
|
| | | if (pFuncSt->OpenFunc) { m_CallBackFuncs.OpenFunc = pFuncSt->OpenFunc; m_bOpenCallBackSet = 1; }
|
| | | if (pFuncSt->CloseFunc) { m_CallBackFuncs.CloseFunc = pFuncSt->CloseFunc; m_bCloseCallBackSet = 1; }
|
| | | if (pFuncSt->SendPkgFunc) { m_CallBackFuncs.SendPkgFunc = pFuncSt->SendPkgFunc; m_bSendCallBackSet = 1; }
|
| | | if (pFuncSt->RecvPkgFunc) { m_CallBackFuncs.RecvPkgFunc = pFuncSt->RecvPkgFunc; m_bRecvCallBackSet = 1; }
|
| | | if (pFuncSt->ClearBufFunc) { m_CallBackFuncs.ClearBufFunc = pFuncSt->ClearBufFunc; m_bClearBufCallBackSet = 1; }
|
| | | // if (pFuncSt->SendPkgFunc) { m_CallBackFuncs.SendPkgFunc = pFuncSt->SendPkgFunc; m_bSendCallBackSet = 1; }
|
| | |
|
| | | return KL_OK;
|
| | | }
|
| | |
|
| | | int KLink::SetRecvCallBackFunc(std::function<int(void *, int)> pRecvFunc)
|
| | | {
|
| | | RecvPkgFunc = pRecvFunc;
|
| | | m_bRecvCallBackSet = 1;
|
| | | return KL_OK;
|
| | | }
|
| | |
|
| | | int KLink::SetOpenCallBackFunc(std::function<int(int)> pOpenFunc)
|
| | | {
|
| | | OpenFunc = pOpenFunc;
|
| | | m_bOpenCallBackSet = 1;
|
| | | return KL_OK;
|
| | | }
|
| | | int KLink::SetCloseCallBackFunc(std::function<int(int)> pCloseFunc)
|
| | | {
|
| | | CloseFunc = pCloseFunc;
|
| | | m_bCloseCallBackSet = 1;
|
| | | return KL_OK;
|
| | | }
|
| | | int KLink::MakeExtDataFrame(void * pBuf, UCHAR nDst, UCHAR nType, UCHAR len2, void * pData)
|
| | | {
|
| | | int framelen1 = 0;
|
| | |
| | | m_DataBuf[0] = Value;
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWrite1Bit, nType, nBitAddr,1,m_DataBuf);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int len2 = RecvPacket(m_RecvBuf, 64);
|
| | | int len2 = RecvPacket(m_RecvBuf, 6);
|
| | | unsigned char nCmd;
|
| | | unsigned short nCount=0;
|
| | | ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nCount, m_DataBuf);
|
| | |
| | | else
|
| | | {
|
| | | m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
| | | CString s1; |
| | | s1= GetErrDescStr(res);
|
| | | m_resultStr += s1;
|
| | | return res;
|
| | | }
|
| | |
|
| | |
| | | int KLink::WriteDataByte(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteDataByte, nType, nByteAddr/2, nByteCount, Values);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | nByteCount = 0;
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
| | | int len2 = RecvPacket(m_RecvBuf, numToRead);
|
| | | if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
| | | if (len2 == 0) return KL_ERR;
|
| | | // if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
| | | if (len2 <= 0) return KL_ERR;
|
| | | unsigned char nCmd;
|
| | | unsigned short nnCount=0;
|
| | | int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | |
| | | int KLink::ReadDataWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadDataWord, nType, nWordAddr, nWordCount);
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadDataWord, nType, nWordAddr, nWordCount*2);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + nWordCount;
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + nWordCount*2;
|
| | |
|
| | | int len2 = RecvPacket(m_RecvBuf, numToRead);
|
| | | if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
| | | if (len2 == 0) return KL_ERR;
|
| | | if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
| | | if (len2 <= 0) { m_resultStr.Format(_T("Recv Failed len %d To=%d"), len2, numToRead); return KL_ERR; }
|
| | | if (len2 < numToRead)
|
| | | {
|
| | | CString s1;
|
| | | for (int i = 0; i < len2; i++)
|
| | | {
|
| | | s1.AppendFormat(_T("%02X "), m_RecvBuf[i]);
|
| | | }
|
| | | s1.Append(_T("\r\n"));
|
| | | m_resultStr.Format(_T("ToRead %d R= %d \r\n"), numToRead, len2);
|
| | | m_resultStr += s1;
|
| | | }
|
| | | unsigned char nCmd;
|
| | | unsigned short nnCount=0;
|
| | | int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | | if (res == KL_OK)
|
| | | {
|
| | | for (int i = 0; i < nnCount/2; i++)
|
| | | {
|
| | | // Values[0] = m_DataBuf[0];
|
| | | Values[i] = m_DataBuf[i*2] + (m_DataBuf[i * 2 +1]<<8);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
| | | CString s1;
|
| | | s1 = GetErrDescStr(res);
|
| | | m_resultStr += s1;
|
| | | return res;
|
| | | }
|
| | | return KL_OK;
|
| | | }
|
| | | int KLink::WriteDataWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteDataWord, nType, nWordAddr, nWordCount, Values);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | nWordCount = 0;
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + nWordCount;
|
| | | int len2 = RecvPacket(m_RecvBuf, nWordCount);
|
| | | if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, nWordCount); }
|
| | | int len2 = RecvPacket(m_RecvBuf, numToRead);
|
| | | if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
|
| | | if (len2 == 0) return KL_ERR;
|
| | | unsigned char nCmd;
|
| | | unsigned short nnCount=0;
|
| | |
| | | int KLink::ReadData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadData, nType, nWordAddr, nWordCount);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | |
| | | int KLink::WriteData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteData, nType, nWordAddr, nWordCount, Values);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | |
| | | int KLink::GetInfo(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetInfo, nType, nWordAddr, nWordCount, Values);
|
| | | CString s1;
|
| | |
| | | int KLink::GetSN(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetSN, nType, nWordAddr, nWordCount, Values);
|
| | | CString s1;
|
| | |
| | | int KLink::GetUID(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetUid, nType, nWordAddr, nWordCount, Values);
|
| | | CString s1;
|
| | |
| | | int KLink::GetFactoryData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetFactoryData, nType, nWordAddr, nWordCount, Values);
|
| | | CString s1;
|
| | |
| | | int KLink::WriteFactoryData(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteFactoryData, nType, nWordAddr, nWordCount, Values);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | |
| | | int KLink::GetEventLogCount(UCHAR nDst, int * nCount)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetEventLogCount, 0);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | |
| | | int KLink::GetEventLog(UCHAR nDst, int nStartIndex, int nCount, stEventLog * theEventLogs)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetEventLog, 0, nStartIndex, nCount, 0);
|
| | | SendPacket(m_Packetbuf, len1);
|