From 6dc80508b1c0f431007f8a8c947c152ec00c3d15 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期一, 08 九月 2025 09:24:05 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp | 62 +++++++++++++++++++++++++++++++
1 files changed, 62 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
index 7529194..a3f8234 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
@@ -130,6 +130,8 @@
m_bTrayIconCreated = FALSE;
}
+ m_plcListener.Stop();
+
DestroyWindow();
CDialogEx::OnClose();
}
@@ -880,6 +882,66 @@
// 鍒濆鍖朓P鍦板潃鎺т欢锛岃缃负榛樿IP鍦板潃
((CIPAddressCtrl*)GetDlgItem(IDC_IPADDRESS))->SetAddress(192, 168, 0, 10);
+ // 璁剧疆 PLC 鐩戝惉鍣ㄧ殑鏃ュ織鍥炶皟鍑芥暟
+ m_plcListener.SetLogCallback([this](const CString& msg, int type) {
+ if (type == -1) {
+ AppendLogLineRichStyled(msg, LOG_COLOR_ERROR);
+ }
+ else if (type == 0) {
+ AppendLogLineRichStyled(msg, LOG_COLOR_SUCCESS);
+ }
+ else if (type == 1) {
+ AppendLogLineRichStyled(msg, LOG_COLOR_WARNING);
+ }
+ else if (type == 2) {
+ AppendLogLineRichStyled(msg, LOG_COLOR_NORMAL);
+ }
+ });
+
+ // 鍒濆鍖� PLC 鐩戝惉鍣�
+ m_plcListener.Initialize(StationIdentifier(0, 255), 200);
+
+ // 璁剧疆 PLC 鐩戝惉鍣ㄧ殑寮�濮嬮噰闆嗗洖璋冨嚱鏁�
+ m_plcListener.SetStartCallback([this]() {
+ if (!m_bConnected) {
+ ConnectToDevice();
+ }
+
+ if (InitDataStorage()) {
+ StartDataStorage();
+ UpdateControlStatus(m_bConnected, m_bSaving);
+ }
+ });
+
+ // 璁剧疆 PLC 鐩戝惉鍣ㄧ殑鍋滄閲囬泦鍥炶皟鍑芥暟
+ m_plcListener.SetStopCallback([this]() {
+ StopDataStorage();
+ UpdateControlStatus(m_bConnected, m_bSaving);
+ });
+
+ // 璁剧疆 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
+ }
+
+ if (std::any_of(result.begin(), result.end(), [](double v) { return v < 0; })) {
+ AppendLogLineRichStyled(_T("鍒嗘瀽澶辫触锛屾煇浜涜緭鍑虹鍙f暟鎹棤鏁堛��"), LOG_COLOR_ERROR);
+ return std::array<double, 4>{ -1.0, -1.0, -1.0, -1.0 };
+ }
+
+ CString strLog;
+ strLog.Format(_T("鍒嗘瀽缁撴灉锛歄UT1: %.3f, OUT2: %.3f, OUT3: %.3f, OUT4: %.3f"), result[0], result[1], result[2], result[3]);
+ return result;
+ });
+ m_plcListener.Start();
+
// 鍒濆鍖栨棩蹇楁
AppendLogLineRichStyled(_T("鍑嗗灏辩华..."), LOG_COLOR_SUCCESS);
--
Gitblit v1.9.3