From f48732b2178bbaf64f39099391832a6f271fed4d Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期六, 13 九月 2025 16:15:09 +0800
Subject: [PATCH] 1. SG精度检保存界面上的参数到配置文件 2. SG精度检允许设置开机自启动 3. 修改日志保存路径

---
 SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp |   81 +++++++++++++++++++++++++++++++++-------
 1 files changed, 67 insertions(+), 14 deletions(-)

diff --git a/SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp b/SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp
index 4176b59..93660d0 100644
--- a/SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp
+++ b/SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp
@@ -1,4 +1,4 @@
-#include "pch.h"
+锘�#include "pch.h"
 #include "PLCSignalListener.h"
 
 // === 鏃ュ織鎵撳嵃绫诲瀷 ===
@@ -247,35 +247,42 @@
 				// 涓婂崌娌胯Е鍙�
 				switch (i) {
 				case 0:
+					// Start 鍛戒护
 					if (m_cbStart) {
 						m_cbStart();
 						WriteOutValues(OutValuesArray{ 0.0, 0.0, 0.0, 0.0 });
-						if (m_pPlc->SetBitDeviceEx(m_station, PLC_BIT_DEVICE_TYPE, PLC_ACK_BASE_BIT + i) == 0) {
-							m_vecAckSent[i] = true;
-							m_vecAckCounter[i] = 0;
-						}
 
 						std::string strProductID;
 						if (ReadProductID(strProductID)) {
 							CString msg;
-							msg.Format(_T("璇诲彇鍒颁骇鍝両D锛�%s"), strProductID);
+							msg.Format(_T("璇诲彇鍒颁骇鍝両D锛�%s"), CString(strProductID.c_str()));
 							LOG_MSG(msg, LOG_TYPE_SUCCESS);
 						}
+					}
+
+					// 鍙戦�佸簲绛斾俊鍙�
+					if (m_pPlc->SetBitDeviceEx(m_station, PLC_BIT_DEVICE_TYPE, PLC_ACK_BASE_BIT + i) == 0) {
+						m_vecAckSent[i] = true;
+						m_vecAckCounter[i] = 0;
 					}
 					break;
 
 				case 1:
+					// Stop 鍛戒护
 					if (m_cbStop) {
 						m_cbStop();
-						if (m_pPlc->SetBitDeviceEx(m_station, PLC_BIT_DEVICE_TYPE, PLC_ACK_BASE_BIT + i) == 0) {
-							m_vecAckSent[i] = true;
-							m_vecAckCounter[i] = 0;
-						}
 					}
 
+					// Analyze 鍛戒护
 					if (m_cbAnalyze) {
 						auto results = m_cbAnalyze();
 						WriteOutValues(results);
+					}
+
+					// 鍙戦�佸簲绛斾俊鍙�
+					if (m_pPlc->SetBitDeviceEx(m_station, PLC_BIT_DEVICE_TYPE, PLC_ACK_BASE_BIT + i) == 0) {
+						m_vecAckSent[i] = true;
+						m_vecAckCounter[i] = 0;
 					}
 					break;
 				}
@@ -302,15 +309,22 @@
 	}
 
 	for (int i = 0; i < PLC_RESULT_ADDR_COUNT; ++i) {
-		// 鏀惧ぇ1000鍊嶅苟鍥涜垗浜斿叆锛岃浆涓篜LC鏁存暟
-		int32_t  nScaled = static_cast<int32_t>(std::round(values[i] * 1000.0));
-		DWordContainer vec = { static_cast<uint32_t>(nScaled) };
+		double dVal = values[i];
+		int32_t nScaled = 0;
+
+		if (dVal == DBL_MAX || dVal == DBL_MIN || std::isnan(dVal)) {
+			nScaled = static_cast<int32_t>(dVal);
+		}
+		else {
+			nScaled = static_cast<int32_t>(std::round(dVal * 1000.0));
+		}
 
 		short nTargetAddr = PLC_RESULT_ADDR_START + i * 2;
+		DWordContainer vec = { static_cast<uint32_t>(nScaled) };
 		int ret = m_pPlc->WriteDWordDataEx(m_station, PLC_WORD_DEVICE_TYPE, nTargetAddr, vec);
 		if (ret != 0) {
 			CString msg;
-			msg.Format(_T("鍐欏叆OUT%d鍒板湴鍧�%d澶辫触锛屽��=%.2f"), i + 1, nTargetAddr, values[i]);
+			msg.Format(_T("鍐欏叆OUT%d鍒板湴鍧�%d澶辫触锛屽��=%.2f"), i + 1, nTargetAddr, dVal);
 			LOG_MSG(msg, LOG_TYPE_ERROR);
 			return false;
 		}
@@ -353,4 +367,43 @@
 	}
 
 	return true;
+}
+
+bool CPLCSignalListener::WriteProductID(const std::string& strProductID)
+{
+	if (!m_pPlc || !m_bConnected) {
+		LOG_MSG(_T("PLC鏈繛鎺ユ垨鏈垵濮嬪寲锛屾棤娉曞啓鍏ヤ骇鍝両D銆�"), LOG_TYPE_ERROR);
+		return false;
+	}
+
+
+	WordContainer vec;
+	vec.reserve(PLC_PRODUCT_ID_WORDS);
+	for (size_t i = 0; i < strProductID.size();) {
+		unsigned char c1 = static_cast<unsigned char>(strProductID[i]);
+		unsigned char c2 = 0;
+
+		if (i + 1 < strProductID.size()) {
+			c2 = static_cast<unsigned char>(strProductID[i + 1]);
+		}
+
+		uint16_t w = static_cast<uint16_t>(c2 << 8 | c1);
+		vec.push_back(w);
+
+		i += 2;
+	}
+
+	while (vec.size() < PLC_PRODUCT_ID_WORDS) {
+		vec.push_back(0);
+	}
+
+	int ret = m_pPlc->WriteWordDataEx(m_station, PLC_WORD_DEVICE_TYPE, PLC_PRODUCT_ID_ADDR, vec);
+	if (ret != 0) {
+		CString msg;
+		msg.Format(_T("鍐欏叆浜у搧ID澶辫触锛岄敊璇爜=%d"), ret);
+		LOG_MSG(msg, LOG_TYPE_ERROR);
+		return false;
+	}
+
+	return true;
 }
\ No newline at end of file

--
Gitblit v1.9.3