| | |
| | | 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},
|
| | |
| | | // 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();
|
| | | }
|
| | |
| | | CFile file1;
|
| | | CFileException e;
|
| | |
|
| | | bool r = file1.Open(sFilePathName, CFile::modeReadWrite, &e);//读写模式打开文件
|
| | | bool r = file1.Open(sFilePathName, CFile::modeCreate|CFile::modeReadWrite, &e);//读写模式打开文件
|
| | | if (r)
|
| | | {
|
| | |
|
| | |
| | | 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());//获取到的文本内容写入文件
|
| | |
|
| | |
| | | file1.Write(s1A, s1A.GetLength());//将转换后的文本内容写入文件
|
| | |
|
| | | //写入注释
|
| | | GetSectionTxt(SectionAnno, sSectionNameA); //获取注释的文本表示
|
| | | GetSectionName(SectionAnno, sSectionNameA); //获取注释的文本表示
|
| | | s1A = "[" + sSectionNameA + "]\r\n";
|
| | | file1.Write(s1A, s1A.GetLength());
|
| | | //循环遍历所有注释,并将其写入文件
|
| | |
| | | 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());
|
| | |
|
| | |
| | | /// </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) {
|
| | |
| | | /// <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) {
|
| | |
| | | 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)
|
| | |
| | | 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)
|
| | |
| | |
|
| | | 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++)
|
| | | {
|
| | |
| | | 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);
|
| | |
| | | //case OP_NOP:
|
| | | break;
|
| | | //无参数 指令
|
| | | case OP_END:
|
| | | case OP_NOT:
|
| | | case OP_ANS:
|
| | | case OP_ORS:
|
| | |
| | | //case OP_NOP:
|
| | | break;
|
| | | //无参数 指令
|
| | | case OP_END:
|
| | | case OP_NOT:
|
| | | case OP_ANS:
|
| | | case OP_ORS:
|
| | |
| | | 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) {
|
| | |
| | | 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];
|
| | |
| | | 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);
|
| | |
| | | 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);
|
| | | }
|
| | |
|
| | |
| | | CString s1;
|
| | | if (!m_bOnline) {
|
| | | r=Connect();
|
| | | // MyKLink1.Open();
|
| | | // theApp.MyKLink1.Open();
|
| | | }
|
| | | if (!m_bOnline) return 0;
|
| | |
|
| | |
| | | // 下载程序
|
| | | 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;
|
| | |
| | | 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;
|
| | |
| | |
|
| | | 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);
|
| | | // 下载系统寄存器配置
|
| | |
|
| | | //启动运行
|
| | |
| | | if (!m_bOnline)
|
| | | {
|
| | | r = Connect();
|
| | | //MyKLink1.Open();
|
| | | //theApp.MyKLink1.Open();
|
| | | }
|
| | | if (!m_bOnline) return;
|
| | | // m_bOnline = true;
|
| | |
| | | if (m_bOnline)
|
| | | {
|
| | | r = DisConnect();
|
| | | MyKLink1.Close();
|
| | | theApp.MyKLink1.Close();
|
| | | }
|
| | | m_bPlcRunning = false;
|
| | | m_bOnline = false;
|
| | | |
| | | UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | // TODO: 在此添加命令更新用户界面处理程序代码
|
| | | pCmdUI->SetCheck(m_bOnline == false);
|
| | | // pCmdUI->SetCheck(false);
|
| | | }
|
| | | void CMTerm1Doc::OnUpdateSimulate(CCmdUI* pCmdUI)
|
| | | {
|
| | | // TODO: 在此添加命令更新用户界面处理程序代码
|
| | | pCmdUI->SetCheck(m_bSimulate == true);
|
| | | }
|
| | | void CMTerm1Doc::OnUpdatePlcRun(CCmdUI* pCmdUI)
|
| | | {
|
| | | // TODO: 在此添加命令更新用户界面处理程序代码
|
| | | pCmdUI->SetCheck(m_bPlcRunning == true);
|
| | | if (!m_bPlcRunning) pCmdUI->SetText(_T("PLC模式[PROG]"));
|
| | | else pCmdUI->SetText(_T("PLC模式[RUN]"));
|
| | | }
|
| | |
|
| | | void CMTerm1Doc::OnSimulate()
|
| | |
| | | UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
| | | }
|
| | |
|
| | | void CMTerm1Doc::OnUpdateSimulate(CCmdUI *pCmdUI)
|
| | | {
|
| | | // TODO: 在此添加命令更新用户界面处理程序代码
|
| | | pCmdUI->SetCheck(m_bSimulate == true);
|
| | | }
|
| | |
|
| | | int CMTerm1Doc::StartPLC()
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
| | | 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;
|
| | |
| | | m_bPlcRunning = false;
|
| | | }
|
| | | else {
|
| | | MyKLink1.ChangeMode(1, 0);
|
| | | theApp.MyKLink1.ChangeMode(1, 0);
|
| | | m_bPlcRunning = false;
|
| | | }
|
| | |
|
| | |
| | | UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
| | | }
|
| | |
|
| | | void CMTerm1Doc::OnUpdatePlcRun(CCmdUI *pCmdUI)
|
| | | {
|
| | | // TODO: 在此添加命令更新用户界面处理程序代码
|
| | | 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;
|
| | |
| | | // 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++) {
|
| | |
| | | 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);
|
| | |
| | |
|
| | | }
|
| | | 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)
|
| | |
| | | if (r == myHvSerialPort1.R_OK)
|
| | | {
|
| | | m_bOnline = true;
|
| | | // MyKLink1.Open();
|
| | | // theApp.MyKLink1.Open();
|
| | | // m_static_connect.SetCtlColor(RGB(0, 255, 0));
|
| | | return 0;
|
| | | }
|
| | |
| | | // TODO: 在此处添加实现代码.
|
| | | if (!m_bOnline) return -1;
|
| | | // myHvSerialPort1.Close();
|
| | | MyKLink1.Close();
|
| | | theApp.MyKLink1.Close();
|
| | | m_bOnline = false;
|
| | | m_bPlcRunning = false;
|
| | | return 0;
|
| | | }
|
| | |
|
| | |
| | | void CMTerm1Doc::OnMenuCommTest()
|
| | | {
|
| | | // TODO: 在此添加命令处理程序代码
|
| | | /*
|
| | | CString s1;
|
| | | CView * pView;
|
| | | pView = FindView(RUNTIME_CLASS(CMTerm1CommDevView));
|
| | |
| | | ASSERT_KINDOF(CFrameWnd, pFrame);
|
| | | theApp.m_pCommDevViewTemplate->InitialUpdateFrame(pFrame, this);
|
| | | }
|
| | | */
|
| | |
|
| | | }
|
| | |
|
| | |
| | | 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;
|
| | |
| | | {
|
| | | unsigned char value =nCoilValue;
|
| | | int res = 0;
|
| | | res = MyKLink1.WriteBit(1, nCoilType, nCoilAddr, value);
|
| | | res = theApp.MyKLink1.WriteBit(1, nCoilType, nCoilAddr, value);
|
| | | return res;
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | if (m_bOnline)
|
| | | {
|
| | | // MyKLink1.WriteBit(1, nCoilType, nCoilAddr, nCoilValue);
|
| | | // theApp.MyKLink1.WriteBit(1, nCoilType, nCoilAddr, nCoilValue);
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
| | | 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;
|
| | | }
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | |
| | | // TODO: 在此处添加实现代码.
|
| | | CString s1;
|
| | | if (m_bSimulate) {
|
| | | int nDataType = MyKLink1.KLDataTypeWX;
|
| | | int nDataType = theApp.MyKLink1.KLDataTypeWX;
|
| | | int nDataAddr = 0;
|
| | | int nDataCount = 4;
|
| | | // int res;
|
| | |
| | | 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);
|
| | | }
|
| | | }
|