From 829fe6c6bc33d53fda9c31fd45a37e1df87befff Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 30 一月 2026 11:16:24 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp b/SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp
index ab32e61..93660d0 100644
--- a/SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp
+++ b/SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp
@@ -255,7 +255,7 @@
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);
}
}
@@ -309,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;
}
@@ -360,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