| | |
| | | // dlg.DoModal();
|
| | | */
|
| | | CDialogCommSet1 dialog1;
|
| | | if (m_bCommParamSet)
|
| | | // if (m_bCommParamSet)
|
| | | {
|
| | | dialog1.m_nComNum = m_nPort;
|
| | | dialog1.m_nBaudRate = m_nBaudRate;
|
| | |
| | | if (r == MySerPort1.R_OK)
|
| | | {
|
| | | m_bOpened = true;
|
| | | // GotoCmdMode();
|
| | | // MyKLink1.Open();
|
| | | // m_static_connect.SetCtlColor(RGB(0, 255, 0));
|
| | | return KL_OK;
|
| | |
| | | }
|
| | | */
|
| | | m_bOpened = true;
|
| | | // |
| | | return KL_OK;
|
| | | };
|
| | | int KLink1::Close(int CloseParam)
|
| | | {
|
| | | ExitCmdMode();
|
| | | if (m_bCloseCallBackSet)
|
| | | {
|
| | | m_CallBackFuncs.CloseFunc();
|
| | |
| | | m_bOpened = false;
|
| | | return KL_OK;
|
| | | };
|
| | |
|
| | | int KLink1::GotoCmdMode(int Param)
|
| | | {
|
| | | int res = KL_OK;
|
| | | int len1 = 3;
|
| | | m_Packetbuf[0] = '+';
|
| | | m_Packetbuf[1] = '+';
|
| | | m_Packetbuf[2] = '+';
|
| | |
|
| | | SendPacket(m_Packetbuf, len1);
|
| | |
|
| | | return res;
|
| | | }
|
| | |
|
| | | int KLink1::ExitCmdMode(int Param)
|
| | | {
|
| | | int res = KL_OK;
|
| | | int len1 = 3;
|
| | | m_Packetbuf[0] = '-';
|
| | | m_Packetbuf[1] = '-';
|
| | | m_Packetbuf[2] = '-';
|
| | |
|
| | | SendPacket(m_Packetbuf, len1);
|
| | |
|
| | | return res;
|
| | | }
|
| | |
|
| | | int KLink1::Connect(int ConnectParam)
|
| | | {
|
| | | int OpenParam = ConnectParam;
|
| | |
| | | unsigned short len1;
|
| | | unsigned short buf1[256];
|
| | | //m_resultStr = MySerPort1.m_strResult;
|
| | | GotoCmdMode();
|
| | | return res;
|
| | | if (res == KL_OK)
|
| | | {
|
| | | GotoCmdMode();
|
| | | int res2 = GetInfo(m_Dst, &len1, buf1);
|
| | |
|
| | | if (m_bOnConnectCallBackSet) { m_CallBackFuncs.OnConnect(); }
|
| | |
| | | }
|
| | | int KLink1::DisConnect(int DisConnectParam)
|
| | | {
|
| | | ExitCmdMode();
|
| | | if (m_bOnDisConnectCallBackSet) { m_CallBackFuncs.OnDisConnect(DisConnectParam); }
|
| | | return Close();
|
| | | }
|
| | |
| | | {
|
| | | if (m_bOpened && m_bSendCallBackSet)
|
| | | {
|
| | | m_nTotalSendCount++;
|
| | | if (m_bClearBufCallBackSet) m_CallBackFuncs.ClearBufFunc();
|
| | | return m_CallBackFuncs.SendPkgFunc(pBuf, Len);
|
| | | }
|
| | |
| | | }
|
| | | if (len2 >= LenToRead) {
|
| | | m_nContinueErrCount = 0;
|
| | | m_nTotalRecvCount++;
|
| | | return len2;
|
| | | }
|
| | | else if (len2 <= 0) {
|
| | |
| | | return KL_ERR;
|
| | | }
|
| | | else {
|
| | | m_nTotalRecvCount++;
|
| | | return len2;
|
| | | }
|
| | | }
|
| | |
| | | pPacket->Cmd = nCMD;
|
| | | pPacket->Type1 = Type;
|
| | | int Datalen = 0;
|
| | | int nWordAddr;
|
| | | int nByteAddr;
|
| | | int nWordCount;
|
| | |
|
| | | switch (nCMD)
|
| | |
| | | Datalen = 0;
|
| | | PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
| | | break;
|
| | | case KLCmdReadPLCAnno:
|
| | | Datalen = 0;
|
| | | PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
| | | break;
|
| | | case KLCmdStartPLCAnno:
|
| | | Datalen = 0;
|
| | | PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
| | | break;
|
| | | case KLCmdWritePLCAnno:
|
| | | Datalen = nCount;
|
| | | memcpy(pPacket->Params + 4, pData, Datalen);
|
| | | PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
| | | break;
|
| | | case KLCmdFinishPLCAnno:
|
| | | Datalen = 0;
|
| | | PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
| | | break;
|
| | |
|
| | | case KLCmdReadRunStat:
|
| | | Datalen = 0;
|
| | |
| | | break;
|
| | |
|
| | | default:
|
| | | pPacket->Params[0] = nAddr % 256;
|
| | | pPacket->Params[1] = nAddr / 256;
|
| | | pPacket->Params[2] = nCount % 256;
|
| | | pPacket->Params[3] = nCount / 256;
|
| | | Datalen = 0;
|
| | | Datalen = nCount; |
| | | memcpy(pPacket->Params + 4, pData, Datalen);
|
| | | PkgLen1 = sizeof(stKLReqPacket) + 4 + Datalen;
|
| | | break;
|
| | |
| | | return PkgLen1;
|
| | | }
|
| | |
|
| | | int KLink1::MakeRemoteReqPacketEx(void* pBuf, UCHAR nDst, UCHAR Stat, UCHAR nPort, UCHAR nChildId, UCHAR nReqId, UCHAR Param1, USHORT nAddr , USHORT nCount , void* pData , int ExtFrameLen , void* pExtDataFrame)
|
| | | {
|
| | | int PkgLen1 = 0;
|
| | | pKLReqPacket pPacket = (pKLReqPacket)pBuf;
|
| | | pPacket->StartSign = KLSignStart;
|
| | | pPacket->DstAddr = nDst;
|
| | | pPacket->Stat = Stat;
|
| | | pPacket->Cmd = KLCmdPortRemoteReq;
|
| | | pPacket->Type1 = nReqId;
|
| | |
|
| | | pKLStat pStat = (pKLStat) & (pPacket->Stat);
|
| | | int Datalen = nCount;
|
| | | int nWordAddr = nAddr;
|
| | | int nWordCount = nCount;
|
| | | pPacket->Params[0] = nPort;
|
| | | pPacket->Params[1] = nChildId;
|
| | | pPacket->Params[2] = Param1;
|
| | | pPacket->Params[3] = nAddr % 256;
|
| | | pPacket->Params[4] = nAddr / 256;
|
| | | pPacket->Params[5] = nCount % 256;
|
| | | // pPacket->Params[6] = nCount / 256;
|
| | | memcpy(&pPacket->Params[6], pData, Datalen);
|
| | | PkgLen1 = sizeof(stKLReqPacket) + 6 + Datalen;
|
| | |
|
| | | if (PkgLen1 >= sizeof(stKLReqPacket))
|
| | | {
|
| | | UCHAR BCC = KLBCC(pBuf, PkgLen1 - 1);
|
| | | pPacket->Params[PkgLen1 - sizeof(stKLReqPacket)] = BCC;
|
| | | }
|
| | | /*
|
| | | if (pStat->HasExt && ExtFrameLen > 0 && pExtDataFrame != NULL)
|
| | | {
|
| | |
|
| | | memcpy(pPacket->Params + PkgLen1 - sizeof(stKLReqPacket) + 1, pExtDataFrame, ExtFrameLen);
|
| | | PkgLen1 += ExtFrameLen;
|
| | | };
|
| | | */
|
| | | return PkgLen1;
|
| | | }
|
| | |
|
| | | int KLink1::CheckPackage(void * pBuf, int nSize)
|
| | | {
|
| | |
| | | m_nRSeq = ((pKLStat)&nStatus)->nSEQ;
|
| | | int Datalen = pPacket->nSize1;
|
| | | *nCount = Datalen;
|
| | | USHORT ErrCode;
|
| | | switch (*nCmd)
|
| | | {
|
| | | case KLCmdNone:
|
| | |
| | |
|
| | | case KLCmdSaveToFlash:
|
| | | break;
|
| | |
|
| | | case KLCmdGetMode:
|
| | | *nCount = Datalen;
|
| | | memcpy(pData, pPacket->Datas, Datalen);
|
| | | break;
|
| | | case KLCmdReadProgram:
|
| | | *nCount = Datalen;
|
| | | memcpy(pData, pPacket->Datas, Datalen);
|
| | |
| | | *nCount = Datalen;
|
| | | break;
|
| | | case KLCmdFinishProgram:
|
| | | *nCount = Datalen;
|
| | | break;
|
| | | case KLCmdReadPLCAnno:
|
| | | *nCount = Datalen;
|
| | | memcpy(pData, pPacket->Datas, Datalen);
|
| | | break;
|
| | | case KLCmdStartPLCAnno:
|
| | | *nCount = Datalen;
|
| | | break;
|
| | | case KLCmdWritePLCAnno:
|
| | | *nCount = Datalen;
|
| | | break;
|
| | | case KLCmdFinishPLCAnno:
|
| | | *nCount = Datalen;
|
| | | break;
|
| | |
|
| | |
| | | *nCount = Datalen;
|
| | | memcpy(pData, pPacket->Datas, Datalen);
|
| | | break;
|
| | |
|
| | | case KLCmdErrRply:
|
| | | case KLCmdGetPortInfo:
|
| | | *nCount = Datalen;
|
| | | memcpy(pData, pPacket->Datas, Datalen);
|
| | | break;
|
| | | case KLCmdGetPortChildInfo:
|
| | | *nCount = Datalen;
|
| | | memcpy(pData, pPacket->Datas, Datalen);
|
| | | break;
|
| | | case KLCmdGetPortChnInfo:
|
| | | *nCount = Datalen;
|
| | | memcpy(pData, pPacket->Datas, Datalen);
|
| | | break;
|
| | | case KLCmdErrRply:
|
| | | ErrCode = Datalen + 1000;
|
| | | *nCount = 0;
|
| | | return ErrCode;
|
| | | //memcpy(pData, pPacket->Datas, Datalen);
|
| | | break;
|
| | | default:
|
| | | *nCount = Datalen;
|
| | |
| | | }
|
| | |
|
| | |
|
| | | int KLink1::ReadSysCfgData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values)
|
| | | int KLink1::ReadSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * nReadBytes, USHORT * Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadSysCfg, 0, nStartAddr, nByteCount, Values);
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadSysCfg, nType, nStartAddr, nByteCount, Values);
|
| | | CString s1;
|
| | | for (int i = 0; i < len1; i++) {
|
| | | s1.AppendFormat(_T("%02X "), m_Packetbuf[i]);
|
| | |
| | | return res;
|
| | | return KL_OK;
|
| | | }
|
| | | int KLink1::WriteSysCfgData(UCHAR nDst, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values)
|
| | | int KLink1::WriteSysCfgData(UCHAR nDst, UCHAR nType, USHORT nStartAddr, UCHAR nByteCount, USHORT * Values)
|
| | | {
|
| | |
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteSysCfg, 0, nStartAddr, nByteCount, Values);
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteSysCfg, nType, nStartAddr, nByteCount, Values);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int nReadBytes = 0;
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + nReadBytes;
|
| | |
| | |
|
| | | }
|
| | |
|
| | | int KLink1::ReadProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | int KLink1::ReadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | | int res = KL_OK;
|
| | | m_Dst = nDst;
|
| | |
| | | unsigned char nCmd;
|
| | | 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 (res == KL_OK) {
|
| | | unsigned char* values2 = (unsigned char*)Values;
|
| | | for (int i = 0; i < nnCount; i++) values2[i] = m_DataBuf[i];
|
| | | }
|
| | | return res;
|
| | |
|
| | | }
|
| | |
|
| | | int KLink1::StartProgram(UCHAR nDst, UCHAR nType)
|
| | | int KLink1::StartDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgBytes, USHORT nCRC)
|
| | | {
|
| | | int res = KL_OK;
|
| | | m_Dst = nDst;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdStartProgram, nType);
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdStartProgram, nType, nProgBytes,nCRC);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int len2 = RecvPacket(m_RecvBuf, 6);
|
| | | if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6); }
|
| | |
| | |
|
| | | }
|
| | |
|
| | | int KLink1::WriteProgram(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | int KLink1::DownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, USHORT * Values)
|
| | | {
|
| | | int res = KL_OK;
|
| | | m_Dst = nDst;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteProgram, nType, nWordAddr, nWordCount, Values);
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWriteProgram, nType, nByteAddr, nByteCount, Values);
|
| | |
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int len2 = RecvPacket(m_RecvBuf, 6, 10);
|
| | | if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
|
| | | if (len2 <= 0) return KL_ERR;
|
| | | unsigned char nCmd;
|
| | | unsigned short nnCount = 0;
|
| | | res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | | // Values[0] = m_DataBuf[0];
|
| | | return res;
|
| | |
|
| | | }
|
| | |
|
| | | int KLink1::FinishDownloadPLCProgram(UCHAR nDst, UCHAR nType, USHORT nProgSteps, USHORT nCRC)
|
| | | {
|
| | | int res = KL_OK;
|
| | |
|
| | | m_Dst = nDst;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdFinishProgram, nType, nProgSteps,nCRC);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int len2 = RecvPacket(m_RecvBuf, 6,10);
|
| | | if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
|
| | | if (len2 <= 0) return KL_ERR;
|
| | | unsigned char nCmd;
|
| | | unsigned short nnCount = 0;
|
| | | res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | | return res;
|
| | | }
|
| | |
|
| | | int KLink1::ReadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
|
| | | {
|
| | | int res = KL_OK;
|
| | | m_Dst = nDst;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdReadPLCAnno, nType, nByteAddr, nByteCount);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | // int nByteCount = nByteCount;
|
| | | 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 = 0;
|
| | | res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | | if (res == KL_OK) {
|
| | | unsigned char* values2 = (unsigned char*)Values;
|
| | | for (int i = 0; i < nnCount; i++) values2[i] = m_DataBuf[i];
|
| | | }
|
| | | return res;
|
| | |
|
| | | }
|
| | |
|
| | | int KLink1::StartDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nBytes, USHORT nCRC)
|
| | | {
|
| | | int res = KL_OK;
|
| | | m_Dst = nDst;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdStartPLCAnno, nType, nBytes, nCRC);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int len2 = RecvPacket(m_RecvBuf, 6);
|
| | | if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6); }
|
| | | if (len2 <= 0) return KL_ERR;
|
| | | unsigned char nCmd;
|
| | | unsigned short nnCount = 0;
|
| | | res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | | return res;
|
| | |
|
| | | }
|
| | |
|
| | | int KLink1::DownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteAddr, UCHAR nByteCount, UCHAR* Values)
|
| | | {
|
| | | int res = KL_OK;
|
| | | m_Dst = nDst;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdWritePLCAnno, nType, nByteAddr, nByteCount, Values);
|
| | |
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int len2 = RecvPacket(m_RecvBuf, 6);
|
| | |
| | |
|
| | | }
|
| | |
|
| | | int KLink1::FinishProgram(UCHAR nDst, UCHAR nType, USHORT nStepSize)
|
| | | int KLink1::FinishDownloadPLCAnno(UCHAR nDst, UCHAR nType, USHORT nByteSize, USHORT nCRC)
|
| | | {
|
| | | int res = KL_OK;
|
| | |
|
| | | m_Dst = nDst;
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdFinishProgram, nType, nStepSize);
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdFinishPLCAnno, nType, nByteSize, nCRC);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int len2 = RecvPacket(m_RecvBuf, 6);
|
| | | if (len2 <= 0) { len2 = RecvPacket(m_RecvBuf, 6, 30); }
|
| | |
| | | res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | | return res;
|
| | | }
|
| | |
|
| | |
|
| | | int KLink1::ReadRunStat(UCHAR nDst, UCHAR nType, USHORT nWordAddr, UCHAR nWordCount, USHORT * Values)
|
| | | {
|
| | |
| | | return res;
|
| | |
|
| | | }
|
| | |
|
| | | int KLink1::ResetDevice(UCHAR nDst, UCHAR nType)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdResetMachine, nType, 0, 0, 0);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int 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_TIMEOUT;
|
| | | unsigned char nCmd;
|
| | | unsigned short nnCount = 0;
|
| | | int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | | return res;
|
| | | }
|
| | |
|
| | | int KLink1::WriteFirmware(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, KLCmdWriteFirmware, nType, nByteAddr , 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); }
|
| | | m_resultStr.Format(_T("S %d, R %d "), len1, len2);
|
| | | if (len2 <= 0) return KL_TIMEOUT;
|
| | | m_resultStr.Append(_T("\r\n"));
|
| | | for (int j = 0; j < len2; j++) {
|
| | | m_resultStr.AppendFormat(_T("%02X "), m_RecvBuf[j]);
|
| | | }
|
| | | unsigned char nCmd;
|
| | | unsigned short nnCount = 0;
|
| | | int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | | return res;
|
| | | }
|
| | |
|
| | | int KLink1::WriteFirmInfo(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, KLCmdWriteFirmInfo, nType, nByteAddr , 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_TIMEOUT;
|
| | | unsigned char nCmd;
|
| | | unsigned short nnCount = 0;
|
| | | int res = ParseRplyPacket(m_RecvBuf, len2, &nCmd, &m_DstStat.StatByte, &nnCount, m_DataBuf);
|
| | | return res;
|
| | | }
|
| | |
|
| | | int KLink1::GetPortInfo(UCHAR nDst, UCHAR nType, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetPortInfo, nType, 0, 0);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
| | | int 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)
|
| | | {
|
| | | memcpy(Values, m_DataBuf, nnCount);
|
| | | }
|
| | | else
|
| | | {
|
| | | m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
| | | CString s1;
|
| | | s1 = GetErrDescStr(res);
|
| | | m_resultStr += s1;
|
| | | return res;
|
| | | }
|
| | | *nByteRead = nnCount;
|
| | | return KL_OK;
|
| | | }
|
| | |
|
| | | int KLink1::GetPortChildInfo(UCHAR nDst, UCHAR nType, UCHAR nChildId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetPortChildInfo, nType, nChildId, 0);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
| | | int 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)
|
| | | {
|
| | | memcpy(Values, m_DataBuf, nnCount);
|
| | | }
|
| | | else
|
| | | {
|
| | | m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
| | | CString s1;
|
| | | s1 = GetErrDescStr(res);
|
| | | m_resultStr += s1;
|
| | | return res;
|
| | | }
|
| | | *nByteRead = nnCount;
|
| | | return KL_OK;
|
| | | }
|
| | |
|
| | | int KLink1::GetPortChnInfo(UCHAR nDst, UCHAR nType, UCHAR nChnId, UCHAR nByteCount, USHORT* nByteRead, USHORT* Values)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, KLCmdGetPortChnInfo, nType, nChnId, 0);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + nByteCount;
|
| | | int 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)
|
| | | {
|
| | | memcpy(Values, m_DataBuf, nnCount);
|
| | | }
|
| | | else
|
| | | {
|
| | | m_resultStr.AppendFormat(_T("Res=%d ToRead %d Count %d "), res, numToRead, len2);
|
| | | CString s1;
|
| | | s1 = GetErrDescStr(res);
|
| | | m_resultStr += s1;
|
| | | return res;
|
| | | }
|
| | | *nByteRead = nnCount;
|
| | | return KL_OK;
|
| | | }
|
| | |
|
| | | int KLink1::RunRemoteReq(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nReqId, UCHAR nParam,USHORT nByteAddr, UCHAR nByteCount, void * pData)
|
| | | {
|
| | | m_Dst = nDst;
|
| | | m_resultStr.Empty();
|
| | | UCHAR nExpSeq = GetNextSeq();
|
| | | int len1 = MakeRemoteReqPacketEx(m_Packetbuf, nDst, m_Stat1.StatByte, nPort, nChnId, nReqId,nParam,nByteAddr,nByteCount,pData);
|
| | | SendPacket(m_Packetbuf, len1);
|
| | | int numToRead = sizeof(stKLRplyPktHdr) + 0;
|
| | | int 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)
|
| | | {
|
| | | }
|
| | | 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 KLink1::RmoteBlinkLED(UCHAR nDst, UCHAR nPort, UCHAR nChnId, UCHAR nSecond)
|
| | | {
|
| | | return RunRemoteReq(nDst, nPort, nChnId, ReqBlinkLED, nSecond,0,0,0);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|