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/MTerm2CommDevView.cpp |  154 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 136 insertions(+), 18 deletions(-)

diff --git a/MTerm2/MTerm2CommDevView.cpp b/MTerm2/MTerm2CommDevView.cpp
index cf8583f..da7e706 100644
--- a/MTerm2/MTerm2CommDevView.cpp
+++ b/MTerm2/MTerm2CommDevView.cpp
@@ -17,23 +17,23 @@
 #include <SetupAPI.h>
 #include "../MyLib/Functions.hpp"
 #include "../MyLib/UI_Func/UI_Func.hpp"
-#include "CAnsiParser.h"
-#include "CDataParser1.h"
+#include "AnsiParser.h"
+#include "DataParser1.h"
 #include "KLink.h"
 //#include "../MyLib/SerialCom/SerialCom.hpp"
 #include <Dbt.h>
-#include "CDialogCommSet1.h"
-#include "CDialogSysRegSet.h"
-#include "CDialogStatusShow.h"
-#include "CDialogInfoDisplay.h"
+#include "DialogCommSet1.h"
+#include "DialogSysRegSet.h"
+#include "DialogStatusShow.h"
+#include "DialogInfoDisplay.h"
 
-#include "CDialogCoilMon.h"
-#include "CDialogDataMon.h"
+#include "DialogCoilMon.h"
+#include "DialogDataMon.h"
 
-#include "CDialogProgress.h"
-#include "CDialogEventLog.h"
-#include "CDialogDateTime.h"
-#include "CDialogForceIO.h"
+#include "DialogProgress.h"
+#include "DialogEventLog.h"
+#include "DialogDateTime.h"
+#include "DialogForceIO.h"
 #include "HvSerialPort.h"
 
 #ifdef _DEBUG
@@ -140,6 +140,9 @@
 //	ON_BN_CLICKED(IDC_BUTTON11, &CMTerm2CommDevView::OnBnClickedButton11)
 	ON_BN_CLICKED(IDC_BUTTON12, &CMTerm2CommDevView::OnBnClickedButton12)
 	ON_BN_CLICKED(IDC_BUTTON13, &CMTerm2CommDevView::OnBnClickedButton13)
+	ON_BN_CLICKED(IDC_BUTTON31, &CMTerm2CommDevView::OnBnClickedButton31)
+	ON_BN_CLICKED(IDC_BUTTON2, &CMTerm2CommDevView::OnBnClickedButton2)
+	ON_BN_CLICKED(IDC_BUTTON3, &CMTerm2CommDevView::OnBnClickedButton3)
 END_MESSAGE_MAP()
 
 
@@ -546,6 +549,7 @@
 		//DrawPic1();
 //		MyLogger1.UpdateLogDisplay(0);
 		UpdateDataDisplay();
+		UpdateLEDDisplay();
 	}
 	else if (nIDEvent == 3)
 	{
@@ -971,7 +975,7 @@
 		{
 			DataType = pDoc->MyKLink1.KLDataTypeWX;
 			DCount = 16;
-			res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, DAddr, &pDoc->MyKLink1.MEM.WXB[DAddr]);
+			res = pDoc->MyKLink1.ReadDataByte(DstAddr,  DataType, DAddr, DCount, &pDoc->MyKLink1.MEM.WXB[DAddr]);
 			nCount = DCount;
 			if (res == pDoc->MyKLink1.KL_OK)
 			{
@@ -993,7 +997,7 @@
 		{
 			DataType = pDoc->MyKLink1.KLDataTypeWY;
 			DCount = 16;
-			res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, DAddr, &pDoc->MyKLink1.MEM.WYB[DAddr]);
+			res = pDoc->MyKLink1.ReadDataByte(DstAddr, DataType, DAddr, DCount, &pDoc->MyKLink1.MEM.WYB[DAddr]);
 			nCount = DCount;
 			if (res == pDoc->MyKLink1.KL_OK)
 			{
@@ -1013,7 +1017,7 @@
 		{
 			DataType = pDoc->MyKLink1.KLDataTypeWR;
 			DCount = 32;
-			res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, DAddr, &pDoc->MyKLink1.MEM.WRB[DAddr]);
+			res = pDoc->MyKLink1.ReadDataByte(DstAddr,  DataType, DAddr, DCount, &pDoc->MyKLink1.MEM.WRB[DAddr]);
 			nCount = DCount;
 			if (res == pDoc->MyKLink1.KL_OK)
 			{
@@ -1032,7 +1036,7 @@
 		{
 			DataType = pDoc->MyKLink1.KLDataTypeDT;
 			DCount = 96;
-			res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, DAddr, &pDoc->MyKLink1.MEM.DTB[DAddr]);
+			res = pDoc->MyKLink1.ReadDataByte(DstAddr,  DataType, DAddr, DCount, &pDoc->MyKLink1.MEM.DTB[DAddr]);
 			nCount = DCount;
 			if (res == pDoc->MyKLink1.KL_OK)
 			{
@@ -1054,7 +1058,7 @@
 			DataType = pDoc->MyKLink1.KLDataTypeSDT;
 			ByteAddr = nBlock * 128;
 			DCount = 128;
-			res = pDoc->MyKLink1.ReadDataByte(DstAddr, DCount, DataType, ByteAddr, &pDoc->MyKLink1.MEM.SDB[ByteAddr]);
+			res = pDoc->MyKLink1.ReadDataByte(DstAddr,  DataType, ByteAddr, DCount, &pDoc->MyKLink1.MEM.SDB[ByteAddr]);
 			nCount = DCount;
 			if (res == pDoc->MyKLink1.KL_OK)
 			{
@@ -1595,7 +1599,7 @@
 	//	s3.Format("%d %d ",recv2length,wCount2);AppendText(s3);
 
 	s1.Format(_T("R %d(Try %d %d)=%d->"), dNumtoRead, nTryCount, nTryCount2, wCount2);
-	for (DWORD i = 0; i < 8 && i < wCount2; i++)
+	for (DWORD i = 0; i < 16 && i < wCount2; i++)
 	{
 		s1.AppendFormat(_T("%02X "), recv1[i]);
 	}
@@ -2106,4 +2110,118 @@
 
 
 }
+enum enStat
+{
+	normal=0,
+	setchn=1,
+	setvalue=2,
+	setonoff=3,
+
+};
+int nStat = 0;
+int ntimecount = 0;
+#define MaxTimeOut 50
+
+int nCurChn = 0;
+int nValue[4] = { 100,200,300,400 };
+int LedOn[4] = { 0 };
+int flickTimer = 0;
+int CMTerm2CommDevView::UpdateLEDDisplay()
+{
+	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
+	flickTimer++;
+	int bHide = 0;
+	if ((flickTimer & 0x7) > 3) { bHide = 1; }
+
+	CString s1;
+	s1 = _T("0000");
+
+	s1.Format(_T("%d%03d"), nCurChn, nValue[nCurChn]);
+	if (nStat == setchn && bHide)
+	{
+		s1.Format(_T(" %03d"), nValue[nCurChn]);
+	}
+	if (nStat == setvalue && bHide)
+	{
+		s1.Format(_T("%d   "),nCurChn);
+	}
+	if (nStat == setonoff && bHide)
+	{
+		s1.Format(_T("    "), nCurChn);
+	}
+
+	SetDlgItemText(IDC_EDIT31, s1);
+
+	s1.Format(_T("%d %d %d %d"), LedOn[0], LedOn[1], LedOn[2], LedOn[3]);
+	SetDlgItemText(IDC_EDIT32, s1);
+
+	ntimecount++;
+	if (ntimecount >= MaxTimeOut) { nStat = normal; }
+	return 0;
+}
+
+void CMTerm2CommDevView::OnBnClickedButton31()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	ntimecount = 0;
+	if (nStat == setchn)
+	{
+		nCurChn++;
+		if (nCurChn >= 4) { nCurChn = 0; }
+	}
+	if (nStat == setvalue)
+	{
+		nValue[nCurChn] ++;
+		if (nValue[nCurChn] > 999) { nValue[nCurChn] = 999; }
+	}
+	if (nStat == setonoff)
+	{
+		LedOn[nCurChn] =1;
+	}
+}
+
+
+void CMTerm2CommDevView::OnBnClickedButton2()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	ntimecount = 0;
+	if (nStat == setchn)
+	{
+		nCurChn--;
+		if (nCurChn <0) { nCurChn = 3; }
+	}
+	if (nStat == setvalue)
+	{
+		nValue[nCurChn] --;
+		if (nValue[nCurChn] <= 0) { nValue[nCurChn] = 0; }
+	}
+	if (nStat == setonoff)
+	{
+		LedOn[nCurChn] = 0;
+	}
+}
+
+
+void CMTerm2CommDevView::OnBnClickedButton3()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	ntimecount = 0;
+	if (nStat == normal)
+	{
+		nStat = setchn;
+	} else 	if (nStat == setchn)
+	{
+		nStat = setvalue;
+	} else 	if (nStat == setvalue)
+	{
+		nStat = setonoff;
+	}
+	else if (nStat == setonoff)
+	{
+		nStat = setchn;
+	}
+
+}
+
+
 

--
Gitblit v1.9.1