| | |
| | | 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;
|
| | |
| | | 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:
|
| | |
| | |
|
| | | 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;
|
| | |
| | | SendPacket(m_Packetbuf, len1);
|
| | | int len2 = RecvPacket(m_RecvBuf, 64);
|
| | | 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;
|
| | | }
|
| | |
| | | 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();
|
| | |
| | | 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)
|
| | | {
|
| | |
| | |
|
| | | 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;
|
| | | 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); }
|
| | | 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;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | |
| | | 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);
|
| | | for (int i = 0; i < nnCount/2; i++)
|
| | | {
|
| | |
| | | }
|
| | | return res;
|
| | | }
|
| | | int KLink::WriteDataWord(UCHAR nDst, UCHAR nWordCount, UCHAR nType, USHORT nWordAddr, USHORT * Values)
|
| | | int KLink::WriteDataWord(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, 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); }
|
| | | nWordCount = 0;
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + nWordCount;
|
| | | int len2 = RecvPacket(m_RecvBuf, nWordCount);
|
| | | if (len2 == 0) { len2 = RecvPacket(m_RecvBuf, nWordCount); }
|
| | | 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;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | |
| | | 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;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | |
| | | 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;
|
| | | 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;
|
| | | 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;
|
| | | 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;
|
| | | 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;
|
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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));
|
| | |
| | | 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;
|
| | |
|
| | | }
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | |
| | | 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;
|
| | |
|
| | |
| | | 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;
|
| | |
|
| | |
| | | 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];
|
| | |
| | | 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;
|
| | |
|
| | |
| | | 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;
|
| | |
| | | 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;
|
| | | }
|
| | |
| | | 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];
|