From dd67df95a7303aee3bed65ffa935465f20ee8b32 Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期五, 22 七月 2022 15:19:55 +0800
Subject: [PATCH] merge from dev2

---
 MTerm2/KLink.cpp |  306 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 226 insertions(+), 80 deletions(-)

diff --git a/MTerm2/KLink.cpp b/MTerm2/KLink.cpp
index 6e3fdfc..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;
@@ -238,6 +224,18 @@
 		PkgLen1 = sizeof(stKLReqPacket) + Datalen;
 		break;
 	case KLCmdGetInfo:
+	case KLCmdGetSN:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdGetFactoryData:
+		Datalen = 0;
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
+		break;
+	case KLCmdWriteFactoryData:
+		Datalen = nCount;
+		memcpy(pPacket->Params + 4, pData, Datalen);
+		PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
 		break;
 	case KLCmdRead:
 		Datalen = 0;
@@ -442,12 +440,21 @@
 	case KLCmdPing:
 	case KLCmdPingReply:
 		*nCount = Datalen;
-		memcpy(pPacket->Datas, pData, Datalen);
+		memcpy(pData, pPacket->Datas, Datalen);
 		break;
 	case KLCmdGetInfo:
 	case KLCmdVerInfo:
 		*nCount = Datalen;
-		memcpy(pPacket->Datas, pData, Datalen);
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	case KLCmdGetUid:
+	case KLCmdGetSN:
+	case KLCmdGetFactoryData:
+		*nCount = Datalen;
+		memcpy(pData, pPacket->Datas, Datalen);
+		break;
+	case KLCmdWriteFactoryData:
+		*nCount = Datalen;
 		break;
 	case KLCmdRead:
 	case KLCmdReadReply:
@@ -534,7 +541,7 @@
 
 	int len2=RecvPacket(m_RecvBuf, numToRead);
 	unsigned char nCmd;
-	unsigned short nCount;
+	unsigned short nCount=0;
 	ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nCount, m_DataBuf);
 	Value[0] = m_DataBuf[0];
 	return KL_OK;
@@ -545,25 +552,25 @@
 	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;
+	unsigned short nCount=0;
 	ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nCount, m_DataBuf);
 	return KL_OK;
 }
-int KLink::ReadBits(UCHAR nDst, UCHAR nBitCount, UCHAR nType, USHORT nBitAddr, UCHAR * Values)
+int KLink::ReadBits(UCHAR nDst, UCHAR nType, USHORT nBitAddr, UCHAR nBitCount, UCHAR * Values)
 {
 	return KL_OK;
 }
-int KLink::WriteBits(UCHAR nDst, UCHAR nBitCount, UCHAR nType, USHORT nBitAddr, UCHAR * Values)
+int KLink::WriteBits(UCHAR nDst,  UCHAR nType, USHORT nBitAddr, UCHAR nBitCount, UCHAR * Values)
 {
 	return KL_OK;
 }
-int KLink::ReadBitsByWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT *Values)
+int KLink::ReadBitsByWord(UCHAR nDst,  UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT *Values)
 {
 	return KL_OK;
 }
-int KLink::WriteBitsByWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT *Values)
+int KLink::WriteBitsByWord(UCHAR nDst,  UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT *Values)
 {
 	return KL_OK;
 }
@@ -575,7 +582,7 @@
 	return m_nSeq;
 }
 
-int KLink::ReadDataByte(UCHAR nDst, UCHAR nByteCount, UCHAR nType, USHORT nByteAddr, UCHAR * Values)
+int KLink::ReadDataByte(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR * Values)
 {
 	m_Dst = nDst;
 	m_resultStr.Empty();
@@ -598,7 +605,7 @@
 		m_resultStr += s1;
 	}
 	unsigned char nCmd  ;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	if (res == KL_OK)
 	{
@@ -608,66 +615,99 @@
 	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::WriteDataByte(UCHAR nDst, UCHAR nByteCount, UCHAR nType, USHORT nByteAddr, UCHAR * Values)
+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);
-	int len2 = RecvPacket(m_RecvBuf, 64);
-	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
-	if (len2 == 0) return KL_ERR;
+	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;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	return res;
 }
 
-int KLink::ReadDataWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
+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) { 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, numToRead);
 	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
 	if (len2 == 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
-	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
-	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);
-	}
-	return res;
-}
-int KLink::WriteDataWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
-{
-	m_Dst = nDst;
-	UCHAR nExpSeq = GetNextSeq();
-	int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteDataWord, nType, nWordAddr, nWordCount, Values);
-	SendPacket(m_Packetbuf, len1);
-	int len2 = RecvPacket(m_RecvBuf, 64);
-	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
-	if (len2 == 0) return KL_ERR;
-	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	Values[0] = m_DataBuf[0];
 	return res;
 }
 
-int KLink::ReadData(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
+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);
@@ -675,16 +715,17 @@
 	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
 	if (len2 == 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	for (int i=0;i<nnCount;i++)	Values[i] = m_DataBuf[i];
 	return res;
 
 	return KL_OK;
 }
-int KLink::WriteData(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
+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);
@@ -692,33 +733,137 @@
 	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
 	if (len2 == 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 //	Values[0] = m_DataBuf[0];
 	return res;
 
 	return KL_OK;
 }
-int KLink::GetInfo(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
+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;
+	for (int i = 0; i < len1; i++) {
+		s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
+	}
+	m_resultStr = s1;
 	SendPacket(m_Packetbuf, len1);
-	int len2 = RecvPacket(m_RecvBuf, 64);
-	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
+	int numToRead = sizeof(stKLRplyPktHdr) + 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;
+	unsigned short nnCount=0;
+	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, Values);
+	//	Values[0] = m_DataBuf[0];
+	return res;
+
+	return KL_OK;
+}
+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;
+	for (int i = 0; i < len1; i++) {
+		s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
+	}
+	m_resultStr = s1;
+	SendPacket(m_Packetbuf, len1);
+	nWordCount = 4;
+	int numToRead = sizeof(stKLRplyPktHdr) + 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 res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, Values);
+	//	Values[0] = m_DataBuf[0];
+	return res;
+
+	return KL_OK;
+	return 0;
+}
+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;
+	for (int i = 0; i < len1; i++) {
+		s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
+	}
+	m_resultStr = s1;
+	SendPacket(m_Packetbuf, len1);
+	int numToRead = sizeof(stKLRplyPktHdr) + 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 res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, Values);
+	//	Values[0] = m_DataBuf[0];
+	return res;
+
+	return KL_OK;
+	return 0;
+}
+
+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;
+	for (int i = 0; i < len1; i++) {
+		s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
+	}
+	m_resultStr = s1;
+	SendPacket(m_Packetbuf, len1);
+	int numToRead = sizeof(stKLRplyPktHdr) + 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 res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, Values);
+	//	Values[0] = m_DataBuf[0];
+	return res;
+	return KL_OK;
+}
+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);
+	nWordCount = 0;
+	int numToRead = sizeof(stKLRplyPktHdr) + 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 res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	//	Values[0] = m_DataBuf[0];
 	return res;
 
 	return KL_OK;
 }
+
 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);
@@ -726,7 +871,7 @@
 	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
 	if (len2 == 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	nCount[0] = *(int *)m_DataBuf;
 	return res;
@@ -737,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);
@@ -744,7 +890,7 @@
 	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
 	if (len2 == 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	
 	memcpy(theEventLogs, m_DataBuf, nCount * sizeof(stEventLog));
@@ -757,7 +903,7 @@
 int  KLink::GetDateTime32(UCHAR nDst, UINT * pValue)
 {
 	int res = KL_OK;
-	res = ReadDataByte(nDst, 4, KLDataTypeSDT, 36, (UCHAR *)pValue);
+	res = ReadDataByte(nDst,  KLDataTypeSDT, 36, 4, (UCHAR *)pValue);
 	return res;
 
 }
@@ -765,7 +911,7 @@
 int  KLink::SetDateTime32(UCHAR nDst, UINT  Value)
 {
 	int res = KL_OK;
-	res = WriteDataByte(nDst, 4, KLDataTypeSDT, 36, (UCHAR *)&Value);
+	res = WriteDataByte(nDst, KLDataTypeSDT, 36, 4, (UCHAR *)&Value);
 	return res;
 }
 
@@ -781,7 +927,7 @@
 	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
 	if (len2 == 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	return res;
 
@@ -800,7 +946,7 @@
 	if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, 64); }
 	if (len2 == 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	return res;
 
@@ -821,7 +967,7 @@
 	if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
 	if (len2 <= 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	unsigned char * values2 = (unsigned char *)Values;
 	for (int i = 0; i < nnCount; i++)	values2[i] = m_DataBuf[i];
@@ -840,7 +986,7 @@
 	if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6); }
 	if (len2 <= 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	return res;
 
@@ -857,7 +1003,7 @@
 	if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
 	if (len2 <= 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	//	Values[0] = m_DataBuf[0];
 	return res;
@@ -875,7 +1021,7 @@
 	if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
 	if (len2 <= 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	return res;
 }
@@ -893,7 +1039,7 @@
 	if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, numToRead); }
 	if (len2 <= 0) return KL_ERR;
 	unsigned char nCmd;
-	unsigned short nnCount;
+	unsigned short nnCount=0;
 	res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
 	unsigned char * values2 = (unsigned char *)Values;
 	for (int i = 0; i < nnCount; i++)	values2[i] = m_DataBuf[i];

--
Gitblit v1.9.1