From 61deef5cdf96cbfdd6ad45be49e80d597c00ca65 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期二, 24 十二月 2024 08:37:21 +0800 Subject: [PATCH] 2024-12-24 --- MTerm1/MTerm1Doc.cpp | 374 ++++++++++++++++++++++++++++++++++------------------- 1 files changed, 241 insertions(+), 133 deletions(-) diff --git a/MTerm1/MTerm1Doc.cpp b/MTerm1/MTerm1Doc.cpp index 79dccd8..0f5cf09 100644 --- a/MTerm1/MTerm1Doc.cpp +++ b/MTerm1/MTerm1Doc.cpp @@ -77,6 +77,7 @@ CMTerm1Doc::stOpDef CMTerm1Doc::OpDef[] = { {OP_NOP,"NOP",0}, + {OP_END,"ED",0}, {OP_ST,"ST",1,KLParamCoil}, {OP_ST_,"ST/",1,KLParamCoil}, {OP_AN,"AN",1,KLParamCoil}, @@ -179,7 +180,7 @@ // callbackfuncs.SendPkgFunc = std::bind(&HvSerialPort::Send, &myHvSerialPort1, std::placeholders::_1, std::placeholders::_2); // callbackfuncs.RecvPkgFunc = std::bind(&HvSerialPort::Recv, &myHvSerialPort1, std::placeholders::_1, std::placeholders::_2); -// MyKLink1.SetCallBackFuncs(&callbackfuncs); +// theApp.MyKLink1.SetCallBackFuncs(&callbackfuncs); // StartTime = myHvSerialPort1.GetTimemS(); } @@ -410,7 +411,7 @@ CFile file1; CFileException e; - bool r = file1.Open(sFilePathName, CFile::modeReadWrite, &e);//璇诲啓妯″紡鎵撳紑鏂囦欢 + bool r = file1.Open(sFilePathName, CFile::modeCreate|CFile::modeReadWrite, &e);//璇诲啓妯″紡鎵撳紑鏂囦欢 if (r) { @@ -418,12 +419,12 @@ CStringA sSectionNameA; //鍐欏叆绯荤粺閰嶇疆 - GetSectionTxt(SectionSysCfg, sSectionNameA); //鑾峰彇绯荤粺閰嶇疆鐨勬枃鏈〃绀� + GetSectionName(SectionSysCfg, sSectionNameA); //鑾峰彇绯荤粺閰嶇疆鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; file1.Write(s1A, s1A.GetLength());//灏嗚幏鍙栧埌鐨勬枃鏈唴瀹瑰啓鍏ユ枃浠� //鍐欏叆绋嬪簭 - GetSectionTxt(SectionProg, sSectionNameA); //鑾峰彇绋嬪簭鐨勬枃鏈〃绀� + GetSectionName(SectionProg, sSectionNameA); //鑾峰彇绋嬪簭鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; file1.Write(s1A, s1A.GetLength());//鑾峰彇鍒扮殑鏂囨湰鍐呭鍐欏叆鏂囦欢 @@ -431,7 +432,7 @@ file1.Write(s1A, s1A.GetLength());//灏嗚浆鎹㈠悗鐨勬枃鏈唴瀹瑰啓鍏ユ枃浠� //鍐欏叆娉ㄩ噴 - GetSectionTxt(SectionAnno, sSectionNameA); //鑾峰彇娉ㄩ噴鐨勬枃鏈〃绀� + GetSectionName(SectionAnno, sSectionNameA); //鑾峰彇娉ㄩ噴鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; file1.Write(s1A, s1A.GetLength()); //寰幆閬嶅巻鎵�鏈夋敞閲婏紝骞跺皢鍏跺啓鍏ユ枃浠� @@ -443,12 +444,12 @@ file1.Write(s1A, s1A.GetLength()); } //鍐欏叆瑙︾偣鐩戞帶鍒楄〃 - GetSectionTxt(SectionCoilList, sSectionNameA); //鑾峰彇瑙︾偣鐩戞帶鍒楄〃鐨勬枃鏈〃绀� + GetSectionName(SectionCoilList, sSectionNameA); //鑾峰彇瑙︾偣鐩戞帶鍒楄〃鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; file1.Write(s1A, s1A.GetLength()); //鍐欏叆鏁版嵁鐩戞帶鍒楄〃 - GetSectionTxt(SectionDataList, sSectionNameA); //鑾峰彇鏁版嵁鐩戞帶鍒楄〃鐨勬枃鏈〃绀� + GetSectionName(SectionDataList, sSectionNameA); //鑾峰彇鏁版嵁鐩戞帶鍒楄〃鐨勬枃鏈〃绀� s1A = "[" + sSectionNameA + "]\r\n"; file1.Write(s1A, s1A.GetLength()); @@ -466,7 +467,7 @@ /// </summary> /// <param name="txt"></param> /// <returns></returns> -int CMTerm1Doc::TxtToSection(CStringA txt) +int CMTerm1Doc::TxtToSectionType(CStringA txt) { for (int i = 0; i < nSectionDefCount; i++) { if (SectionDef[i].SectionName == txt) { @@ -482,7 +483,7 @@ /// <param name="nSectionType"></param> /// <param name="txt"></param> /// <returns></returns> -int CMTerm1Doc::GetSectionTxt(int nSectionType, CStringA & txt) +int CMTerm1Doc::GetSectionName(int nSectionType, CStringA & txt) { for (int i = 0; i < nSectionDefCount; i++) { if (SectionDef[i].nSectionType == nSectionType) { @@ -872,22 +873,23 @@ StackDeeps[i] = nCurStackDeep; } - s1.Format(_T("Remaining STs %d"), nSts); - SysLog(s1); + s1.Format(_T("Remaining STs %d \r\n"), nSts); +// SysLog(s1); for (int i = 0; i < nSts; i++) { - s1.Format(_T("[%d] %d "), i, stpos[i]); - SysLog(s1); + s1.AppendFormat(_T("[%d] %d\t"), i, stpos[i]); } - s1.Format(_T("Pairs")); SysLog(s1); + + s1.Format(_T("Pairs \r\n")); +// SysLog(s1); for (int i = 0; i < m_nProgSteps; i++) { int nPairTo = Progs[i].PairTo; if (nPairTo > 0) { - s1.Format(_T("%d -- %d type:%d"), i, nPairTo, Progs[nPairTo].nOpType1); - SysLog(s1); + s1.AppendFormat(_T("%d - %d type:%d\t"), i, nPairTo, Progs[nPairTo].nOpType1); } } + SysLog(s1); return 0; } int CMTerm1Doc::TransTxtToProg(CStringA ProgTxtA) @@ -904,6 +906,24 @@ TransLinesToProg(txtLines); return 0; +} +int CMTerm1Doc::AnnoToTxt(CStringA & AnnoTxtA) +{ + CString s1; + CStringA s1A; + CStringA sSectionNameA; + + GetSectionName(SectionAnno, sSectionNameA); //鑾峰彇娉ㄩ噴鐨勬枃鏈〃绀� + s1A = "[" + sSectionNameA + "]\r\n"; + //寰幆閬嶅巻鎵�鏈夋敞閲婏紝骞跺皢鍏跺啓鍏ユ枃浠� + for (int i = 0; i < nCoilAnnoCount; i++) + { + if (mCoilAnnos[i].sAnno.IsEmpty()) { continue; } + s1 = mCoilAnnos[i].sCoilName + _T("\t") + mCoilAnnos[i].sAnno + _T("\r\n"); + s1A += s1; + } + AnnoTxtA = s1A; + return AnnoTxtA.GetLength(); } int CMTerm1Doc::ReadAnnoFromTxt(CStringA AnnoTxtA) @@ -923,11 +943,11 @@ nCoilAnnoCount = 0; int nAnnoSectionLine = 0; - int nAnnoStartLine = 0; - int nAnnoLines = 0; + int nAnnoStartLine = 1; + int nAnnoLines = txtLineCount - 1; - int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines); - if (bAnnoSection) { nAnnoStartLine = nAnnoSectionLine + 1; } +// int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines); +// if (bAnnoSection) { nAnnoStartLine = nAnnoSectionLine + 1; } for (int i = nAnnoStartLine; i < nAnnoStartLine + nAnnoLines; i++) { @@ -998,7 +1018,7 @@ CStringA sSectionNameA; sSectionName = sLine.Mid(1, nRightBracket - 1); sSectionNameA = sSectionName; - int theSection = TxtToSection(sSectionNameA); + int theSection = TxtToSectionType(sSectionNameA); s1.Format(_T("+ Line %d Section %d : [%s] type:%d "), i + 1, nSectionCount, sSectionName, theSection); SysLog(s1); @@ -1116,6 +1136,7 @@ //case OP_NOP: break; //鏃犲弬鏁� 鎸囦护 + case OP_END: case OP_NOT: case OP_ANS: case OP_ORS: @@ -1280,6 +1301,7 @@ //case OP_NOP: break; //鏃犲弬鏁� 鎸囦护 + case OP_END: case OP_NOT: case OP_ANS: case OP_ORS: @@ -1504,17 +1526,25 @@ CString s1; if (!m_bOnline) { r = Connect(); - // MyKLink1.Open(); + // theApp.MyKLink1.Open(); } if (!m_bOnline) return; - r = MyKLink1.ReadRunStat(1,0,0,32,(unsigned short *)&MyKLink1.KMRunStat); + r = theApp.MyKLink1.ReadRunStat(1,0,0,32,(unsigned short *)&theApp.MyKLink1.KMRunStat); + + USHORT read; + unsigned short buf1[4096]; + r = theApp.MyKLink1.ReadSysCfgData(1, 0, 0, sizeof(stKMSysCfg), &read, buf1); + pstKMSysCfg pKMSysCfg = (pstKMSysCfg)buf1; + pKMSysCfg->nProgBank; if (r != 0) { - AfxMessageBox(_T("UploadFrom PLC Failed")); + AfxMessageBox(_T("璇诲彇 PLC 淇℃伅澶辫触")); return; } // AfxMessageBox(_T("UploadFrom PLC From Doc")); + CString s2; +/* s2.Format(_T("Cur Programs %d \r\n"), nBinProgSteps); unsigned short * pBinBuf2 = (unsigned short *)BinProgs; for (int i = 0; i < nBinProgSteps * 2; i += 8) { @@ -1525,9 +1555,9 @@ s2 += s1 + _T("\r\n"); } DbgLog(s2); - - int nBinSteps = MyKLink1.KMRunStat.nBinProgSize; - s1.Format(_T("program to upload Size %d "), nBinSteps); +*/ + int nBinSteps = pKMSysCfg->nProgSize; //theApp.MyKLink1.KMRunStat.nBinProgSize; + s1.Format(_T("寮�濮嬩笂杞界▼搴� 澶у皬 %d 姝� "), nBinSteps); DbgLog(s1); USHORT Buf3[2048]; @@ -1536,13 +1566,14 @@ int nSteps = 64; for (int i = 0; i < nUploadSize; i += nSteps) { if (i + nSteps > nUploadSize) { nSteps = nUploadSize - i; } - s1.Format(_T("2 Uploading %d to %d "), i, i + nSteps); - DbgLog(s1); - int r = MyKLink1.ReadProgram(1, 2, i, nSteps*2 , Buf3+i); - s1.Format(_T("Download r = %d "), r); + s1.Format(_T("涓婅浇 %3d to %3d "), i, i + nSteps); +// DbgLog(s1); + int r = theApp.MyKLink1.ReadPLCProgram(1, 2, i, nSteps*2 , Buf3+i); + s1.AppendFormat(_T(" r = %d "), r); DbgLog(s1); //Update Progress Bar } +/* s2.Format(_T(" Uploaded from bank 2 \r\n")); for (int i = 0; i < nBinSteps * 2; i += 8) { s1.Format(_T("%03X: "), i); @@ -1552,13 +1583,43 @@ s2 += s1 + _T("\r\n"); } DbgLog(s2); - +*/ for (int i = 0; i < nBinSteps * 2; i++) { ((USHORT *)BinProgs)[i] = Buf3[i]; } + nBinProgSteps = nBinSteps; TransBinToProg(); + FindProgPair(); + int AnnoSize = pKMSysCfg->nAnnoSize; + if (AnnoSize > 4088) { AnnoSize = 4088; } + s1.Format(_T("寮�濮嬩笂杞芥敞閲� 澶у皬 %d 瀛楄妭"), AnnoSize); + DbgLog(s1); + int nBlockSize = 64; + UCHAR buf5[4096]; + for (int i = 0; i < AnnoSize; i += nBlockSize) + { + if (i + nBlockSize > AnnoSize) { nBlockSize = AnnoSize - i; } + s1.Format(_T("涓婅浇娉ㄩ噴 %3d to %3d "), i, i + nBlockSize); + int r = theApp.MyKLink1.ReadPLCAnno(1, 2, i, nBlockSize, buf5 + i); + s1.AppendFormat(_T(" r = %d \r\n"), r); +// for (int j = 0; j < nBlockSize; j++) { +// s1.AppendFormat(_T("%02X "), buf5[i+ j]); +// } + DbgLog(s1); + } + CStringA s1A; + char * p1 = s1A.GetBufferSetLength(4096); + memcpy(p1, buf5, AnnoSize); + p1[AnnoSize] = 0; + s1A.ReleaseBuffer(); + + s1 = s1A; +// DbgLog(s1); + + ReadAnnoFromTxt(s1A); + UpdateAllViews(NULL); } @@ -1569,7 +1630,7 @@ CString s1; if (!m_bOnline) { r=Connect(); - // MyKLink1.Open(); + // theApp.MyKLink1.Open(); } if (!m_bOnline) return 0; @@ -1582,7 +1643,7 @@ // 涓嬭浇绋嬪簭 s1.Format(_T("Start Download Program ...")); DbgLog(s1); - r = MyKLink1.StartProgram(1,2); + r = theApp.MyKLink1.StartDownloadPLCProgram(1,2,nBinProgSteps * 4); s1.Format(_T("Result = %d"),r); DbgLog(s1); int DownloadSize = nBinProgSteps; @@ -1595,7 +1656,7 @@ do { s1.Format(_T("Downloading %d to %d "), i, i + Steps); DbgLog(s1); - r = MyKLink1.WriteProgram(1, 2, (i) * 4, Steps * 4, (USHORT*)&BinProgs[i]); + r = theApp.MyKLink1.DownloadPLCProgram(1, 2, (i) * 4, Steps * 4, (USHORT*)&BinProgs[i]); s1.Format(_T("Download r = %d "), r); DbgLog(s1); n += 1; @@ -1606,12 +1667,35 @@ s1.Format(_T("Finish Downloading ")); DbgLog(s1); - r = MyKLink1.FinishProgram(1,2,nBinProgSteps); + r = theApp.MyKLink1.FinishDownloadPLCProgram(1,2,nBinProgSteps); s1.Format(_T("Download Finished r = %d "), r); DbgLog(s1); // 涓嬭浇娉ㄩ噴 - - + CStringA AnnoTxtA; + int len3 = AnnoToTxt(AnnoTxtA); + unsigned char buf1[4096]; + if (len3 > 4088) { len3 = 4088; } + memcpy(buf1, AnnoTxtA.GetBuffer(), len3); + AnnoTxtA.ReleaseBuffer(); + s1.Format(_T("寮�濮嬩笅杞芥敞閲� ... %d bytes "),len3); + DbgLog(s1); + s1 = AnnoTxtA; + DbgLog(s1); + r = theApp.MyKLink1.StartDownloadPLCAnno(1, 1, len3); + int nBlockSize = 64; + for (int i = 0; i < len3; i += nBlockSize) { + if (i + nBlockSize > len3) { nBlockSize = len3 - i; } + s1.Format(_T("Downloading %d to %d "), i, i + nBlockSize); + DbgLog(s1); + r = theApp.MyKLink1.DownloadPLCAnno(1, 1,i,nBlockSize,buf1+i); + s1.Format(_T("Download r = %d "), r); + DbgLog(s1); + } + s1.Format(_T("Finish Downloading 娉ㄩ噴")); + DbgLog(s1); + r = theApp.MyKLink1.FinishDownloadPLCAnno(1, 1, len3); + s1.Format(_T("Download Finished r = %d "), r); + DbgLog(s1); // 涓嬭浇绯荤粺瀵勫瓨鍣ㄩ厤缃� //鍚姩杩愯 @@ -1640,7 +1724,7 @@ if (!m_bOnline) { r = Connect(); - //MyKLink1.Open(); + //theApp.MyKLink1.Open(); } if (!m_bOnline) return; // m_bOnline = true; @@ -1660,9 +1744,11 @@ if (m_bOnline) { r = DisConnect(); - MyKLink1.Close(); + theApp.MyKLink1.Close(); } + m_bPlcRunning = false; m_bOnline = false; + UpdateAllViews(NULL, UpdataHint::UpdateStat); } @@ -1670,6 +1756,19 @@ { // TODO: 鍦ㄦ娣诲姞鍛戒护鏇存柊鐢ㄦ埛鐣岄潰澶勭悊绋嬪簭浠g爜 pCmdUI->SetCheck(m_bOnline == false); +// pCmdUI->SetCheck(false); +} +void CMTerm1Doc::OnUpdateSimulate(CCmdUI* pCmdUI) +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护鏇存柊鐢ㄦ埛鐣岄潰澶勭悊绋嬪簭浠g爜 + pCmdUI->SetCheck(m_bSimulate == true); +} +void CMTerm1Doc::OnUpdatePlcRun(CCmdUI* pCmdUI) +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护鏇存柊鐢ㄦ埛鐣岄潰澶勭悊绋嬪簭浠g爜 + pCmdUI->SetCheck(m_bPlcRunning == true); + if (!m_bPlcRunning) pCmdUI->SetText(_T("PLC妯″紡[PROG]")); + else pCmdUI->SetText(_T("PLC妯″紡[RUN]")); } void CMTerm1Doc::OnSimulate() @@ -1705,12 +1804,6 @@ UpdateAllViews(NULL, UpdataHint::UpdateStat); } -void CMTerm1Doc::OnUpdateSimulate(CCmdUI *pCmdUI) -{ - // TODO: 鍦ㄦ娣诲姞鍛戒护鏇存柊鐢ㄦ埛鐣岄潰澶勭悊绋嬪簭浠g爜 - pCmdUI->SetCheck(m_bSimulate == true); -} - int CMTerm1Doc::StartPLC() { // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. @@ -1730,10 +1823,11 @@ for (int i = 0; i < TOTALTIMERS; i++) { KMem.Timers[i] = { 0 }; } + myKMachine1.nScanCount = 0; nScanCount = 0; m_bPlcRunning = 1; }else { - MyKLink1.ChangeMode(1, 1); + theApp.MyKLink1.ChangeMode(1, 1); m_bPlcRunning = 1; } return 0; @@ -1747,7 +1841,7 @@ m_bPlcRunning = false; } else { - MyKLink1.ChangeMode(1, 0); + theApp.MyKLink1.ChangeMode(1, 0); m_bPlcRunning = false; } @@ -1765,22 +1859,13 @@ UpdateAllViews(NULL, UpdataHint::UpdateStat); } -void CMTerm1Doc::OnUpdatePlcRun(CCmdUI *pCmdUI) -{ - // TODO: 鍦ㄦ娣诲姞鍛戒护鏇存柊鐢ㄦ埛鐣岄潰澶勭悊绋嬪簭浠g爜 - pCmdUI->SetCheck(m_bPlcRunning == true); - if (!m_bPlcRunning) pCmdUI->SetText(_T("PLC妯″紡[PROG]")); - else pCmdUI->SetText(_T("PLC妯″紡[RUN]")); -} - - int CMTerm1Doc::SetCommParam() { // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. CString s1; s1.Format(_T("Doc SetupComm")); SysLog(s1); - MyKLink1.SetCommParam(); + theApp.MyKLink1.SetCommParam(); return 0; /* CDialogCommSet1 dialog1; @@ -1808,9 +1893,9 @@ // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. CString s1; unsigned short buf1[32]; - int res = MyKLink1.Connect(); + int res = theApp.MyKLink1.Connect(); unsigned short len1; - int j=MyKLink1.GetInfo(1, &len1, buf1); + int j=theApp.MyKLink1.GetInfo(1, &len1, buf1); s1.Format(_T("GetInfo = %d %d \r\n"), j,len1); if (j==0 && len1 > 0) { for (int i = 0; i < len1/2; i++) { @@ -1819,19 +1904,19 @@ s1 += _T("\r\n"); pKMInfoBlock pinfob = (pKMInfoBlock)buf1; - s1.AppendFormat(_T(" DeviceType %04X \r\n"),pinfob->nDeviceTypeVer); + s1.AppendFormat(_T(" DeviceType %04X \t "),pinfob->nDeviceTypeVer); s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer); - s1.AppendFormat(_T(" nKLinkVer %04X \r\n"), pinfob->nKLinkVer); + s1.AppendFormat(_T(" nKLinkVer %04X \t"), pinfob->nKLinkVer); s1.AppendFormat(_T(" nKBusVer %04X \r\n"), pinfob->nKBusVer); - s1.AppendFormat(_T(" nCapacity1 %d k\r\n"), pinfob->nCapacity1); + s1.AppendFormat(_T(" nCapacity1 %d k \t"), pinfob->nCapacity1); s1.AppendFormat(_T(" nCapacity2 %d k\r\n"), pinfob->nCapacity2); - s1.AppendFormat(_T(" nDInput %d \r\n"), pinfob->nDInput); + s1.AppendFormat(_T(" nDInput %d \t"), pinfob->nDInput); s1.AppendFormat(_T(" nDOutput %d \r\n"), pinfob->nDOutput); - s1.AppendFormat(_T(" nAInput %d \r\n"), pinfob->nAInput); + s1.AppendFormat(_T(" nAInput %d \t"), pinfob->nAInput); s1.AppendFormat(_T(" nAOutput %d \r\n"), pinfob->nAOutput); - s1.AppendFormat(_T(" nHInput %d \r\n"), pinfob->nHInput); + s1.AppendFormat(_T(" nHInput %d \t"), pinfob->nHInput); s1.AppendFormat(_T(" nHOutput %d \r\n"), pinfob->nHOutput); - s1.AppendFormat(_T(" nExt1 %d \r\n"), pinfob->nExt1); + s1.AppendFormat(_T(" nExt1 %d \t"), pinfob->nExt1); s1.AppendFormat(_T(" nExt2 %d \r\n"), pinfob->nExt2); s1.AppendFormat(_T(" nLogSize %d \r\n"), pinfob->nLogSize); s1.AppendFormat(_T(" nPorts %d \r\n"), pinfob->nPorts); @@ -1841,31 +1926,32 @@ } SysLog(s1); - int r = MyKLink1.ReadRunStat(1, 0, 0, 32, (unsigned short*)&MyKLink1.KMRunStat); + int r = theApp.MyKLink1.ReadRunStat(1, 0, 0, 32, (unsigned short*)&theApp.MyKLink1.KMRunStat); s1.Format(_T("GetRunStat = %d %d \r\n"), r, 32); - KLink1::stRunStat RunStat1 = MyKLink1.KMRunStat; + KLink1::stRunStat RunStat1 = theApp.MyKLink1.KMRunStat; - s1.AppendFormat(_T(" Sign1 %04X \r\n"), RunStat1.Sign1); + s1.AppendFormat(_T(" Sign1 %04X \t"), RunStat1.Sign1); s1.AppendFormat(_T(" Seq1 %d \r\n"), RunStat1.Seq1); s1.AppendFormat(_T(" PowerCount %d \r\n"), RunStat1.PowerCount); s1.AppendFormat(_T(" Reserved1 %d \r\n"), RunStat1.Reserved1); s1.AppendFormat(_T(" UpTime %d \r\n"), RunStat1.UpTime); s1.AppendFormat(_T(" UserData1 %d \r\n"), RunStat1.UserData1); - s1.AppendFormat(_T(" WorkMode %d \r\n"), RunStat1.WorkMode); + s1.AppendFormat(_T(" WorkMode %d \t"), RunStat1.WorkMode); s1.AppendFormat(_T(" WorkMode2 %d \r\n"), RunStat1.WorkMode2); - s1.AppendFormat(_T(" nBinProgBank %d \r\n"), RunStat1.nBinProgBank); + s1.AppendFormat(_T(" nBinProgBank %d \t"), RunStat1.nBinProgBank); s1.AppendFormat(_T(" nBinProgSize %d \r\n"), RunStat1.nBinProgSize); s1.AppendFormat(_T(" bLEDFlick %d \r\n"), RunStat1.bLEDFlick); s1.AppendFormat(_T(" Reserved2 %d \r\n"), RunStat1.Reserved2); s1.AppendFormat(_T(" CRC1 %04X \r\n"), RunStat1.CRC1); s1.AppendFormat(_T(" EndSign1 %04X \r\n"), RunStat1.EndSign1); + SysLog(s1); unsigned char value; - r = MyKLink1.GetMode(1, 0, &value); + r = theApp.MyKLink1.GetMode(1, 0, &value); if (r == KLink1::KL_OK) { m_bPlcRunning = value; } - - + s1.Format(_T("PLC Mode = %d"), value); SysLog(s1); + // m_static_connect.SetCtlColor(RGB(0, 255, 0)); /* if (!m_bCommParamSet) @@ -1883,7 +1969,7 @@ if (r == myHvSerialPort1.R_OK) { m_bOnline = true; -// MyKLink1.Open(); +// theApp.MyKLink1.Open(); // m_static_connect.SetCtlColor(RGB(0, 255, 0)); return 0; } @@ -1897,8 +1983,9 @@ // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. if (!m_bOnline) return -1; // myHvSerialPort1.Close(); - MyKLink1.Close(); + theApp.MyKLink1.Close(); m_bOnline = false; + m_bPlcRunning = false; return 0; } @@ -2037,6 +2124,7 @@ void CMTerm1Doc::OnMenuCommTest() { // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 +/* CString s1; CView * pView; pView = FindView(RUNTIME_CLASS(CMTerm1CommDevView)); @@ -2052,6 +2140,7 @@ ASSERT_KINDOF(CFrameWnd, pFrame); theApp.m_pCommDevViewTemplate->InitialUpdateFrame(pFrame, this); } +*/ } @@ -2090,7 +2179,7 @@ if (m_bOnline && 0) { unsigned char value = 0; - MyKLink1.ReadBit(1, nCoilType, nCoilAddr, &value); + theApp.MyKLink1.ReadBit(1, nCoilType, nCoilAddr, &value); return value; } int nWordAddr = nCoilAddr >> 4; @@ -2149,7 +2238,7 @@ { unsigned char value =nCoilValue; int res = 0; - res = MyKLink1.WriteBit(1, nCoilType, nCoilAddr, value); + res = theApp.MyKLink1.WriteBit(1, nCoilType, nCoilAddr, value); return res; } @@ -2198,7 +2287,7 @@ } if (m_bOnline) { -// MyKLink1.WriteBit(1, nCoilType, nCoilAddr, nCoilValue); +// theApp.MyKLink1.WriteBit(1, nCoilType, nCoilAddr, nCoilValue); } return 0; } @@ -2215,7 +2304,7 @@ return nDataAddr; } - MyKLink1.ReadDataWord(1, nDataType, nDataAddr, 2, &nCount, value);// (unsigned char *)&KMem.DT[nDataAddr]); + theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, 2, &nCount, value);// (unsigned char *)&KMem.DT[nDataAddr]); svalue = value[0]; return svalue; } @@ -2300,7 +2389,7 @@ unsigned short svalue[10]; svalue[0]=nDataValue; int res = 0; - res = MyKLink1.WriteDataWord(1, nDataType, nDataAddr, 2, svalue); + res = theApp.MyKLink1.WriteDataWord(1, nDataType, nDataAddr, 2, svalue); return res; } @@ -2398,7 +2487,7 @@ // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. CString s1; if (m_bSimulate) { - int nDataType = MyKLink1.KLDataTypeWX; + int nDataType = theApp.MyKLink1.KLDataTypeWX; int nDataAddr = 0; int nDataCount = 4; // int res; @@ -2406,129 +2495,148 @@ KMem.WX[i] = myKMachine1.KMem.WX[i]; } - nDataType = MyKLink1.KLDataTypeWY; + nDataType = theApp.MyKLink1.KLDataTypeWY; nDataAddr = 0; nDataCount = 4; for (int i = 0; i < nDataCount; i++) { KMem.WY[i] = myKMachine1.KMem.WY[i]; } - nDataType = MyKLink1.KLDataTypeWLX; + nDataType = theApp.MyKLink1.KLDataTypeWLX; nDataAddr = 0; nDataCount = 4; for (int i = 0; i < nDataCount; i++) { KMem.WLX[i] = myKMachine1.KMem.WLX[i]; } - nDataType = MyKLink1.KLDataTypeWLY; + nDataType = theApp.MyKLink1.KLDataTypeWLY; nDataAddr = 0; nDataCount = 4; for (int i = 0; i < nDataCount; i++) { KMem.WLY[i] = myKMachine1.KMem.WLY[i]; } - nDataType = MyKLink1.KLDataTypeWR; + nDataType = theApp.MyKLink1.KLDataTypeWR; nDataAddr = 0; nDataCount = 10; for (int i = 0; i < nDataCount; i++) { KMem.WR[i] = myKMachine1.KMem.WR[i]; } - nDataType = MyKLink1.KLDataTypeDT; + nDataType = theApp.MyKLink1.KLDataTypeDT; nDataAddr = 0; - nDataCount = 80; + nDataCount = 128; for (int i = 0; i < nDataCount; i++) { KMem.DT[i] = myKMachine1.KMem.DT[i]; } - nDataType = MyKLink1.KLDataTypeSV; + nDataType = theApp.MyKLink1.KLDataTypeSV; nDataAddr = 0; nDataCount = 40; for (int i = 0; i < nDataCount; i++) { KMem.SV[i] = myKMachine1.KMem.SV[i]; } - //res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]); + //res = theApp.MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]); - nDataType = MyKLink1.KLDataTypeEV; + nDataType = theApp.MyKLink1.KLDataTypeEV; nDataAddr = 0; nDataCount = 40; for (int i = 0; i < nDataCount; i++) { KMem.EV[i] = myKMachine1.KMem.EV[i]; } -// res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]); +// res = theApp.MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]); }else if (m_bOnline) { - int nDataType = MyKLink1.KLDataTypeWX; + if (theApp.MyKLink1.m_nContinueErrCount > 10) { + DisConnect(); + } + int nDataType = theApp.MyKLink1.KLDataTypeWX; int nDataAddr = 0; - int nDataCount = 4; + int nDataCount = 16; unsigned short nCount; int res; - res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]); - if (res != MyKLink1.KL_OK) { - s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); SysLog(s1); } - nDataType = MyKLink1.KLDataTypeWY; + nDataType = theApp.MyKLink1.KLDataTypeWY; nDataAddr = 0; - nDataCount = 4; - res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]); - if (res != MyKLink1.KL_OK) { - s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + nDataCount = 16; + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); SysLog(s1); } - nDataType = MyKLink1.KLDataTypeWLX; + nDataType = theApp.MyKLink1.KLDataTypeWLX; nDataAddr = 0; - nDataCount = 4; - res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLX);// (unsigned char *)&KMem.DT[nDataAddr]); - if (res != MyKLink1.KL_OK) { - s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + nDataCount = 8; + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLX);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); SysLog(s1); } - nDataType = MyKLink1.KLDataTypeWLY; + nDataType = theApp.MyKLink1.KLDataTypeWLY; nDataAddr = 0; - nDataCount = 4; - res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLY);// (unsigned char *)&KMem.DT[nDataAddr]); - if (res != MyKLink1.KL_OK) { - s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + nDataCount = 8; + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WLY);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); SysLog(s1); } - nDataType = MyKLink1.KLDataTypeWR; + nDataType = theApp.MyKLink1.KLDataTypeWR; + nDataAddr = 0; + nDataCount = 16; + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); + SysLog(s1); + } + nDataType = theApp.MyKLink1.KLDataTypeWSR; nDataAddr = 0; nDataCount = 10; - res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]); - if (res != MyKLink1.KL_OK) { - s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.WSR);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); SysLog(s1); } - nDataType = MyKLink1.KLDataTypeDT; + nDataType = theApp.MyKLink1.KLDataTypeDT; nDataAddr = 0; - nDataCount = 80; - res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]); - if (res != MyKLink1.KL_OK) { - s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + nDataCount = 64; + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); SysLog(s1); } - nDataType = MyKLink1.KLDataTypeSV; - nDataAddr = 0; - nDataCount = 40; - res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]); - if (res != MyKLink1.KL_OK) { - s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + nDataAddr = 64; + nDataCount = 64; + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, &KMem.DT[64]);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); SysLog(s1); } - nDataType = MyKLink1.KLDataTypeEV; + + nDataType = theApp.MyKLink1.KLDataTypeSV; nDataAddr = 0; - nDataCount = 40; - res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]); - if (res != MyKLink1.KL_OK) { - s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + nDataCount = 64; + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); + SysLog(s1); + } + nDataType = theApp.MyKLink1.KLDataTypeEV; + nDataAddr = 0; + nDataCount = 64; + res = theApp.MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, &nCount, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != theApp.MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, theApp.MyKLink1.m_resultStr); SysLog(s1); } } -- Gitblit v1.9.1