From a3943d169515d841e70c57703cbd9fcbf5409a5a Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期一, 04 八月 2025 17:59:52 +0800
Subject: [PATCH] 1. SGMeasurement模块添加CC-Link通信 2. SGMeasurement模块添加PLC交互
---
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
index 7529194..94363a7 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,56 @@
// 鍒濆鍖朓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);
+ }
+ if (type == 0) {
+ AppendLogLineRichStyled(msg, LOG_COLOR_SUCCESS);
+ }
+ else if (type == 1) {
+ AppendLogLineRichStyled(msg, LOG_COLOR_WARNING);
+ }
+ else {
+ AppendLogLineRichStyled(msg, LOG_COLOR_NORMAL);
+ }
+ });
+
+ // 鍒濆鍖� PLC 鐩戝惉鍣�
+ m_plcListener.Initialize(StationIdentifier(0, 255), 200);
+
+ // 璁剧疆 PLC 鐩戝惉鍣ㄧ殑寮�濮嬮噰闆嗗洖璋冨嚱鏁�
+ m_plcListener.SetStartCallback([this]() {
+ InitDataStorage();
+ StartDataStorage();
+ UpdateControlStatus(m_bConnected, m_bSaving);
+ });
+
+ // 璁剧疆 PLC 鐩戝惉鍣ㄧ殑鍋滄閲囬泦鍥炶皟鍑芥暟
+ m_plcListener.SetStopCallback([this]() {
+ StopDataStorage();
+ UpdateControlStatus(m_bConnected, m_bSaving);
+ });
+
+ // 璁剧疆 PLC 鐩戝惉鍣ㄧ殑鍒嗘瀽鍥炶皟鍑芥暟
+ m_plcListener.SetAnalyzeCallback([this]() {
+ 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