From d64036c0510cf06009a7252e318d828fbc2658f0 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 11 九月 2025 09:22:02 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp | 71 +++++++++++++++++++++++++++++++++--
1 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
index 7529194..dcf3a01 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();
}
@@ -245,7 +247,7 @@
strFullLogLine.Format(_T("%s %s"), strLevel, strContent);
// 鍐欏叆鏃ュ織鏂囦欢
- // LOG_LINE(strFullLogLine);
+ LOG_LINE(strFullLogLine);
}
void CSGMeasurementDlg::HighlightAllMatches(const CString& strSearch, COLORREF clrHighlight/* = RGB(255, 165, 0)*/)
@@ -637,7 +639,8 @@
fAvg1 = CalcAverage(vecGlass1);
fAvg2 = CalcAverage(vecGlass2);
- fOffset = std::fabs(fAvg2 - fAvg1); // 绗簩鐗� - 绗竴鐗�
+ fOffset = fAvg2 - fAvg1; // 绗簩鐗� - 绗竴鐗�
+ //fOffset = std::fabs(fAvg2 - fAvg1); // 绗簩鐗� - 绗竴鐗�
CString strLog;
strLog.Format(_T("绗竴鐗囩幓鐠冨钩鍧囧��: %.3f锛岀浜岀墖鐜荤拑骞冲潎鍊�: %.3f锛屽亸绉婚噺: %.3f"), fAvg1, fAvg2, fOffset);
@@ -758,10 +761,10 @@
vecBuffer.resize(nReceived);
CleanInvalidValuesInPlace(nOutNo, vecBuffer);
- std::vector<float> vecGlass1, vecGlass2;
+ std::vector<float> vecGlass1, vecGlass2;
if (!SplitGlassSegments(nOutNo, vecBuffer, vecGlass1, vecGlass2, m_fJumpThreshold, m_nJumpWindow, m_nValleyMargin, m_nMinGlass1Count)) {
AppendLogLineRichStyled(_T("鏈兘璇嗗埆鍑轰袱鐗囩幓鐠冪殑鏁版嵁銆�"), LOG_COLOR_WARNING);
- return -1.0f;
+ return -1.0f;
}
std::vector<float> vecGlass1Filtered, vecGlass2Filtered;
@@ -880,6 +883,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