From 65f7136c6dfebde14a07c89c4366fb8bed2fe37f Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期二, 10 五月 2022 14:22:45 +0800
Subject: [PATCH] add factory config mode

---
 MTerm2/MTerm2Doc.cpp |  126 +++++++++++++++++++++++++++--------------
 1 files changed, 82 insertions(+), 44 deletions(-)

diff --git a/MTerm2/MTerm2Doc.cpp b/MTerm2/MTerm2Doc.cpp
index 9ee69b6..8500f61 100644
--- a/MTerm2/MTerm2Doc.cpp
+++ b/MTerm2/MTerm2Doc.cpp
@@ -26,7 +26,11 @@
 #include "MTerm2CommDevView.h"
 #include <propkey.h>
 
-#include "CDialogCommSet1.h"
+#include "DialogCommSet1.h"
+#include "DialogStatusShow.h"
+#include "DialogSysRegSet.h"
+#include "DialogFactCfg.h"
+
 #include "HvSerialPort.h"
 #include <functional>
 
@@ -35,7 +39,7 @@
 #endif
 
 // CMTerm2Doc
-CMTerm2Doc::stTypeDef CMTerm2Doc::CoilTypeDef[] =
+CMTerm2Doc::stTypeNameDef CMTerm2Doc::CoilTypeNameDef[] =
 {
 	{KLCoilTypeX,"X"},
 	{KLCoilTypeY,"Y"}, 
@@ -47,9 +51,9 @@
 	{KLCoilTypeC,"C"},
 	{KLCoilTypeT,"T"},
 };
-int CMTerm2Doc::nCoilTypeDefCount = sizeof(CMTerm2Doc::CoilTypeDef) / sizeof(stTypeDef);
+int CMTerm2Doc::nCoilTypeDefCount = sizeof(CMTerm2Doc::CoilTypeNameDef) / sizeof(stTypeNameDef);
 
-CMTerm2Doc::stTypeDef CMTerm2Doc::DataTypeDef[] =
+CMTerm2Doc::stTypeNameDef CMTerm2Doc::DataTypeNameDef[] =
 {
 	{KLDataTypeDEC,"K"},
 	{KLDataTypeHEX,"H"},
@@ -65,9 +69,9 @@
 	{KLDataTypeSV,"SV"},
 	{KLDataTypeLD,"LD"},
 };
-int CMTerm2Doc::nDataTypeDefCount = sizeof(CMTerm2Doc::DataTypeDef) / sizeof(stTypeDef);
+int CMTerm2Doc::nDataTypeDefCount = sizeof(CMTerm2Doc::DataTypeNameDef) / sizeof(stTypeNameDef);
 
-CMTerm2Doc::stProgDef CMTerm2Doc::ProgDef[] =
+CMTerm2Doc::stOpDef CMTerm2Doc::OpDef[] =
 {
 	{OP_NOP,"NOP",0},
 	{OP_ST,"ST",1,KLParamCoil},
@@ -122,11 +126,8 @@
 	{OP_MUL,"MUL",3,KLParamWord,"X"},
 	{OP_DIV,"DIV",3,KLParamWord,"/"},
 
-
-
-
 };
-int CMTerm2Doc::nProgDefCount = sizeof(CMTerm2Doc::ProgDef) / sizeof(stProgDef);
+int CMTerm2Doc::nOpDefCount = sizeof(CMTerm2Doc::OpDef) / sizeof(stOpDef);
 
 IMPLEMENT_DYNCREATE(CMTerm2Doc, CDocument)
 
@@ -150,8 +151,12 @@
 	ON_COMMAND(ID_MENU_SHOW_CONSOLE, &CMTerm2Doc::OnMenuShowConsole)
 
 	ON_COMMAND(ID_MENU_COMM_TEST, &CMTerm2Doc::OnMenuCommTest)
+	
+	
 	ON_COMMAND(ID_SIMULATE, &CMTerm2Doc::OnSimulate)
 	ON_UPDATE_COMMAND_UI(ID_SIMULATE, &CMTerm2Doc::OnUpdateSimulate)
+	ON_COMMAND(ID_MENU_STATUS_SHOW, &CMTerm2Doc::OnMenuStatusShow)
+	ON_COMMAND(ID_MENU_FACT_CFG, &CMTerm2Doc::OnMenuFactCfg)
 END_MESSAGE_MAP()
 
 
@@ -163,7 +168,7 @@
 
 	MyKLink1.SetSendCallBackFunc(std::bind(&CMTerm2Doc::SendPacket, this, std::placeholders::_1, std::placeholders::_2));
 	MyKLink1.SetRecvCallBackFunc(std::bind(&CMTerm2Doc::RecvPacket, this, std::placeholders::_1, std::placeholders::_2));
-	StartTime = myHvSerialPort1.GetTimeMs();
+	StartTime = myHvSerialPort1.GetTimemS();
 }
 
 CMTerm2Doc::~CMTerm2Doc()
@@ -176,7 +181,8 @@
 }
 int CMTerm2Doc::RecvPacket(void * pBuf, int Len)
 {
-	int j = myHvSerialPort1.Recv((char *)pBuf, Len);
+	int j = 0;
+	j = myHvSerialPort1.Recv((char *)pBuf, Len);
 	if (j <= 0)
 	{
 		CString s1;
@@ -429,20 +435,20 @@
 
 int CMTerm2Doc::TxtToOp(CStringA optxt, int* ParamCount, int* ParamType)
 {
-	for (int i = 0; i < nProgDefCount; i++){
-		if (ProgDef[i].OpTxt == optxt)	{
-			*ParamCount = ProgDef[i].nParamCount;
-			*ParamType = ProgDef[i].nParamType;
-			return ProgDef[i].nOpType1;
+	for (int i = 0; i < nOpDefCount; i++){
+		if (OpDef[i].OpTxt == optxt)	{
+			*ParamCount = OpDef[i].nParamCount;
+			*ParamType = OpDef[i].nParamType;
+			return OpDef[i].nOpType1;
 		}
 	}
 	return -1;
 }
 int CMTerm2Doc::OpToTxt(int nOp, CStringA & OpTxt)
 {
-	for (int i = 0; i < nProgDefCount; i++){
-		if (ProgDef[i].nOpType1 == nOp) {
-			OpTxt = ProgDef[i].OpTxt;
+	for (int i = 0; i < nOpDefCount; i++){
+		if (OpDef[i].nOpType1 == nOp) {
+			OpTxt = OpDef[i].OpTxt;
 			return true;
 		}
 	}
@@ -451,9 +457,9 @@
 
 int CMTerm2Doc::OpToShowTxt(int nOp, CStringA & OpShowTxt)
 {
-	for (int i = 0; i < nProgDefCount; i++) {
-		if (ProgDef[i].nOpType1 == nOp) {
-			OpShowTxt = ProgDef[i].ShowTxt;
+	for (int i = 0; i < nOpDefCount; i++) {
+		if (OpDef[i].nOpType1 == nOp) {
+			OpShowTxt = OpDef[i].ShowTxt;
 			return true;
 		}
 	}
@@ -465,10 +471,10 @@
 	Typetxt.MakeUpper();
 	for (int i = 0; i < nCoilTypeDefCount; i++)
 	{
-		if (Typetxt.Find( CoilTypeDef[i].TypeTxt)==0) {
-			*nCoilType = CoilTypeDef[i].nType;
-			*nCoilAddr = atoi(Typetxt.Mid(CoilTypeDef[i].TypeTxt.GetLength()));
-			return CoilTypeDef[i].nType;
+		if (Typetxt.Find( CoilTypeNameDef[i].TypeTxt)==0) {
+			*nCoilType = CoilTypeNameDef[i].nType;
+			*nCoilAddr = atoi(Typetxt.Mid(CoilTypeNameDef[i].TypeTxt.GetLength()));
+			return CoilTypeNameDef[i].nType;
 		}
 	}
 	return false;;
@@ -478,8 +484,8 @@
 {
 	for (int i = 0; i < nCoilTypeDefCount; i++)
 	{
-		if (CoilTypeDef[i].nType == nType){
-			typeTxt = CoilTypeDef[i].TypeTxt;
+		if (CoilTypeNameDef[i].nType == nType){
+			typeTxt = CoilTypeNameDef[i].TypeTxt;
 			return true;
 		}
 	}
@@ -491,9 +497,9 @@
 	Typetxt.MakeUpper();
 	for (int i = 0; i < nDataTypeDefCount; i++)
 	{
-		if (Typetxt.Find(DataTypeDef[i].TypeTxt) == 0) {
-			*nDataType = DataTypeDef[i].nType;
-			*nDataAddr = atoi(Typetxt.Mid(DataTypeDef[i].TypeTxt.GetLength()));
+		if (Typetxt.Find(DataTypeNameDef[i].TypeTxt) == 0) {
+			*nDataType = DataTypeNameDef[i].nType;
+			*nDataAddr = atoi(Typetxt.Mid(DataTypeNameDef[i].TypeTxt.GetLength()));
 			return true;
 		}
 	}
@@ -505,8 +511,8 @@
 {
 	for (int i = 0; i < nDataTypeDefCount; i++)
 	{
-		if (DataTypeDef[i].nType == nType) {
-			typeTxt = DataTypeDef[i].TypeTxt;
+		if (DataTypeNameDef[i].nType == nType) {
+			typeTxt = DataTypeNameDef[i].TypeTxt;
 			return true;
 		}
 	}
@@ -558,7 +564,7 @@
 int CMTerm2Doc::SetAnno(unsigned short nType, unsigned short nAddr, CString sCoilName, CString sAnno)
 {
 	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
-// 浜屽垎娉� 鏌ユ壘銆�
+// 浜屽垎娉�? 鏌ユ壘銆�
 // map.
 	for (int i = 0; i < nCoilAnnoCount; i++) {
 		if (mCoilAnnos[i].nType == nType && mCoilAnnos[i].nAddr == nAddr) {
@@ -1358,6 +1364,23 @@
 void CMTerm2Doc::OnPlcSysregSet()
 {
 	// TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜
+	CDialogSysRegSet dialog1;
+	INT_PTR r = dialog1.DoModal();
+	if (r == IDOK)
+	{
+
+	}
+}
+
+void CMTerm2Doc::OnMenuFactCfg()
+{
+	// TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜
+	CDialogFactCfg dialog1;
+	INT_PTR r = dialog1.DoModal();
+	if (r == IDOK)
+	{
+
+	}
 }
 
 
@@ -1643,7 +1666,7 @@
 			return nDataAddr;
 		}
 
-		MyKLink1.ReadDataWord(1, 2, nDataType, nDataAddr, value);// (unsigned char *)&KMem.DT[nDataAddr]);
+		MyKLink1.ReadDataWord(1,  nDataType, nDataAddr, 2, value);// (unsigned char *)&KMem.DT[nDataAddr]);
 		svalue = value[0];
 		return svalue;
 	}
@@ -1728,7 +1751,7 @@
 		unsigned short svalue[10];
 		svalue[0]=nDataValue;
 		int res = 0;
-		res = MyKLink1.WriteDataWord(1, 2, nDataType, nDataAddr, svalue);
+		res = MyKLink1.WriteDataWord(1, nDataType, nDataAddr, 2, svalue);
 		return res;
 	}
 
@@ -1828,7 +1851,7 @@
 		int nDataType = MyKLink1.KLDataTypeWX;
 		int nDataAddr = 0;
 		int nDataCount = 4;
-		int res;
+//		int res;
 		for (int i = 0; i < nDataCount; i++) {
 			KMem.WX[i] = myKMachine1.KMem.WX[i];
 		}
@@ -1878,32 +1901,32 @@
 		int nDataAddr = 0;
 		int nDataCount = 4;
 		int res;
-		res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]);
+		res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]);
 
 		nDataType = MyKLink1.KLDataTypeWY;
 		nDataAddr = 0;
 		nDataCount = 4;
-		res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]);
+		res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]);
 
 		nDataType = MyKLink1.KLDataTypeWR;
 		nDataAddr = 0;
 		nDataCount = 10;
-		res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]);
+		res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]);
 
 		nDataType = MyKLink1.KLDataTypeDT;
 		nDataAddr = 0;
 		nDataCount = 80;
-		res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]);
+		res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]);
 
 		nDataType = MyKLink1.KLDataTypeSV;
 		nDataAddr = 0;
 		nDataCount = 40;
-		res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
+		res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]);
 
 		nDataType = MyKLink1.KLDataTypeEV;
 		nDataAddr = 0;
 		nDataCount = 40;
-		res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
+		res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]);
 
 	}
 
@@ -1912,12 +1935,27 @@
 
 void CMTerm2Doc::OnTimer(UINT_PTR nIDEvent)
 {
+	CString s1;
+//	s1.Format(_T("Doc::OntTimer"));
+//	SysLog(s1);
 	if (m_bSimulate && m_bPlcRunning)
 	{
 		//ProcessPLCProg(Progs, m_nProgSteps);
 		myKMachine1.ProcPLC();
 
 		// update PLC Stat
+	}
+}
+
+void CMTerm2Doc::OnMenuStatusShow()
+{
+	// TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜
+	CDialogStatusShow dialog1;
+	INT_PTR r = dialog1.DoModal();
+	if (r == IDOK)
+	{
 
 	}
 }
+
+

--
Gitblit v1.9.1