| | |
| | | std::string strProductID; |
| | | if (ReadProductID(strProductID)) { |
| | | CString msg; |
| | | msg.Format(_T("读取到产品ID:%s"), strProductID.c_str()); |
| | | msg.Format(_T("读取到产品ID:%s"), strProductID); |
| | | LOG_MSG(msg, LOG_TYPE_SUCCESS); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | for (int i = 0; i < PLC_RESULT_ADDR_COUNT; ++i) { |
| | | // 放大100倍并四舍五入,转为PLC整数 |
| | | uint16_t nScaled = static_cast<uint16_t>(std::round(values[i] * 100.0)); |
| | | WordContainer vec = { nScaled }; |
| | | // 放大1000倍并四舍五入,转为PLC整数 |
| | | int32_t nScaled = static_cast<int32_t>(std::round(values[i] * 1000.0)); |
| | | DWordContainer vec = { static_cast<uint32_t>(nScaled) }; |
| | | |
| | | short nTargetAddr = PLC_RESULT_ADDR_START + i * 2; |
| | | int ret = m_pPlc->WriteWordDataEx(m_station, PLC_WORD_DEVICE_TYPE, nTargetAddr, vec); |
| | | int ret = m_pPlc->WriteDWordDataEx(m_station, PLC_WORD_DEVICE_TYPE, nTargetAddr, vec); |
| | | if (ret != 0) { |
| | | CString msg; |
| | | msg.Format(_T("写入OUT%d到地址%d失败,值=%.2f"), i + 1, nTargetAddr, values[i]); |
| | |
| | | } |
| | | |
| | | strProductID.clear(); |
| | | strProductID.reserve(PLC_PRODUCT_ID_WORDS * 2); |
| | | for (auto w : vec) { |
| | | char c1 = static_cast<char>(w & 0xFF); // 低字节 |
| | | char c2 = static_cast<char>((w >> 8) & 0xFF); // 高字节 |
| | |
| | | <PreprocessorDefinitions>_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
| | | <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> |
| | | <AdditionalIncludeDirectories>.;..;.\DLL\64bit;.\CCLinkPerformance;..\MELSECSDK\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
| | | <Optimization>MaxSpeed</Optimization> |
| | | <Optimization>Disabled</Optimization> |
| | | </ClCompile> |
| | | <Link> |
| | | <SubSystem>Windows</SubSystem> |
| | |
| | | <RESOURCE_FILE>SGMeasurement.rc</RESOURCE_FILE> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
| | | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |
| | | <DebuggerFlavor>WindowsRemoteDebugger</DebuggerFlavor> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
| | | <RemoteDebuggerCommand>\\DESKTOP-IODBVIQ\SGMeasurement\$(ProjectName).exe</RemoteDebuggerCommand> |
| | |
| | | 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; |
| | |
| | | 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 }; |
| | | 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 |
| | | } |
| | | |
| | | 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; |