mrDarker
2025-08-04 a3943d169515d841e70c57703cbd9fcbf5409a5a
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
@@ -130,6 +130,8 @@
      m_bTrayIconCreated = FALSE;
   }
   m_plcListener.Stop();
   DestroyWindow();
   CDialogEx::OnClose();
}
@@ -880,6 +882,56 @@
   // 初始化IP地址控件,设置为默认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("分析失败,某些输出端口数据无效。"), LOG_COLOR_ERROR);
         return std::array<double, 4>{ -1.0, -1.0, -1.0, -1.0 };
      }
      CString strLog;
      strLog.Format(_T("分析结果:OUT1: %.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);