From 4cda72771765720a6a8721bd8844945c2403afe6 Mon Sep 17 00:00:00 2001 From: QuakeGod <quakegod@sina.com> Date: 星期一, 23 十月 2023 08:52:12 +0800 Subject: [PATCH] fix vcxproj version --- MTerm2/KLink.cpp | 99 ++++++++++++++++++++++++++++++------------------- 1 files changed, 61 insertions(+), 38 deletions(-) diff --git a/MTerm2/KLink.cpp b/MTerm2/KLink.cpp index 53ba599..fc4508d 100644 --- a/MTerm2/KLink.cpp +++ b/MTerm2/KLink.cpp @@ -103,32 +103,18 @@ 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; @@ -566,7 +552,7 @@ 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); @@ -629,6 +615,9 @@ else { m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2); + CString s1; + s1= GetErrDescStr(res); + m_resultStr += s1; return res; } @@ -637,14 +626,15 @@ 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); @@ -654,34 +644,58 @@ 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; - unsigned char nCmd; - unsigned short nnCount=0; - int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf); - for (int i = 0; i < nnCount/2; i++) + 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) { -// Values[0] = m_DataBuf[0]; - Values[i] = m_DataBuf[i*2] + (m_DataBuf[i * 2 +1]<<8); + 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; } - return res; + 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; @@ -693,6 +707,7 @@ 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); @@ -710,6 +725,7 @@ 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); @@ -727,6 +743,7 @@ 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; @@ -750,6 +767,7 @@ 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; @@ -775,6 +793,7 @@ 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; @@ -800,6 +819,7 @@ 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; @@ -822,6 +842,7 @@ 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); @@ -842,6 +863,7 @@ 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); @@ -860,6 +882,7 @@ 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); -- Gitblit v1.9.1