| | |
| | | {KLCoilTypeSR,"SR"},
|
| | | {KLCoilTypeC,"C"},
|
| | | {KLCoilTypeT,"T"},
|
| | | {KLCoilTypeP,"P"},
|
| | | {KLCoilTypeE,"E"},
|
| | | };
|
| | | int CMTerm1Doc::nCoilTypeDefCount = sizeof(CMTerm1Doc::CoilTypeNameDef) / sizeof(stTypeNameDef);
|
| | |
|
| | |
| | | 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();
|
| | | }
|
| | |
| | | }
|
| | | */
|
| | |
|
| | | /// <summary>
|
| | | /// 处理新文档的创建事件
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | BOOL CMTerm1Doc::OnNewDocument()
|
| | | {
|
| | | if (!CDocument::OnNewDocument())
|
| | | {
|
| | | return FALSE;
|
| | |
|
| | | }
|
| | |
|
| | | // TODO: 在此添加重新初始化代码
|
| | | // (SDI 文档将重用该文档)
|
| | | // LoadFromFile(_T("0prog1.txt"));
|
| | | //LoadFromFile(_T("0prog1.txt"));
|
| | | return TRUE;
|
| | | |
| | |
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 处理打开的文档
|
| | | /// </summary>
|
| | | /// <param name="lpszPathName">指向要打开的文件路径的指针</param>
|
| | | /// <returns></returns>
|
| | | BOOL CMTerm1Doc::OnOpenDocument(LPCTSTR lpszPathName)
|
| | | {
|
| | | // if (!CDocument::OnOpenDocument(lpszPathName))
|
| | | // return FALSE;
|
| | |
|
| | | // TODO: 在此添加您专用的创建代码
|
| | | CString s1;
|
| | | CString s1;//日志信息
|
| | | s1.Format(_T("OnOpenDocument %s"), lpszPathName);
|
| | | SysLog(s1);
|
| | |
|
| | | //加载文件内容
|
| | | LoadFromFile(lpszPathName);
|
| | | return TRUE;
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 处理保存文档的事件
|
| | | /// </summary>
|
| | | /// <param name="lpszPathName">指向要打开的文件路径的指针</param>
|
| | | /// <returns></returns>
|
| | | BOOL CMTerm1Doc::OnSaveDocument(LPCTSTR lpszPathName)
|
| | | {
|
| | | // TODO: 在此添加专用代码和/或调用基类
|
| | | CString s1;
|
| | | s1.Format(_T("OnSaveDocument %s"), lpszPathName);
|
| | | SysLog(s1);
|
| | | SaveToFile(lpszPathName);
|
| | | return TRUE;
|
| | |
|
| | | //0912-zxd-Modify
|
| | | int result = SaveToFile(lpszPathName);
|
| | | return result == 1 ? TRUE : FALSE;
|
| | | // return CDocument::OnSaveDocument(lpszPathName);
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 处理关闭文档的事件
|
| | | /// </summary>
|
| | | void CMTerm1Doc::OnCloseDocument()
|
| | | {
|
| | | // TODO: 在此添加专用代码和/或调用基类
|
| | |
| | | CDocument::OnCloseDocument();
|
| | | }
|
| | |
|
| | | // CMTerm1Doc 序列化
|
| | |
|
| | | /// <summary>
|
| | | /// CMTerm1Doc 序列化
|
| | | /// </summary>
|
| | | /// <param name="ar"></param>
|
| | | void CMTerm1Doc::Serialize(CArchive& ar)
|
| | | {
|
| | | CString s1;
|
| | |
| | | SetSearchContent(strSearchContent);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置文档的搜索内容
|
| | | /// </summary>
|
| | | /// <param name="value">要搜索内容的字符串值</param>
|
| | | void CMTerm1Doc::SetSearchContent(const CString& value)
|
| | | {
|
| | | if (value.IsEmpty())
|
| | |
| | | // CMTerm1Doc 诊断
|
| | |
|
| | | #ifdef _DEBUG
|
| | | /// <summary>
|
| | | /// 验证对象的有效性
|
| | | /// </summary>
|
| | | void CMTerm1Doc::AssertValid() const
|
| | | {
|
| | | CDocument::AssertValid();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 诊断信息的输出
|
| | | /// </summary>
|
| | | /// <param name="dc"></param>
|
| | | void CMTerm1Doc::Dump(CDumpContext& dc) const
|
| | | {
|
| | | CDocument::Dump(dc);
|
| | |
| | | #endif //_DEBUG
|
| | |
|
| | |
|
| | | // CMTerm1Doc 命令
|
| | | /// <summary>
|
| | | /// 加载指定的文件
|
| | | /// </summary>
|
| | | /// <param name="sFilePathName">需要加载的文件的路径名</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::LoadFromFile(CString sFilePathName)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | | CFile file1;
|
| | | CFile file1;//打开指定的文件
|
| | | CFileException e;
|
| | | bool r = file1.Open(sFilePathName, CFile::modeRead, &e);
|
| | | if (r)
|
| | |
| | | file1.Read(s1A.GetBuffer(l + 2048), l);
|
| | | file1.Close();
|
| | | s1A.ReleaseBuffer(l);
|
| | | TransFileToProg(s1A);
|
| | | UpdateAllViews(NULL);
|
| | |
|
| | | TransFileToProg(s1A);//文件内容转换为Prog格式
|
| | | UpdateAllViews(NULL);//更新所有的视图,以反映新加载的内容
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 保存文件
|
| | | /// </summary>
|
| | | /// <param name="sFilePathName">需要保存的文件的路径名</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::SaveToFile(CString sFilePathName)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | | CString s1;
|
| | | 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 s1A;
|
| | | CStringA sSectionNameA;
|
| | |
|
| | | //写入系统配置
|
| | | GetSectionTxt(SectionSysCfg, sSectionNameA); //
|
| | | GetSectionName(SectionSysCfg, sSectionNameA); //获取系统配置的文本表示
|
| | | s1A = "[" + sSectionNameA + "]\r\n";
|
| | | file1.Write(s1A, s1A.GetLength());
|
| | | 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());//获取到的文本内容写入文件
|
| | |
|
| | | TransToTxt(s1A);
|
| | | file1.Write(s1A, s1A.GetLength());
|
| | | TransToTxt(s1A);//将程序内容转换为文本格式
|
| | | file1.Write(s1A, s1A.GetLength());//将转换后的文本内容写入文件
|
| | |
|
| | | //写入注释
|
| | | GetSectionTxt(SectionAnno, sSectionNameA); //
|
| | | GetSectionName(SectionAnno, sSectionNameA); //获取注释的文本表示
|
| | | s1A = "[" + sSectionNameA + "]\r\n";
|
| | | file1.Write(s1A, s1A.GetLength());
|
| | | //循环遍历所有注释,并将其写入文件
|
| | | 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");
|
| | | s1 = mCoilAnnos[i].sCoilName + _T("\t") + mCoilAnnos[i].sAnno + _T("\r\n");
|
| | | s1A = s1;
|
| | | 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());
|
| | |
|
| | | file1.Close();
|
| | | return 1;
|
| | | }
|
| | | return 0;
|
| | | else//文件打开失败
|
| | | {
|
| | | return 0;
|
| | | }
|
| | | }
|
| | |
|
| | | int CMTerm1Doc::TxtToSection(CStringA txt)
|
| | | /// <summary>
|
| | | /// 根据文本匹配类型的Key并返回
|
| | | /// </summary>
|
| | | /// <param name="txt"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::TxtToSectionType(CStringA txt)
|
| | | {
|
| | | for (int i = 0; i < nSectionDefCount; i++) {
|
| | | if (SectionDef[i].SectionName == txt) {
|
| | |
| | | return SectionNone;
|
| | | }
|
| | |
|
| | | int CMTerm1Doc::GetSectionTxt(int nSectionType, CStringA & txt)
|
| | | /// <summary>
|
| | | /// 根据Key匹配类型的文本,通过txt传递,返回查询执行结果
|
| | | /// </summary>
|
| | | /// <param name="nSectionType"></param>
|
| | | /// <param name="txt"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::GetSectionName(int nSectionType, CStringA & txt)
|
| | | {
|
| | | for (int i = 0; i < nSectionDefCount; i++) {
|
| | | if (SectionDef[i].nSectionType == nSectionType) {
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// |
| | | /// </summary>
|
| | | /// <param name="nSectionType">Section类型</param>
|
| | | /// <param name="nSectionLine">行号</param>
|
| | | /// <param name="nSectionLines">行数</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::GetSectionPos(int nSectionType, int * nSectionLine, int * nSectionLines)
|
| | | {
|
| | | for (int i = 0; i < nSectionCount; i++) {
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 文本表示的操作转换为其相应的操作类型、参数数量和参数类型
|
| | | /// </summary>
|
| | | /// <param name="optxt">表示操作的字符串</param>
|
| | | /// <param name="ParamCount">返回与给定操作相对应的参数数量</param>
|
| | | /// <param name="ParamType">返回与给定操作相对应的参数类型</param>
|
| | | /// <returns>-1:匹配失败</returns>
|
| | | int CMTerm1Doc::TxtToOp(CStringA optxt, int* ParamCount, int* ParamType)
|
| | | {
|
| | | for (int i = 0; i < nOpDefCount; i++){
|
| | |
| | | }
|
| | | return -1;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 操作类型转换为其相应的文本表示
|
| | | /// </summary>
|
| | | /// <param name="nOp">操作类型</param>
|
| | | /// <param name="OpTxt">操作文本</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::OpToTxt(int nOp, CStringA & OpTxt)
|
| | | {
|
| | | for (int i = 0; i < nOpDefCount; i++){
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 操作类型转换为其相应的前台展示文本
|
| | | /// </summary>
|
| | | /// <param name="nOp">操作类型</param>
|
| | | /// <param name="OpShowTxt">前台展示文本</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::OpToShowTxt(int nOp, CStringA & OpShowTxt)
|
| | | {
|
| | | for (int i = 0; i < nOpDefCount; i++) {
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 文本转线圈类型
|
| | | /// </summary>
|
| | | /// <param name="Typetxt">线圈类型</param>
|
| | | /// <param name="nCoilType">线圈类型</param>
|
| | | /// <param name="nCoilAddr">线圈地址</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::TxtToCoilType(CStringA Typetxt, int* nCoilType, int* nCoilAddr)
|
| | | {
|
| | | Typetxt.MakeUpper();
|
| | |
| | | if (Typetxt.Find( CoilTypeNameDef[i].TypeTxt)==0) {
|
| | | *nCoilType = CoilTypeNameDef[i].nType;
|
| | | *nCoilAddr = atoi(Typetxt.Mid(CoilTypeNameDef[i].TypeTxt.GetLength()));
|
| | | return true;
|
| | | return CoilTypeNameDef[i].nType;
|
| | | }
|
| | | }
|
| | | return false;;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 线圈类型转文本
|
| | | /// </summary>
|
| | | /// <param name="nType">线圈类型</param>
|
| | | /// <param name="typeTxt">线圈文本</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::CoilTypeToTxt(int nType, CStringA & typeTxt)
|
| | | {
|
| | | for (int i = 0; i < nCoilTypeDefCount; i++)
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// |
| | | /// </summary>
|
| | | /// <param name="Typetxt"></param>
|
| | | /// <param name="nDataType"></param>
|
| | | /// <param name="nDataAddr"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::TxtToDataType(CStringA Typetxt, int * nDataType, int* nDataAddr)
|
| | | {
|
| | | Typetxt.MakeUpper();
|
| | |
| | | return true;
|
| | | }
|
| | | }
|
| | | *nDataType = KLDataTypeDEC;
|
| | | *nDataAddr = atoi(Typetxt);
|
| | | return false;
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// |
| | | /// </summary>
|
| | | /// <param name="nType"></param>
|
| | | /// <param name="typeTxt"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::DataTypeToTxt(int nType, CStringA & typeTxt)
|
| | | {
|
| | | for (int i = 0; i < nDataTypeDefCount; i++)
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取与特定类型和地址相对应的线圈注释
|
| | | /// </summary>
|
| | | /// <param name="nType"></param>
|
| | | /// <param name="nAddr"></param>
|
| | | /// <param name="sAnno"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::GetAnno(unsigned short nType, unsigned short nAddr, CString & sAnno)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设置或更新特定线圈的注释
|
| | | /// </summary>
|
| | | /// <param name="sCoilName"></param>
|
| | | /// <param name="sAnno"></param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::SetAnno(CString sCoilName, CString sAnno)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
| | | return 2;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 直接使用类型和地址参数来设置或更新特定线圈的注释
|
| | | /// </summary>
|
| | | /// <param name="nType">类型</param>
|
| | | /// <param name="nAddr">地址</param>
|
| | | /// <param name="sCoilName">线圈名称</param>
|
| | | /// <param name="sAnno">线圈注释</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::SetAnno(unsigned short nType, unsigned short nAddr, CString sCoilName, CString sAnno)
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
| | | nCoilAnnoCount++;
|
| | | return 0;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 转换文本行为Prog格式
|
| | | /// </summary>
|
| | | /// <param name="txtLines">文本行集合</param>
|
| | | /// <param name="StartLine">开始行</param>
|
| | | /// <param name="ProgLines">程序行</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::TransLinesToProg(const CStringArray & txtLines, int StartLine , int ProgLines)
|
| | | {
|
| | | CString s1;
|
| | |
| | | else nProgLines = ProgLines;
|
| | | int nProgPos = 0;
|
| | |
|
| | | //逐行读取并转化
|
| | | for (int i = nProgStartLine; i < nProgStartLine + nProgLines; i++)
|
| | | {
|
| | | CString sLine;
|
| | | sLine = txtLines.GetAt(i);
|
| | | //清除空格和制表符
|
| | | sLine.Trim();
|
| | | sLine.Replace(_T("\t"), _T(" "));
|
| | | sLine.Replace(_T(" "), _T(" "));
|
| | | sLine.Replace(_T(" "), _T(" "));
|
| | |
|
| | | //使用空格分隔字符串,并将其存储在 strarr2 数组中
|
| | | CStringArray strarr2;
|
| | | DivideStringToArray(sLine, _T(" "), strarr2);
|
| | | if (strarr2.GetSize() == 0) continue;
|
| | |
|
| | | if (strarr2.GetSize() == 0)
|
| | | {
|
| | | continue;
|
| | | }
|
| | |
|
| | | //从数组中提取指令,并将其转换为大写形式
|
| | | CString sCmd;
|
| | | sCmd = strarr2.GetAt(0);
|
| | | sCmd.MakeUpper();
|
| | |
|
| | | //使用 TxtToOp 函数将指令文本转换为操作类型。
|
| | | CStringA s1A;
|
| | | s1A = sCmd;
|
| | | int nParamCount, nParamType;
|
| | | int nType, nAddr;
|
| | | int k = TxtToOp(s1A, &nParamCount, &nParamType);
|
| | |
|
| | | if (k >= 0)
|
| | | {
|
| | | //根据参数类型,使用 TxtToCoilType 或 TxtToDataType 函数将参数文本转换为参数类型和地址
|
| | | Progs[nProgPos].nOpType1 = k;
|
| | | for (int j = 0; j < 3 && j < nParamCount && j < strarr2.GetSize() - 1; j++)
|
| | | {
|
| | |
| | | Progs[nProgPos].Params[j].nParamType = nType;
|
| | | Progs[nProgPos].Params[j].nParamAddr = nAddr;
|
| | | }
|
| | | else {
|
| | | else { |
| | |
|
| | | }
|
| | | }
|
| | |
| | | nProgPos++;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | m_nProgSteps = nProgPos;
|
| | |
|
| | | s1.Format(_T("DOC::Trans to Prog "));
|
| | | SysLog(s1);
|
| | | |
| | | FindProgPair();
|
| | | TransProgToBin();
|
| | | return 0;
|
| | | }
|
| | |
|
| | | int CMTerm1Doc::FindProgPair()
|
| | | {
|
| | | CString s1;
|
| | | // 先扫描分开的程序段
|
| | | int stpos[100] = { 0 };
|
| | | int nSts = 0;
|
| | | int StackDeeps[512] = { 0 };
|
| | | int nCurStackDeep = 0;
|
| | | // 查找匹配指令和地址
|
| | | s1.Format(_T("DOC::Trans to Prog "));
|
| | | SysLog(s1);
|
| | | for (int i = 0; i < m_nProgSteps; i++) {
|
| | | //匹配指令(错误,此处匹配指令使用数字
|
| | | for (int i = 0; i < m_nProgSteps; i++)
|
| | | {
|
| | | int nOpType = Progs[i].nOpType1;
|
| | | int nParamCount = Progs[i].nParamCount;
|
| | | switch (Progs[i].nOpType1)
|
| | |
| | | }
|
| | | 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);
|
| | | }
|
| | | }
|
| | | TransProgToBin();
|
| | | SysLog(s1);
|
| | | return 0;
|
| | | }
|
| | |
|
| | | int CMTerm1Doc::TransTxtToProg(CStringA ProgTxtA)
|
| | | {
|
| | | CString s1;
|
| | |
| | | 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++)
|
| | | {
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 解析文件为梯形图
|
| | | /// </summary>
|
| | | /// <param name="ProgTxtA">文本</param>
|
| | | /// <returns></returns>
|
| | | int CMTerm1Doc::TransFileToProg(CStringA ProgTxtA)
|
| | | {
|
| | | CString s1;
|
| | |
| | | sProg.Replace(_T("\r\n"), _T("\n"));
|
| | | sProg.Replace(_T("\r"), _T("\n"));
|
| | |
|
| | | //分割文本字符串
|
| | | DivideStringToArray(sProg, _T("\n"), txtLines);
|
| | |
|
| | | nSectionCount = 0;
|
| | |
| | | int nRightBracket;
|
| | | if (sLine.Find(_T("[")) == 0 && (nRightBracket = sLine.Find(_T("]"))) > 1)
|
| | | { //找到 [ ] 标志
|
| | | if (nSectionCount > 0) {
|
| | | if (nSectionCount > 0) |
| | | {
|
| | | Sections[nSectionCount - 1].nLines = i - Sections[nSectionCount - 1].nSectionLineNo - 1;
|
| | | s1.Format(_T("- Line %d Section %d Ends, %d Lines"), i, nSectionCount -1 ,Sections[nSectionCount - 1].nLines);
|
| | | SysLog(s1);
|
| | |
| | | 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);
|
| | | Sections[nSectionCount].nSectionType = theSection;
|
| | |
| | | int nAnnoLines = 0;
|
| | |
|
| | | int bAnnoSection = GetSectionPos(SectionAnno, &nAnnoSectionLine, &nAnnoLines);
|
| | | if (bAnnoSection) { nAnnoStartLine = nAnnoSectionLine + 1; }
|
| | | if (bAnnoSection) |
| | | {
|
| | | nAnnoStartLine = nAnnoSectionLine + 1; |
| | | }
|
| | |
|
| | | for (int i = nAnnoStartLine; i < nAnnoStartLine + nAnnoLines; i++)
|
| | | {
|
| | |
| | | CStringA s1A;
|
| | | s1A = sCoilName;
|
| | | int nParamType,nAddr;
|
| | | TxtToCoilType(s1A, &nParamType,&nAddr)||TxtToDataType(s1A, &nParamType, &nAddr);
|
| | | TxtToCoilType(s1A, &nParamType,&nAddr)
|
| | | ||TxtToDataType(s1A, &nParamType, &nAddr);
|
| | |
|
| | | mCoilAnnos[nCoilAnnoCount].nType = nParamType;
|
| | | mCoilAnnos[nCoilAnnoCount].nAddr = nAddr;
|
| | |
| | |
|
| | | return 0;
|
| | | }
|
| | |
|
| | | //文本段在此处组装
|
| | | int CMTerm1Doc::TransToTxt(CStringA &ProgTxt)
|
| | | {
|
| | | CStringA s1, s2;
|
| | |
| | | int CMTerm1Doc::TransProgToBin()
|
| | | {
|
| | | CString s1;
|
| | | stBinProg15* pBinProg15;
|
| | | stBinProg2 * pBinProg2;
|
| | | stBinProg15 * pBinProg15;
|
| | | stBinProg3 * pBinProg3;
|
| | | nBinProgSteps = 0;
|
| | | for (int i = 0; i < m_nProgSteps; i++)
|
| | |
| | | //case OP_NOP:
|
| | | break;
|
| | | //无参数 指令
|
| | | case OP_END:
|
| | | case OP_NOT:
|
| | | case OP_ANS:
|
| | | case OP_ORS:
|
| | |
| | | case OP_TMX:
|
| | | case OP_TMY:
|
| | | pBinProg15 = (stBinProg15 *)(&BinProgs[nBinProgSteps]);
|
| | |
|
| | | BinProgs[nBinProgSteps].nOp = nOpType;
|
| | | BinProgs[nBinProgSteps].nParamType = nParamAddr1;
|
| | | BinProgs[nBinProgSteps].nParamAddr = nParamAddr2;
|
| | | BinProgs[nBinProgSteps + 1].nOp = nParamType2;
|
| | | BinProgs[nBinProgSteps + 1].nParamType = 0;
|
| | | BinProgs[nBinProgSteps + 1].nParamAddr = 0;
|
| | | pBinProg15->nOpNum = Progs[i].Params[0].nParamAddr;
|
| | | |
| | | nBinProgSteps += 2;
|
| | | break;
|
| | | // 1 参数高级指令
|
| | |
| | |
|
| | | int CMTerm1Doc::TransBinToProg()
|
| | | {
|
| | | CString s1;
|
| | | //nBinProgSteps = 0;
|
| | | m_nProgSteps = 0;
|
| | | stBinProg2* pBinProg2;
|
| | | stBinProg15* pBinProg15;
|
| | | stBinProg3* pBinProg3;
|
| | | CStringA s1A;
|
| | | CString s2,s3;
|
| | | CStringA s2A, s3A;
|
| | | for (int i = 0; i < nBinProgSteps; i++)
|
| | | {
|
| | | int nOpType = BinProgs[i].nOp;
|
| | | int nParamType1 = BinProgs[i].nParamType;
|
| | | int nParamAddr1 = BinProgs[i].nParamAddr;
|
| | | // int nParamType1 = Progs[i].Params[0].nParamType;
|
| | | // int nParamAddr1 = Progs[i].Params[0].nParamAddr;
|
| | | int nParamType2, nParamAddr2;
|
| | | int nParamType3, nParamAddr3;
|
| | | CoilTypeToTxt(nParamType1, s1A);
|
| | | s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
| | | Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
| | | Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
| | | Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
| | |
|
| | | switch (nOpType)
|
| | | {
|
| | | case OP_NONE:
|
| | | break;
|
| | | //case OP_NOP:
|
| | | break;
|
| | | //无参数 指令
|
| | | case OP_END:
|
| | | case OP_NOT:
|
| | | case OP_ANS:
|
| | | case OP_ORS:
|
| | | case OP_PSHS:
|
| | | case OP_RDS:
|
| | | case OP_POPS:
|
| | | case OP_DF:
|
| | | case OP_DF_:
|
| | | Progs[m_nProgSteps].nOpType1 = nOpType;
|
| | | Progs[m_nProgSteps].nParamCount = 0;
|
| | | Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
| | | Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
| | |
|
| | | //BinProgs[nBinProgSteps].nOp = nOpType;
|
| | | m_nProgSteps += 1;
|
| | | //nBinProgSteps += 1;
|
| | | break;
|
| | | // 1参数指令
|
| | | case OP_ST:
|
| | | case OP_ST_:
|
| | | case OP_AN:
|
| | | case OP_AN_:
|
| | | case OP_OR:
|
| | | case OP_OR_:
|
| | | Progs[m_nProgSteps].nOpType1 = nOpType;
|
| | | Progs[m_nProgSteps].nParamCount = 1;
|
| | | Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
| | | Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
| | | m_nProgSteps += 1;
|
| | | //i += 1;
|
| | | break;
|
| | | // 1 参数 输出
|
| | | case OP_OUT:
|
| | | case OP_SET:
|
| | | case OP_RESET:
|
| | | Progs[m_nProgSteps].nOpType1 = nOpType;
|
| | | Progs[m_nProgSteps].nParamCount = 1;
|
| | | Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
| | | Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
| | | m_nProgSteps += 1;
|
| | | //i += 1;
|
| | | break;
|
| | |
|
| | | // 比较指令
|
| | | case OP_ST_EQ:
|
| | | case OP_ST_NE:
|
| | | case OP_ST_LT:
|
| | | case OP_ST_GT:
|
| | | case OP_ST_LE:
|
| | | case OP_ST_GE:
|
| | | case OP_AN_EQ:
|
| | | case OP_AN_NE:
|
| | | case OP_AN_LT:
|
| | | case OP_AN_GT:
|
| | | case OP_AN_LE:
|
| | | case OP_AN_GE:
|
| | | case OP_OR_EQ:
|
| | | case OP_OR_NE:
|
| | | case OP_OR_LT:
|
| | | case OP_OR_GT:
|
| | | case OP_OR_LE:
|
| | | case OP_OR_GE:
|
| | | pBinProg2 = (stBinProg2*)(&BinProgs[i]);
|
| | |
|
| | | nParamType1 = pBinProg2->nParamType1;
|
| | | nParamAddr1 = pBinProg2->nParamAddr1;
|
| | | nParamType2 = pBinProg2->nParamType2;
|
| | | nParamAddr2 = pBinProg2->nParamAddr2;
|
| | |
|
| | | DataTypeToTxt(nParamType1, s1A);
|
| | | s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
| | |
|
| | | DataTypeToTxt(nParamType2, s2A);
|
| | | s2.Format(_T("%S%d"), s2A, nParamAddr2);
|
| | |
|
| | | Progs[m_nProgSteps].nOpType1 = nOpType;
|
| | | Progs[m_nProgSteps].nParamCount = 2;
|
| | | Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
| | | Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
| | | Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
| | |
|
| | | Progs[m_nProgSteps].Params[1].nParamType = nParamType2;
|
| | | Progs[m_nProgSteps].Params[1].nParamAddr = nParamAddr2;
|
| | | Progs[m_nProgSteps].Params[1].sParamStr = s2;
|
| | |
|
| | | m_nProgSteps += 1;
|
| | | i += 1;
|
| | | break;
|
| | |
|
| | | // 定时器
|
| | | case OP_TML:
|
| | | case OP_TMR:
|
| | | case OP_TMX:
|
| | | case OP_TMY:
|
| | | //pBinProg2 = (stBinProg2*)(&BinProgs[i]);
|
| | |
|
| | | pBinProg15 = (stBinProg15*)(&BinProgs[i]);
|
| | |
|
| | | nParamType1 = 0;
|
| | | nParamAddr1 = pBinProg15->nOpNum;
|
| | | nParamType2 = pBinProg15->nParamType1;
|
| | | nParamAddr2 = pBinProg15->nParamAddr1;
|
| | | //nParamAddr2 = pBinProg15->nParamAddr2;
|
| | | DataTypeToTxt(nParamType1, s1A);
|
| | | s1.Format(_T("%d"), nParamAddr1);
|
| | |
|
| | | DataTypeToTxt(nParamType2, s2A);
|
| | | s2.Format(_T("%S%d"), s2A, nParamAddr2);
|
| | |
|
| | | Progs[m_nProgSteps].nOpType1 = nOpType;
|
| | | Progs[m_nProgSteps].nParamCount = 2;
|
| | | Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
| | | Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
| | | Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
| | |
|
| | | Progs[m_nProgSteps].Params[1].nParamType = nParamType2;
|
| | | Progs[m_nProgSteps].Params[1].nParamAddr = nParamAddr2;
|
| | | Progs[m_nProgSteps].Params[1].sParamStr = s2;
|
| | | m_nProgSteps += 1;
|
| | | i += 1;
|
| | |
|
| | | break;
|
| | | // 1 参数高级指令
|
| | | case OP_INC:
|
| | | case OP_DEC:
|
| | | pBinProg15 = (stBinProg15*)(&BinProgs[i]);
|
| | | nParamType1 = pBinProg15->nParamType1;
|
| | | nParamAddr1 = pBinProg15->nParamAddr1;
|
| | |
|
| | | DataTypeToTxt(nParamType1, s1A);
|
| | | s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
| | |
|
| | | Progs[m_nProgSteps].nOpType1 = nOpType;
|
| | | Progs[m_nProgSteps].nParamCount = 1;
|
| | | Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
| | | Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
| | | Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
| | |
|
| | | m_nProgSteps += 1;
|
| | | i += 1;
|
| | | break;
|
| | | // 2参数高级指令
|
| | | case OP_MV:
|
| | | case OP_ADD2:
|
| | | case OP_SUB2:
|
| | | pBinProg2 = (stBinProg2*)(&BinProgs[i]);
|
| | |
|
| | | nParamType1 = pBinProg2->nParamType1;
|
| | | nParamAddr1 = pBinProg2->nParamAddr1;
|
| | | nParamType2 = pBinProg2->nParamType2;
|
| | | nParamAddr2 = pBinProg2->nParamAddr2;
|
| | |
|
| | | DataTypeToTxt(nParamType1, s1A);
|
| | | s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
| | |
|
| | | DataTypeToTxt(nParamType2, s2A);
|
| | | s2.Format(_T("%S%d"), s2A, nParamAddr2);
|
| | |
|
| | | Progs[m_nProgSteps].nOpType1 = nOpType;
|
| | | Progs[m_nProgSteps].nParamCount = 2;
|
| | | Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
| | | Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
| | | Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
| | |
|
| | | Progs[m_nProgSteps].Params[1].nParamType = nParamType2;
|
| | | Progs[m_nProgSteps].Params[1].nParamAddr = nParamAddr2;
|
| | | Progs[m_nProgSteps].Params[1].sParamStr = s2;
|
| | |
|
| | | m_nProgSteps += 1;
|
| | | i += 1;
|
| | |
|
| | | break;
|
| | | // 3 参数高级指令
|
| | | case OP_ADD3:
|
| | | case OP_SUB3:
|
| | | case OP_MUL:
|
| | | case OP_DIV:
|
| | | pBinProg3 = (stBinProg3*)(&BinProgs[i]);
|
| | | nParamType1 = pBinProg3->nParamType1;
|
| | | nParamAddr1 = pBinProg3->nParamAddr1;
|
| | | nParamType2 = pBinProg3->nParamType2;
|
| | | nParamAddr2 = pBinProg3->nParamAddr2;
|
| | | nParamType3 = pBinProg3->nParamType3;
|
| | | nParamAddr3 = pBinProg3->nParamAddr3;
|
| | |
|
| | | DataTypeToTxt(nParamType1, s1A);
|
| | | s1.Format(_T("%S%d"), s1A, nParamAddr1);
|
| | |
|
| | | DataTypeToTxt(nParamType2, s2A);
|
| | | s2.Format(_T("%S%d"), s2A, nParamAddr2);
|
| | | DataTypeToTxt(nParamType3, s3A);
|
| | | s3.Format(_T("%S%d"), s3A, nParamAddr3);
|
| | |
|
| | | Progs[m_nProgSteps].nOpType1 = nOpType;
|
| | | Progs[m_nProgSteps].nParamCount = 3;
|
| | | Progs[m_nProgSteps].Params[0].nParamType = nParamType1;
|
| | | Progs[m_nProgSteps].Params[0].nParamAddr = nParamAddr1;
|
| | | Progs[m_nProgSteps].Params[0].sParamStr = s1;
|
| | | Progs[m_nProgSteps].Params[1].nParamType = nParamType2;
|
| | | Progs[m_nProgSteps].Params[1].nParamAddr = nParamAddr2;
|
| | | Progs[m_nProgSteps].Params[1].sParamStr = s2;
|
| | | Progs[m_nProgSteps].Params[2].nParamType = nParamType3;
|
| | | Progs[m_nProgSteps].Params[2].nParamAddr = nParamAddr3;
|
| | | Progs[m_nProgSteps].Params[2].sParamStr = s3;
|
| | | m_nProgSteps += 1;
|
| | | i += 2;
|
| | | break;
|
| | | default:
|
| | | break;
|
| | | }
|
| | |
|
| | | }
|
| | | s1.Format(_T("%d binsteps to %d Steps "), nBinProgSteps, m_nProgSteps );
|
| | | DbgLog(s1);
|
| | | return 0;
|
| | | }
|
| | |
|
| | |
| | | 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("读取 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;
|
| | |
|
| | | if (m_bPlcRunning) {
|
| | | r = AfxMessageBox(_T("PLC Running, Stop it?"), MB_YESNO);
|
| | | r = AfxMessageBox(_T("PLC运行中,是否停止以便下载程序?"), MB_YESNO);
|
| | | if (r == IDYES) { StopPLC();}
|
| | | else { 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;
|
| | |
| | | for (int i = 0; i < DownloadSize; i += Steps) {
|
| | | //int Steps = 16;
|
| | | if (i + Steps > DownloadSize) { Steps = DownloadSize - i; }
|
| | | s1.Format(_T("Downloading %d to %d "), i, i + Steps);
|
| | | DbgLog(s1);
|
| | | r = MyKLink1.WriteProgram(1, 2, (i)*4, Steps * 4, (USHORT *)&BinProgs[i]);
|
| | | s1.Format(_T("Download r = %d "), r);
|
| | | DbgLog(s1);
|
| | | int n = 0;
|
| | | do {
|
| | | s1.Format(_T("Downloading %d to %d "), i, i + Steps);
|
| | | DbgLog(s1);
|
| | | r = theApp.MyKLink1.DownloadPLCProgram(1, 2, (i) * 4, Steps * 4, (USHORT*)&BinProgs[i]);
|
| | | s1.Format(_T("Download r = %d "), r);
|
| | | DbgLog(s1);
|
| | | n += 1;
|
| | | if (n > 10) break;
|
| | | } while (r != 0);
|
| | | //Update Progress Bar
|
| | | }
|
| | |
|
| | | 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);
|
| | | // 下载系统寄存器配置
|
| | |
|
| | |
|
| | | //启动运行
|
| | | r = AfxMessageBox(_T("程序下载完成,是否启动运行?"), MB_YESNO);
|
| | | if (r == IDYES) { StartPLC(); }
|
| | | else { return 0; }
|
| | |
|
| | | return 0;
|
| | | }
|
| | |
| | | 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()
|
| | | {
|
| | | // TODO: 在此添加命令处理程序代码
|
| | | CString s1;
|
| | | unsigned short* p1 = (unsigned short *)&BinProgs;
|
| | | if (!m_bSimulate) {
|
| | | myKMachine1.Download(BinProgs, nBinProgSteps);
|
| | | myKMachine1.StartPLC();
|
| | | |
| | | s1.Format(_T("启动PLC模拟\r\n"));
|
| | | SysLog(s1);
|
| | | m_bSimulate = true;
|
| | | s1.Empty();
|
| | | for (int i = 0; i < nBinProgSteps; i++) {
|
| | | s1.AppendFormat(_T("%04X %04X "), p1[i*2],p1[i*2+1]);
|
| | | }
|
| | | SysLog(s1);
|
| | | s1.Format(_T("Download %d program to sim PLC"),nBinProgSteps);
|
| | | SysLog(s1);
|
| | | myKMachine1.Download(BinProgs, nBinProgSteps);
|
| | | m_bOnline = true;
|
| | | myKMachine1.StartPLC();
|
| | | s1.Format(_T("Start sim PLC"));
|
| | | SysLog(s1);
|
| | | StartPLC();
|
| | | }
|
| | | else {
|
| | | StopPLC();
|
| | | m_bSimulate = false;
|
| | | m_bOnline = false;
|
| | | StopPLC();
|
| | |
|
| | | }
|
| | | UpdateAllViews(NULL, UpdataHint::UpdateStat);
|
| | | }
|
| | |
|
| | | void CMTerm1Doc::OnUpdateSimulate(CCmdUI *pCmdUI)
|
| | | {
|
| | | // TODO: 在此添加命令更新用户界面处理程序代码
|
| | | pCmdUI->SetCheck(m_bSimulate == true);
|
| | | }
|
| | |
|
| | | int CMTerm1Doc::StartPLC()
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | | for (int i = 0; i < KLDataWXCount; i++) {
|
| | | KMem.WX[i] = 0;
|
| | | if (m_bSimulate) {
|
| | | for (int i = 0; i < KLDataWXCount; i++) {
|
| | | KMem.WX[i] = 0;
|
| | | }
|
| | | for (int i = 0; i < KLDataWYCount; i++) {
|
| | | KMem.WY[i] = 0;
|
| | | }
|
| | | for (int i = 0; i < KLDataWRCount; i++) {
|
| | | KMem.WR[i] = 0;
|
| | | }
|
| | | for (int i = 0; i < KLDataDTCount; i++) {
|
| | | KMem.DT[i] = 0;
|
| | | }
|
| | | for (int i = 0; i < TOTALTIMERS; i++) {
|
| | | KMem.Timers[i] = { 0 };
|
| | | }
|
| | | myKMachine1.nScanCount = 0;
|
| | | nScanCount = 0;
|
| | | m_bPlcRunning = 1;
|
| | | }else {
|
| | | theApp.MyKLink1.ChangeMode(1, 1);
|
| | | m_bPlcRunning = 1;
|
| | | }
|
| | | for (int i = 0; i < KLDataWYCount; i++) {
|
| | | KMem.WY[i] = 0;
|
| | | }
|
| | | for (int i = 0; i < KLDataWRCount; i++) {
|
| | | KMem.WR[i] = 0;
|
| | | }
|
| | | for (int i = 0; i < KLDataDTCount; i++) {
|
| | | KMem.DT[i] = 0;
|
| | | }
|
| | | for (int i = 0; i < TOTALTIMERS; i++) {
|
| | | KMem.Timers[i] = { 0 };
|
| | | }
|
| | | nScanCount = 0;
|
| | | m_bPlcRunning = 1;
|
| | | return 0;
|
| | | }
|
| | |
|
| | |
| | | int CMTerm1Doc::StopPLC()
|
| | | {
|
| | | // TODO: 在此处添加实现代码.
|
| | |
|
| | | m_bPlcRunning = false;
|
| | | if (m_bSimulate) {
|
| | | m_bPlcRunning = false;
|
| | | }
|
| | | else {
|
| | | theApp.MyKLink1.ChangeMode(1, 0);
|
| | | m_bPlcRunning = false;
|
| | | }
|
| | |
|
| | | return 0;
|
| | | }
|
| | |
| | | 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);
|
| | | s1.Format(_T("GetInfo = %d %d"), j,len1);
|
| | | 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.AppendFormat(_T("%04X "), buf1[i]);
|
| | | }
|
| | | s1 += _T("\r\n");
|
| | | pKMInfoBlock pinfob = (pKMInfoBlock)buf1;
|
| | |
|
| | | s1.AppendFormat(_T(" DeviceType %04X \t "),pinfob->nDeviceTypeVer);
|
| | | s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer);
|
| | | s1.AppendFormat(_T(" nKLinkVer %04X \t"), pinfob->nKLinkVer);
|
| | | s1.AppendFormat(_T(" nKBusVer %04X \r\n"), pinfob->nKBusVer);
|
| | | s1.AppendFormat(_T(" nCapacity1 %d k \t"), pinfob->nCapacity1);
|
| | | s1.AppendFormat(_T(" nCapacity2 %d k\r\n"), pinfob->nCapacity2);
|
| | | s1.AppendFormat(_T(" nDInput %d \t"), pinfob->nDInput);
|
| | | s1.AppendFormat(_T(" nDOutput %d \r\n"), pinfob->nDOutput);
|
| | | s1.AppendFormat(_T(" nAInput %d \t"), pinfob->nAInput);
|
| | | s1.AppendFormat(_T(" nAOutput %d \r\n"), pinfob->nAOutput);
|
| | | s1.AppendFormat(_T(" nHInput %d \t"), pinfob->nHInput);
|
| | | s1.AppendFormat(_T(" nHOutput %d \r\n"), pinfob->nHOutput);
|
| | | 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);
|
| | | s1.AppendFormat(_T(" nManSize %d \r\n"), pinfob->nManSize);
|
| | | s1.AppendFormat(_T(" nAbility %d \r\n"), pinfob->nAbility);
|
| | | s1.AppendFormat(_T(" nSwitchBits %d \r\n"), pinfob->nSwitchBits);
|
| | |
|
| | | }
|
| | | SysLog(s1);
|
| | | 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 = theApp.MyKLink1.KMRunStat;
|
| | |
|
| | | 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 \t"), RunStat1.WorkMode);
|
| | | s1.AppendFormat(_T(" WorkMode2 %d \r\n"), RunStat1.WorkMode2);
|
| | | 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 = 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::OnMenuShowConsole()
|
| | | {
|
| | | // TODO: 在此添加命令处理程序代码
|
| | |
| | | ASSERT_VALID(theApp.m_pCtrlViewTemplate);
|
| | | CFrameWnd * pFrame = theApp.m_pCtrlViewTemplate->CreateNewFrame(this, NULL);
|
| | | ASSERT_KINDOF(CFrameWnd, pFrame);
|
| | | theApp.m_pCtrlViewTemplate->InitialUpdateFrame(pFrame, this);
|
| | | theApp.m_pCtrlViewTemplate->InitialUpdateFrame(pFrame, this);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | 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.KLDataTypeWR;
|
| | | nDataType = theApp.MyKLink1.KLDataTypeWLX;
|
| | | nDataAddr = 0;
|
| | | nDataCount = 4;
|
| | | for (int i = 0; i < nDataCount; i++) {
|
| | | KMem.WLX[i] = myKMachine1.KMem.WLX[i];
|
| | | }
|
| | |
|
| | | nDataType = theApp.MyKLink1.KLDataTypeWLY;
|
| | | nDataAddr = 0;
|
| | | nDataCount = 4;
|
| | | for (int i = 0; i < nDataCount; i++) {
|
| | | KMem.WLY[i] = myKMachine1.KMem.WLY[i];
|
| | | }
|
| | |
|
| | | 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.KLDataTypeWR;
|
| | |
|
| | | nDataType = theApp.MyKLink1.KLDataTypeWLX;
|
| | | nDataAddr = 0;
|
| | | 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 = theApp.MyKLink1.KLDataTypeWLY;
|
| | | nDataAddr = 0;
|
| | | 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 = 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);
|
| | | }
|
| | | }
|