1. SG精度检写入日志文件
2. SG精度检结果可以是负数
3. 添加读取产品ID功能
| | |
| | | #define PLC_RESULT_ADDR_START 0x37B0 // PLC结果寄存器起始地址(如W37B0) |
| | | #define PLC_RESULT_ADDR_COUNT 4 // 结果寄存器数量(如W37B0, W37B2, W37B4, W37B6) |
| | | |
| | | // === PLC 产品ID配置(PLC -> PC)=== |
| | | #define PLC_PRODUCT_ID_ADDR 0x1B160 // 产品ID起始地址 (W1B160) |
| | | #define PLC_PRODUCT_ID_WORDS 10 // 产品ID长度(10个Word) |
| | | |
| | | #define IS_RISING_EDGE(prev, curr) (!(prev) && (curr)) |
| | | |
| | | CPLCSignalListener::CPLCSignalListener() = default; |
| | |
| | | m_vecAckSent[i] = true; |
| | | m_vecAckCounter[i] = 0; |
| | | } |
| | | |
| | | std::string strProductID; |
| | | if (ReadProductID(strProductID)) { |
| | | CString msg; |
| | | msg.Format(_T("读取到产品ID:%s"), strProductID.c_str()); |
| | | LOG_MSG(msg, LOG_TYPE_SUCCESS); |
| | | } |
| | | } |
| | | break; |
| | | |
| | |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | bool CPLCSignalListener::ReadProductID(std::string& strProductID) |
| | | { |
| | | if (!m_pPlc || !m_bConnected) { |
| | | LOG_MSG(_T("PLC未连接或未初始化,无法读取产品ID。"), LOG_TYPE_ERROR); |
| | | return false; |
| | | } |
| | | |
| | | WordContainer vec; |
| | | int ret = m_pPlc->ReadWordDataEx(m_station, PLC_WORD_DEVICE_TYPE, PLC_PRODUCT_ID_ADDR, PLC_PRODUCT_ID_WORDS, vec); |
| | | if (ret != 0 || vec.size() != PLC_PRODUCT_ID_WORDS) { |
| | | CString msg; |
| | | msg.Format(_T("读取产品ID失败,错误码=%d"), ret); |
| | | LOG_MSG(msg, LOG_TYPE_ERROR); |
| | | return false; |
| | | } |
| | | |
| | | strProductID.clear(); |
| | | for (auto w : vec) { |
| | | char c1 = static_cast<char>(w & 0xFF); // 低字节 |
| | | char c2 = static_cast<char>((w >> 8) & 0xFF); // 高字节 |
| | | |
| | | if (c1 == '\0') { |
| | | break; |
| | | } |
| | | strProductID.push_back(c1); |
| | | |
| | | if (c2 == '\0') { |
| | | break; |
| | | } |
| | | strProductID.push_back(c2); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | |
| | | */ |
| | | bool WriteOutValues(const OutValuesArray& values); |
| | | |
| | | /** |
| | | * @brief 读取 PLC 内部的产品 ID(字符串形式)。 |
| | | * |
| | | * @param strProductID 输出参数,存储读取到的产品 ID。 |
| | | * @return true 读取成功。 |
| | | * @return false 读取失败。 |
| | | */ |
| | | bool ReadProductID(std::string& strProductID); |
| | | |
| | | private: |
| | | /** |
| | | * @brief 输出日志信息(封装日志回调)。 |
| | |
| | | <RESOURCE_FILE>SGMeasurement.rc</RESOURCE_FILE> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
| | | <DebuggerFlavor>WindowsRemoteDebugger</DebuggerFlavor> |
| | | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
| | | <RemoteDebuggerCommand>\\DESKTOP-IODBVIQ\SGMeasurement\$(ProjectName).exe</RemoteDebuggerCommand> |
| | |
| | | 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); |
| | |
| | | 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; |