From f56051fa3102feb35ea60650ebda80f49e62d025 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期二, 05 八月 2025 14:54:24 +0800
Subject: [PATCH] 1. SGMeasurement实现规划的地址 2. 优化读取位时输入的地址不是8的倍数的问题 3. 添加读写心跳的功能

---
 SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
index 94363a7..a3f8234 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
@@ -887,13 +887,13 @@
 		if (type == -1) {
 			AppendLogLineRichStyled(msg, LOG_COLOR_ERROR);
 		}
-		if (type == 0) {
+		else if (type == 0) {
 			AppendLogLineRichStyled(msg, LOG_COLOR_SUCCESS);
 		}
 		else if (type == 1) {
 			AppendLogLineRichStyled(msg, LOG_COLOR_WARNING);
 		}
-		else {
+		else if (type == 2) {
 			AppendLogLineRichStyled(msg, LOG_COLOR_NORMAL);
 		}
 	});
@@ -903,9 +903,14 @@
 
 	// 璁剧疆 PLC 鐩戝惉鍣ㄧ殑寮�濮嬮噰闆嗗洖璋冨嚱鏁�
 	m_plcListener.SetStartCallback([this]() {
-		InitDataStorage();
-		StartDataStorage();
-		UpdateControlStatus(m_bConnected, m_bSaving);
+		if (!m_bConnected) {
+			ConnectToDevice();
+		}
+
+		if (InitDataStorage()) {
+			StartDataStorage();
+			UpdateControlStatus(m_bConnected, m_bSaving);
+		}
 	});
 
 	// 璁剧疆 PLC 鐩戝惉鍣ㄧ殑鍋滄閲囬泦鍥炶皟鍑芥暟
@@ -916,6 +921,11 @@
 
 	// 璁剧疆 PLC 鐩戝惉鍣ㄧ殑鍒嗘瀽鍥炶皟鍑芥暟
 	m_plcListener.SetAnalyzeCallback([this]() {
+		if (!m_bConnected) {
+			AppendLogLineRichStyled(_T("璁惧鏈繛鎺ワ紝璇峰厛杩炴帴璁惧銆�"), LOG_COLOR_WARNING);
+			return std::array<double, 4>{ -1.0, -1.0, -1.0, -1.0 };
+		}
+
 		std::array<double, 4> result;
 		for (int i = 0; i < 4; ++i) {
 			result[i] = AnalyzeStoredData(i + 1); // OUT1 ~ OUT4

--
Gitblit v1.9.3