1. SG精度检写入日志文件
2. SG精度检结果可以是负数
3. 添加读取产品ID功能
已修改4个文件
62 ■■■■■ 文件已修改
SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/SGMeasurement/PLCSignalListener.h 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj.user 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/SGMeasurement/PLCSignalListener.cpp
@@ -31,6 +31,10 @@
#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;
@@ -250,6 +254,13 @@
                            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;
@@ -307,3 +318,38 @@
    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;
}
SourceCode/Bond/SGMeasurement/PLCSignalListener.h
@@ -78,6 +78,15 @@
     */
    bool WriteOutValues(const OutValuesArray& values);
    /**
     * @brief 读取 PLC 内部的产品 ID(字符串形式)。
     *
     * @param strProductID  输出参数,存储读取到的产品 ID。
     * @return true         读取成功。
     * @return false        读取失败。
     */
    bool ReadProductID(std::string& strProductID);
private:
    /**
     * @brief 输出日志信息(封装日志回调)。
SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj.user
@@ -4,7 +4,7 @@
    <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>
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
@@ -247,7 +247,7 @@
    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)*/)
@@ -639,7 +639,8 @@
    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);