From 6ff05a44b01c6ac6e33db2ec28dcf6e2a7c2abb0 Mon Sep 17 00:00:00 2001
From: QuakeGod <quakegod@sina.com>
Date: 星期二, 16 一月 2024 19:46:01 +0800
Subject: [PATCH] fix LDS to Prog

---
 MTerm1/MTerm1Doc.cpp |  711 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 634 insertions(+), 77 deletions(-)

diff --git a/MTerm1/MTerm1Doc.cpp b/MTerm1/MTerm1Doc.cpp
index 7f3aaaf..79dccd8 100644
--- a/MTerm1/MTerm1Doc.cpp
+++ b/MTerm1/MTerm1Doc.cpp
@@ -51,6 +51,8 @@
 	{KLCoilTypeSR,"SR"},
 	{KLCoilTypeC,"C"},
 	{KLCoilTypeT,"T"},
+	{KLCoilTypeP,"P"},
+	{KLCoilTypeE,"E"},
 };
 int CMTerm1Doc::nCoilTypeDefCount = sizeof(CMTerm1Doc::CoilTypeNameDef) / sizeof(stTypeNameDef);
 
@@ -204,43 +206,65 @@
 }
 */
 
+/// <summary>
+/// 澶勭悊鏂版枃妗g殑鍒涘缓浜嬩欢
+/// </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:  鍦ㄦ娣诲姞鎮ㄤ笓鐢ㄧ殑鍒涘缓浠g爜
-	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: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫�
 	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: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫�
@@ -250,8 +274,10 @@
 	CDocument::OnCloseDocument();
 }
 
-// CMTerm1Doc 搴忓垪鍖�
-
+/// <summary>
+///  CMTerm1Doc 搴忓垪鍖�
+/// </summary>
+/// <param name="ar"></param>
 void CMTerm1Doc::Serialize(CArchive& ar)
 {
 	CString s1;
@@ -304,6 +330,10 @@
 	SetSearchContent(strSearchContent);
 }
 
+/// <summary>
+/// 璁剧疆鏂囨。鐨勬悳绱㈠唴瀹�
+/// </summary>
+/// <param name="value">瑕佹悳绱㈠唴瀹圭殑瀛楃涓插��</param>
 void CMTerm1Doc::SetSearchContent(const CString& value)
 {
 	if (value.IsEmpty())
@@ -327,11 +357,17 @@
 // 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);
@@ -339,11 +375,14 @@
 #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)
@@ -353,64 +392,80 @@
 		file1.Read(s1A.GetBuffer(l + 2048), l);
 		file1.Close();
 		s1A.ReleaseBuffer(l);
-		TransFileToProg(s1A);
-		UpdateAllViews(NULL);
+
+		TransFileToProg(s1A);//鏂囦欢鍐呭杞崲涓篜rog鏍煎紡
+		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::modeReadWrite, &e);//璇诲啓妯″紡鎵撳紑鏂囦欢
 	if (r)
 	{
-	
+
 		CStringA s1A;
 		CStringA sSectionNameA;
 
 		//鍐欏叆绯荤粺閰嶇疆
-		GetSectionTxt(SectionSysCfg, sSectionNameA); //
+		GetSectionTxt(SectionSysCfg, sSectionNameA); //鑾峰彇绯荤粺閰嶇疆鐨勬枃鏈〃绀�
 		s1A = "[" + sSectionNameA + "]\r\n";
-		file1.Write(s1A, s1A.GetLength());
+		file1.Write(s1A, s1A.GetLength());//灏嗚幏鍙栧埌鐨勬枃鏈唴瀹瑰啓鍏ユ枃浠�
 
 		//鍐欏叆绋嬪簭
-		GetSectionTxt(SectionProg, sSectionNameA); //
+		GetSectionTxt(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); //
+		GetSectionTxt(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); //
+		GetSectionTxt(SectionCoilList, sSectionNameA); //鑾峰彇瑙︾偣鐩戞帶鍒楄〃鐨勬枃鏈〃绀�
 		s1A = "[" + sSectionNameA + "]\r\n";
 		file1.Write(s1A, s1A.GetLength());
+
 		//鍐欏叆鏁版嵁鐩戞帶鍒楄〃
-		GetSectionTxt(SectionDataList, sSectionNameA); //
+		GetSectionTxt(SectionDataList, sSectionNameA); //鑾峰彇鏁版嵁鐩戞帶鍒楄〃鐨勬枃鏈〃绀�
 		s1A = "[" + sSectionNameA + "]\r\n";
 		file1.Write(s1A, s1A.GetLength());
 
 		file1.Close();
+		return 1;
 	}
-	return 0;
+	else//鏂囦欢鎵撳紑澶辫触
+	{
+		return 0;
+	}
 }
 
+/// <summary>
+/// 鏍规嵁鏂囨湰鍖归厤绫诲瀷鐨凨ey骞惰繑鍥�
+/// </summary>
+/// <param name="txt"></param>
+/// <returns></returns>
 int CMTerm1Doc::TxtToSection(CStringA txt)
 {
 	for (int i = 0; i < nSectionDefCount; i++) {
@@ -421,6 +476,12 @@
 	return SectionNone;
 }
 
+/// <summary>
+/// 鏍规嵁Key鍖归厤绫诲瀷鐨勬枃鏈紝閫氳繃txt浼犻�掞紝杩斿洖鏌ヨ鎵ц缁撴灉
+/// </summary>
+/// <param name="nSectionType"></param>
+/// <param name="txt"></param>
+/// <returns></returns>
 int CMTerm1Doc::GetSectionTxt(int nSectionType, CStringA & txt)
 {
 	for (int i = 0; i < nSectionDefCount; i++) {
@@ -432,6 +493,13 @@
 	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++) {
@@ -444,6 +512,13 @@
 	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++){
@@ -455,6 +530,13 @@
 	}
 	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++){
@@ -466,6 +548,12 @@
 	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++) {
@@ -477,6 +565,13 @@
 	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();
@@ -485,12 +580,19 @@
 		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++)
@@ -503,6 +605,13 @@
 	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();
@@ -514,10 +623,18 @@
 			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++)
@@ -530,6 +647,13 @@
 	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: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
@@ -544,6 +668,12 @@
 	return 0;
 }
 
+/// <summary>
+/// 璁剧疆鎴栨洿鏂扮壒瀹氱嚎鍦堢殑娉ㄩ噴
+/// </summary>
+/// <param name="sCoilName"></param>
+/// <param name="sAnno"></param>
+/// <returns></returns>
 int CMTerm1Doc::SetAnno(CString sCoilName, CString sAnno)
 {
 	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
@@ -572,6 +702,14 @@
 	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: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
@@ -590,6 +728,14 @@
 	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;
@@ -604,27 +750,41 @@
 	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++)
 			{
@@ -641,7 +801,7 @@
 					Progs[nProgPos].Params[j].nParamType = nType;
 					Progs[nProgPos].Params[j].nParamAddr = nAddr;
 				}
-				else {
+				else {                                                                                                                                                                                                 
 
 				}
 			}
@@ -650,16 +810,30 @@
 			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)
@@ -697,8 +871,10 @@
 		}
 		StackDeeps[i] = nCurStackDeep;
 	}
+
 	s1.Format(_T("Remaining STs %d"), nSts);
 	SysLog(s1);
+
 	for (int i = 0; i < nSts; i++) {
 		s1.Format(_T("[%d] %d "), i, stpos[i]);
 		SysLog(s1);
@@ -712,10 +888,8 @@
 			SysLog(s1);
 		}
 	}
-	TransProgToBin();
 	return 0;
 }
-
 int CMTerm1Doc::TransTxtToProg(CStringA ProgTxtA)
 {
 	CString s1;
@@ -786,6 +960,11 @@
 	return 0;
 }
 
+/// <summary>
+/// 瑙f瀽鏂囦欢涓烘褰㈠浘
+/// </summary>
+/// <param name="ProgTxtA">鏂囨湰</param>
+/// <returns></returns>
 int CMTerm1Doc::TransFileToProg(CStringA ProgTxtA)
 {
 	CString s1;
@@ -795,6 +974,7 @@
 	sProg.Replace(_T("\r\n"), _T("\n"));
 	sProg.Replace(_T("\r"), _T("\n"));
 
+	//鍒嗗壊鏂囨湰瀛楃涓�
 	DivideStringToArray(sProg, _T("\n"), txtLines);
 
 	nSectionCount = 0;
@@ -808,7 +988,8 @@
 		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);
@@ -818,6 +999,7 @@
 			sSectionName = sLine.Mid(1, nRightBracket - 1);
 			sSectionNameA = sSectionName;
 			int theSection = TxtToSection(sSectionNameA);
+
 			s1.Format(_T("+ Line %d  Section %d : [%s] type:%d  "), i + 1, nSectionCount, sSectionName, theSection);
 			SysLog(s1);
 			Sections[nSectionCount].nSectionType = theSection;
@@ -849,7 +1031,10 @@
 	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++)
 	{
@@ -870,7 +1055,8 @@
 		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;
@@ -882,6 +1068,8 @@
 
 	return 0;
 }
+
+//鏂囨湰娈靛湪姝ゅ缁勮
 int CMTerm1Doc::TransToTxt(CStringA &ProgTxt)
 {
 	CStringA s1, s2;
@@ -901,8 +1089,8 @@
 int CMTerm1Doc::TransProgToBin()
 {
 	CString s1;
+	stBinProg15* pBinProg15;
 	stBinProg2 * pBinProg2;
-	stBinProg15 * pBinProg15;
 	stBinProg3 * pBinProg3;
 	nBinProgSteps = 0;
 	for (int i = 0; i < m_nProgSteps; i++)
@@ -996,12 +1184,15 @@
 		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 鍙傛暟楂樼骇鎸囦护
@@ -1058,7 +1249,251 @@
 
 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_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;
 }
 
@@ -1069,12 +1504,15 @@
 	CString s1;
 	if (!m_bOnline) {
 		r = Connect();
-		MyKLink1.Open();
+	//	MyKLink1.Open();
 	}
 	if (!m_bOnline) return;
 	r = MyKLink1.ReadRunStat(1,0,0,32,(unsigned short *)&MyKLink1.KMRunStat);
 
-
+	if (r != 0) {
+		AfxMessageBox(_T("UploadFrom PLC Failed"));
+		return;
+	}
 //	AfxMessageBox(_T("UploadFrom PLC From Doc"));
 	CString s2;
 	s2.Format(_T("Cur Programs %d \r\n"), nBinProgSteps);
@@ -1131,12 +1569,12 @@
 	CString s1;
 	if (!m_bOnline) {
 		r=Connect();
-		MyKLink1.Open();
+	//	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; }
 	}
@@ -1153,11 +1591,16 @@
 	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 = MyKLink1.WriteProgram(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
 	}
 
@@ -1171,7 +1614,10 @@
 
 	// 涓嬭浇绯荤粺瀵勫瓨鍣ㄩ厤缃�
 
-
+	//鍚姩杩愯
+	r = AfxMessageBox(_T("绋嬪簭涓嬭浇瀹屾垚锛屾槸鍚﹀惎鍔ㄨ繍琛�?"), MB_YESNO);
+	if (r == IDYES) { StartPLC(); }
+	else { return 0; }
 
 	return 0;
 }
@@ -1194,7 +1640,7 @@
 	if (!m_bOnline)
 	{
 		r = Connect();
-		MyKLink1.Open();
+		//MyKLink1.Open();
 	}
 	if (!m_bOnline) return;
 //	m_bOnline = true;
@@ -1229,17 +1675,32 @@
 void CMTerm1Doc::OnSimulate()
 {
 	// TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜
+	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);
 }
@@ -1253,23 +1714,28 @@
 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 };
+		}
+		nScanCount = 0;
+		m_bPlcRunning = 1;
+	}else {
+		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;
 }
 
@@ -1277,8 +1743,13 @@
 int CMTerm1Doc::StopPLC()
 {
 	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
-
-	m_bPlcRunning = false;
+	if (m_bSimulate) {
+		m_bPlcRunning = false;
+	}
+	else {
+		MyKLink1.ChangeMode(1, 0);
+		m_bPlcRunning = false;
+	}
 
 	return 0;
 }
@@ -1340,7 +1811,60 @@
 	int res = MyKLink1.Connect();
 	unsigned short len1;
 	int j=MyKLink1.GetInfo(1, &len1, buf1);
-	s1.Format(_T("GetInfo = %d %d"), j,len1);
+	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 \r\n"),pinfob->nDeviceTypeVer);
+		s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer);
+		s1.AppendFormat(_T(" nKLinkVer %04X \r\n"), pinfob->nKLinkVer);
+		s1.AppendFormat(_T(" nKBusVer %04X \r\n"), pinfob->nKBusVer);
+		s1.AppendFormat(_T(" nCapacity1 %d k\r\n"), pinfob->nCapacity1);
+		s1.AppendFormat(_T(" nCapacity2 %d k\r\n"), pinfob->nCapacity2);
+		s1.AppendFormat(_T(" nDInput %d \r\n"), pinfob->nDInput);
+		s1.AppendFormat(_T(" nDOutput %d \r\n"), pinfob->nDOutput);
+		s1.AppendFormat(_T(" nAInput %d \r\n"), pinfob->nAInput);
+		s1.AppendFormat(_T(" nAOutput %d \r\n"), pinfob->nAOutput);
+		s1.AppendFormat(_T(" nHInput %d \r\n"), pinfob->nHInput);
+		s1.AppendFormat(_T(" nHOutput %d \r\n"), pinfob->nHOutput);
+		s1.AppendFormat(_T(" nExt1 %d \r\n"), 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 = MyKLink1.ReadRunStat(1, 0, 0, 32, (unsigned short*)&MyKLink1.KMRunStat);
+	s1.Format(_T("GetRunStat = %d %d \r\n"), r, 32);
+	KLink1::stRunStat RunStat1 = MyKLink1.KMRunStat;
+
+	s1.AppendFormat(_T(" Sign1 %04X \r\n"), 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(" WorkMode2 %d \r\n"), RunStat1.WorkMode2);
+	s1.AppendFormat(_T(" nBinProgBank %d \r\n"), 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);
+
+	unsigned char value;
+	r = MyKLink1.GetMode(1, 0, &value);
+	if (r == KLink1::KL_OK) { m_bPlcRunning = value; }
+
+
 	SysLog(s1);
 //	m_static_connect.SetCtlColor(RGB(0, 255, 0));
 /*
@@ -1488,7 +2012,7 @@
 	}
 }
 //*/
-
+ 
 void CMTerm1Doc::OnMenuShowConsole()
 {
 	// TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜
@@ -1505,7 +2029,7 @@
 		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);
 	}
 }
 
@@ -1889,6 +2413,20 @@
 			KMem.WY[i] = myKMachine1.KMem.WY[i];
 		}
 
+		nDataType = MyKLink1.KLDataTypeWLX;
+		nDataAddr = 0;
+		nDataCount = 4;
+		for (int i = 0; i < nDataCount; i++) {
+			KMem.WLX[i] = myKMachine1.KMem.WLX[i];
+		}
+
+		nDataType = MyKLink1.KLDataTypeWLY;
+		nDataAddr = 0;
+		nDataCount = 4;
+		for (int i = 0; i < nDataCount; i++) {
+			KMem.WLY[i] = myKMachine1.KMem.WLY[i];
+		}
+
 		nDataType = MyKLink1.KLDataTypeWR;
 		nDataAddr = 0;
 		nDataCount = 10;
@@ -1942,6 +2480,25 @@
 			s1.Format(_T("R:= %d %s  \r\n"), res, MyKLink1.m_resultStr);
 			SysLog(s1);
 		}
+
+		nDataType = 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);
+			SysLog(s1);
+		}
+
+		nDataType = 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);
+			SysLog(s1);
+		}
+
 		nDataType = MyKLink1.KLDataTypeWR;
 		nDataAddr = 0;
 		nDataCount = 10;

--
Gitblit v1.9.1