From fc8a81d80e32cdafdae319cf439145db6613c793 Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期五, 22 七月 2022 15:00:10 +0800
Subject: [PATCH] fix HvserialPort and Klink

---
 MTerm2/MTerm2CommDevView.cpp |  177 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 156 insertions(+), 21 deletions(-)

diff --git a/MTerm2/MTerm2CommDevView.cpp b/MTerm2/MTerm2CommDevView.cpp
index cf8583f..00eb853 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()
 
 
@@ -272,7 +275,8 @@
 	//	s1.AppendFormat(_T("Total S %8d \r\nTotal R %8d \r\n"), MySerialCom1.TotalSendBytes, MySerialCom1.TotalRecvBytes);
 	s1 += intToString(pDoc->myHvSerialPort1.TotalRecvBytes) + _T("\r\n");
 	//	stepCount++;
-	static double LastCalTime = GetTimemS();
+
+	static double LastCalTime = 0;
 	double thisTime = GetTimemS();
 	if (thisTime - LastCalTime > 500)
 	{
@@ -354,6 +358,20 @@
 		}
 		s2.Append(_T("\r\n"));
 	}
+	s2.Append(_T("\r\n"));
+
+	for (int i = 8; i < (nCount + 15) / 16; i++)
+	{
+		s2.AppendFormat(_T("%3X: "), i * 16);
+		for (int j = 0; j < 16; j++)
+		{
+			s2.AppendFormat(_T("%02X"), pDoc->MyKLink1.MEM.SDB[i * 16 + j]);
+			if (j == 7) { s2.Append(_T("  ")); }
+			else { s2.Append(_T(" ")); }
+		}
+		s2.Append(_T("\r\n"));
+	}
+
 	//	s2.AppendFormat(_T("%d\r\n"), pDoc->MyKLink1.MEM.SDD[5]);
 
 	nCount = 32;
@@ -546,6 +564,7 @@
 		//DrawPic1();
 //		MyLogger1.UpdateLogDisplay(0);
 		UpdateDataDisplay();
+		UpdateLEDDisplay();
 	}
 	else if (nIDEvent == 3)
 	{
@@ -971,7 +990,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 +1012,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 +1032,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 +1051,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 +1073,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)
 			{
@@ -1072,14 +1091,16 @@
 		nStep++;
 //		if (nStep == 2) { nStep = 3; }
 		if (nStep > 4) { nStep = 0; }
+		MonitorSuccessCount += nThisSuccessCount;
+		MonitorFailCount += nThisFailCount;
 		if (nThisFailCount == 0)
 		{
-			MonitorSuccessCount++;
+
 
 		}
 		else
 		{
-			MonitorFailCount++;
+
 		}
 	}
 	return 0;
@@ -1595,7 +1616,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 +2127,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