| | |
| | | m_bTrayIconCreated = FALSE; |
| | | } |
| | | |
| | | m_plcListener.Stop(); |
| | | |
| | | DestroyWindow(); |
| | | CDialogEx::OnClose(); |
| | | } |
| | |
| | | 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)*/) |
| | |
| | | |
| | | 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); |
| | |
| | | if (m_nUseTrigger) { |
| | | UpdateControlStatus(m_bConnected, m_bSaving); |
| | | AfxMessageBox(_T("当前是硬触发模式,请检查触发器状态。"), MB_ICONINFORMATION); |
| | | return -1.0f; |
| | | return 0xFF; |
| | | } |
| | | |
| | | if (!m_bConnected) { |
| | | AppendLogLineRichStyled(_T("设备未连接,请先连接设备。"), LOG_COLOR_WARNING); |
| | | return -1.0f; |
| | | return 0xFF; |
| | | } |
| | | |
| | | if (m_bSaving) { |
| | | AppendLogLineRichStyled(_T("数据存储正在进行中,请先停止存储。"), LOG_COLOR_WARNING); |
| | | return -1.0f; |
| | | return 0xFF; |
| | | } |
| | | |
| | | if (nOutNo < 1 || nOutNo > 4) { |
| | | AppendLogLineRichStyled(_T("输出端口编号无效,必须在 1 到 4 之间。"), LOG_COLOR_ERROR); |
| | | return -1.0f; |
| | | return 0xFF; |
| | | } |
| | | |
| | | if (m_nSavePointCount < 0) { |
| | | AppendLogLineRichStyled(_T("数据点数必须大于 0。"), LOG_COLOR_ERROR); |
| | | return -1.0f; |
| | | return 0xFF; |
| | | } |
| | | |
| | | std::vector<float> vecBuffer(m_nSavePointCount, 0.0f); |
| | |
| | | CString strError; |
| | | strError.Format(_T("读取 OUT%d 数据失败,错误码:%#X"), nOutNo, nRet); |
| | | AppendLogLineRichStyled(strError, LOG_COLOR_ERROR); |
| | | return -1.0f; |
| | | return 0xFF; |
| | | } |
| | | |
| | | vecBuffer.resize(nReceived); |
| | |
| | | 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 0xFF; |
| | | } |
| | | |
| | | std::vector<float> vecGlass1Filtered, vecGlass2Filtered; |
| | |
| | | // 初始化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); |
| | | } |
| | | 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>{ 0xFF, 0xFF, 0xFF, 0xFF }; |
| | | } |
| | | |
| | | std::array<double, 4> result; |
| | | for (int i = 0; i < 4; ++i) { |
| | | result[i] = AnalyzeStoredData(i + 1); // OUT1 ~ OUT4 |
| | | } |
| | | |
| | | std::string strProductID; |
| | | m_plcListener.ReadProductID(strProductID); |
| | | m_resultStorage.SaveAnalyzeResult(CString(strProductID.c_str()), result); |
| | | |
| | | 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); |
| | | |
| | |
| | | RC nRet = SGIF_GetCalcDataALL(DeviceID, value); |
| | | if (nRet == RC_OK) { |
| | | for (int i = 0; i < 4; ++i) { |
| | | m_dOutValues[i] = value[i].Value; |
| | | } |
| | | double dNew = value[i].Value; |
| | | if (fabs(m_dOutValues[i] - dNew) > 1e-6) { |
| | | m_dOutValues[i] = dNew; |
| | | |
| | | // 更新绑定控件 |
| | | UpdateData(FALSE); |
| | | CString str; |
| | | str.Format(_T("%.3f"), dNew); |
| | | |
| | | switch (i) { |
| | | case 0: GetDlgItem(IDC_EDIT_OUT1)->SetWindowText(str); break; |
| | | case 1: GetDlgItem(IDC_EDIT_OUT2)->SetWindowText(str); break; |
| | | case 2: GetDlgItem(IDC_EDIT_OUT3)->SetWindowText(str); break; |
| | | case 3: GetDlgItem(IDC_EDIT_OUT4)->SetWindowText(str); break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | CString strError; |