LAPTOP-SNT8I5JK\Boounion
2025-10-14 cfcab53b0e7d5918c79cc77f0f447730682f94b1
1.glass, 保存csv
已修改5个文件
426 ■■■■ 文件已修改
SourceCode/Bond/Servo/CMaster.cpp 47 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPageGlassList.cpp 301 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CPageGlassList.h 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CServoUtilsTool.cpp 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CServoUtilsTool.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CMaster.cpp
@@ -6,35 +6,10 @@
#include "RecipeManager.h"
#include <fstream>
#include "SerializeUtil.h"
#include "CServoUtilsTool.h"
namespace SERVO {
    static std::unordered_map<int, std::vector<std::string>> MACHINE_DATA_TYPES = {
    {EQ_ID_Bonder1, {
        "气囊压力", "上腔压力", "管道真空规值", "腔体真空规值",
        "上腔温度1", "上腔温度2", "上腔温度3", "上腔温度4",
        "上腔温度5", "上腔温度6", "下腔温度1", "下腔温度2",
        "下腔温度3", "下腔温度4", "下腔温度5", "下腔温度6"
    }},
    {EQ_ID_Bonder2, {
        "气囊压力", "上腔压力", "管道真空规值", "腔体真空规值",
        "上腔温度1", "上腔温度2", "上腔温度3", "上腔温度4",
        "上腔温度5", "上腔温度6", "下腔温度1", "下腔温度2",
        "下腔温度3", "下腔温度4", "下腔温度5", "下腔温度6"
    }},
    {EQ_ID_VACUUMBAKE, {
        "A腔真空规值", "A腔温控1", "A腔温控2", "A腔温控4",
        "A腔温控5", "A腔温控6", "A腔温控7", "B腔真空规值",
        "B腔温控1", "B腔温控2", "B腔温控4", "B腔温控5",
        "B腔温控6", "B腔温控7"
    }},
    {EQ_ID_BAKE_COOLING, {
        "A烘烤温控1", "A烘烤温控2", "A烘烤温控4", "A烘烤温控5",
        "A烘烤温控6", "A烘烤温控7", "B烘烤温控1", "B烘烤温控2",
        "B烘烤温控4", "B烘烤温控5", "B烘烤温控6", "B烘烤温控7"
    }}
    };
    static inline int64_t now_ms_epoch() {
        using namespace std::chrono;
        return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
@@ -1662,7 +1637,8 @@
                };
                CGlass* pGlass = ((CEquipment*)pEquipment)->getGlassFromSlot(0);
                auto& bonderTypes = MACHINE_DATA_TYPES[eqid];
                auto& dataTypes = CServoUtilsTool::getEqDataTypes();
                auto& bonderTypes = dataTypes[eqid];
                for (const auto& mapping : bonderMapping) {
                    int paramIndex = mapping.first;
                    int channel = mapping.second;
@@ -1683,16 +1659,17 @@
                };
                CGlass* pGlass = ((CEquipment*)pEquipment)->getGlassFromSlot(0);
                auto& bonderTypes = MACHINE_DATA_TYPES[eqid];
                auto& dataTypes = CServoUtilsTool::getEqDataTypes();
                auto& vacuumbakeTypes = dataTypes[eqid];
                for (const auto& mapping : vacuumMapping) {
                    int paramIndex = mapping.first;
                    int channel = mapping.second;
                    if (paramIndex < params.size() && channel - 1 < bonderTypes.size()) {
                    if (paramIndex < params.size() && channel - 1 < vacuumbakeTypes.size()) {
                        if (m_pCollector != nullptr)
                            m_pCollector->buffersPush(eqid, channel, ts, params.at(paramIndex).getDoubleValue());
                        if (pGlass != nullptr)
                            pGlass->addSVData(eqid, bonderTypes[channel], ts, params.at(paramIndex).getDoubleValue());
                            pGlass->addSVData(eqid, vacuumbakeTypes[channel], ts, params.at(paramIndex).getDoubleValue());
                    }
                }
            }
@@ -1704,7 +1681,8 @@
                };
                CGlass* pGlass = ((CEquipment*)pEquipment)->getGlassFromSlot(0);
                auto& coolingTypes = MACHINE_DATA_TYPES[eqid];
                auto& dataTypes = CServoUtilsTool::getEqDataTypes();
                auto& coolingTypes = dataTypes[eqid];
                for (const auto& mapping : coolingMapping) {
                    int paramIndex = mapping.first;
                    int channel = mapping.second;
@@ -3161,18 +3139,19 @@
            // 2) 为通道设置“曲线名称”
            auto& bonderTypes = MACHINE_DATA_TYPES[EQ_ID_Bonder1];
            auto& dataTypes = CServoUtilsTool::getEqDataTypes();
            auto& bonderTypes = dataTypes[EQ_ID_Bonder1];
            for (size_t i = 0; i < bonderTypes.size(); ++i) {
                m_pCollector->buffersSetChannelName(EQ_ID_Bonder1, i + 1, bonderTypes[i].c_str());
                m_pCollector->buffersSetChannelName(EQ_ID_Bonder2, i + 1, bonderTypes[i].c_str());
            }
            auto& vacuumbakeTypes = MACHINE_DATA_TYPES[EQ_ID_VACUUMBAKE];
            auto& vacuumbakeTypes = dataTypes[EQ_ID_VACUUMBAKE];
            for (size_t i = 0; i < bonderTypes.size(); ++i) {
                m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, i + 1, vacuumbakeTypes[i].c_str());
            }
            auto& coolingTypes = MACHINE_DATA_TYPES[EQ_ID_BAKE_COOLING];
            auto& coolingTypes = dataTypes[EQ_ID_BAKE_COOLING];
            for (size_t i = 0; i < bonderTypes.size(); ++i) {
                m_pCollector->buffersSetChannelName(EQ_ID_VACUUMBAKE, i + 1, coolingTypes[i].c_str());
            }
SourceCode/Bond/Servo/CPageGlassList.cpp
@@ -1347,98 +1347,210 @@
    CString fileExt = fileDialog.GetFileExt();
    if (fileExt.CompareNoCase(_T("json")) == 0) {
        // 保存为 JSON
        if (!row->pretty.empty()) {
            CFile file;
            if (file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) {
                file.Write(row->pretty.c_str(), row->pretty.length());
                file.Close();
                CString strSuccess;
                strSuccess.Format(_T("记录已保存为JSON文件:\n%s"), filePath);
                AfxMessageBox(strSuccess);
            }
            else {
                AfxMessageBox(_T("保存文件失败"));
            }
        }
        else {
            AfxMessageBox(_T("该记录没有JSON数据"));
        }
        ExportToJson(*row, filePath);
    }
    else {
        // 保存为 CSV 格式 - 分段式
        CString csvContent;
        ExportToCsv(*row, filePath);
    }
}
        // === 第一部分:基础信息 ===
        csvContent += _T("=== 基础信息 ===\n");
        csvContent += _T("ID,Cassette序列号,Job序列号,Glass ID,物料类型,状态,开始时间,结束时间,绑定Glass ID,AOI结果,路径\n");
void CPageGlassList::ExportToJson(const GlassLogDb::Row& row, const CString& filePath)
{
    // 保存为 JSON
    if (!row.pretty.empty()) {
        CFile file;
        if (file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) {
            file.Write(row.pretty.c_str(), row.pretty.length());
            file.Close();
        CString baseInfoRow;
        baseInfoRow.Format(_T("%lld,%d,%d,%s,%d,%d,%s,%s,%s,%d,%s\n"),
            row->id, row->cassetteSeqNo, row->jobSeqNo,
            CString(row->classId.c_str()), row->materialType, row->state,
            CString(row->tStart.c_str()), CString(row->tEnd.c_str()),
            CString(row->buddyId.c_str()), row->aoiResult,
            CString(row->path.c_str()));
        csvContent += baseInfoRow;
        // === 第二部分:工艺参数 ===
        csvContent += _T("\n=== 工艺参数 ===\n");
        // 如果有 pretty 字段,解析工艺参数
        if (!row->pretty.empty()) {
            SERVO::CGlass tempGlass;
            if (GlassJson::FromString(row->pretty, tempGlass)) {
                auto& params = tempGlass.getParams();
                if (!params.empty()) {
                    // 工艺参数表头 - 调整后的列
                    csvContent += _T("参数名称,参数ID,数值,机器单元\n");
                    // 工艺参数数据 - 调整后的格式
                    for (auto& param : params) {
                        CString paramRow;
                        CString valueStr;
                        // 根据参数类型格式化数值
                        if (param.getValueType() == PVT_INT) {
                            valueStr.Format(_T("%d"), param.getIntValue());
                        }
                        else {
                            valueStr.Format(_T("%.3f"), param.getDoubleValue());
                        }
                        // 调整后的格式:去掉数值类型列
                        paramRow.Format(_T("%s,%s,%s,%s\n"),
                            CString(param.getName().c_str()),
                            CString(param.getId().c_str()),
                            valueStr,
                            CString(param.getUnit().c_str())); // 这里显示机器单元
                        csvContent += paramRow;
                    }
                }
                else {
                    csvContent += _T("无工艺参数数据\n");
                }
            }
            else {
                csvContent += _T("无法解析工艺参数\n");
            }
        }
        else {
            csvContent += _T("无工艺参数数据\n");
        }
        // 使用辅助函数保存为 UTF-8 编码
        if (WriteAnsiStringAsUtf8ToFile(csvContent, filePath)) {
            CString strSuccess;
            strSuccess.Format(_T("记录已保存为CSV文件:\n%s"), filePath);
            strSuccess.Format(_T("记录已保存为JSON文件:\n%s"), filePath);
            AfxMessageBox(strSuccess);
        }
        else {
            AfxMessageBox(_T("保存文件失败"));
        }
    }
    else {
        AfxMessageBox(_T("该记录没有JSON数据"));
    }
}
void CPageGlassList::ExportToCsv(const GlassLogDb::Row& row, const CString& filePath)
{
    CString csvContent;
    // === 第一部分:基础信息 ===
    ExportBasicInfo(csvContent, row);
    // === 第二部分:工艺参数 ===
    ExportProcessParams(csvContent, row);
    // === 第三部分:传感器数据详情 ===
    ExportSensorData(csvContent, row);
    // 使用辅助函数保存为 UTF-8 编码
    if (WriteAnsiStringAsUtf8ToFile(csvContent, filePath)) {
        CString strSuccess;
        strSuccess.Format(_T("记录已保存为CSV文件:\n%s"), filePath);
        AfxMessageBox(strSuccess);
    }
    else {
        AfxMessageBox(_T("保存文件失败"));
    }
}
void CPageGlassList::ExportBasicInfo(CString& csvContent, const GlassLogDb::Row& row)
{
    csvContent += _T("=== 基础信息 ===\n");
    csvContent += _T("ID,Cassette序列号,Job序列号,Glass ID,物料类型,状态,开始时间,结束时间,绑定Glass ID,AOI结果,路径\n");
    CString baseInfoRow;
    baseInfoRow.Format(_T("%lld,%d,%d,%s,%d,%d,%s,%s,%s,%d,%s\n"),
        row.id, row.cassetteSeqNo, row.jobSeqNo,
        CString(row.classId.c_str()), row.materialType, row.state,
        CString(row.tStart.c_str()), CString(row.tEnd.c_str()),
        CString(row.buddyId.c_str()), row.aoiResult,
        CString(row.path.c_str()));
    csvContent += baseInfoRow;
}
void CPageGlassList::ExportProcessParams(CString& csvContent, const GlassLogDb::Row& row)
{
    csvContent += _T("\n=== 工艺参数 ===\n");
    // 如果有 pretty 字段,解析工艺参数
    if (!row.pretty.empty()) {
        SERVO::CGlass tempGlass;
        if (GlassJson::FromString(row.pretty, tempGlass)) {
            auto& params = tempGlass.getParams();
            if (!params.empty()) {
                // 工艺参数表头
                csvContent += _T("参数名称,参数ID,数值,机器单元\n");
                // 工艺参数数据
                for (auto& param : params) {
                    CString paramRow;
                    CString valueStr;
                    // 根据参数类型格式化数值
                    if (param.getValueType() == PVT_INT) {
                        valueStr.Format(_T("%d"), param.getIntValue());
                    }
                    else {
                        valueStr.Format(_T("%.3f"), param.getDoubleValue());
                    }
                    paramRow.Format(_T("%s,%s,%s,%s\n"),
                        CString(param.getName().c_str()),
                        CString(param.getId().c_str()),
                        valueStr,
                        CString(param.getUnit().c_str()));
                    csvContent += paramRow;
                }
            }
            else {
                csvContent += _T("无工艺参数数据\n");
            }
        }
        else {
            csvContent += _T("无法解析工艺参数\n");
        }
    }
    else {
        csvContent += _T("无工艺参数数据\n");
    }
}
void CPageGlassList::ExportSensorData(CString& csvContent, const GlassLogDb::Row& row)
{
    csvContent += _T("\n=== 传感器数据详情 ===\n");
    // 如果有 pretty 字段,解析传感器数据
    if (!row.pretty.empty()) {
        SERVO::CGlass tempGlass;
        if (GlassJson::FromString(row.pretty, tempGlass)) {
            // 对每个机器生成表格
            for (const auto& machinePair : tempGlass.getAllSVData()) {
                int machineId = machinePair.first;
                CString machineName = CString(SERVO::CServoUtilsTool::getEqName(machineId).c_str());
                csvContent += _T("\n[") + machineName + _T("]\n");
                // 获取该机器的预定义列顺序
                auto columnOrder = getMachineColumnOrder(machineId);
                if (columnOrder.empty()) {
                    csvContent += _T("无预定义列配置\n");
                    continue;
                }
                // 构建表头 - 直接使用中文列名
                CString header = _T("时间戳(ms),本地时间");
                for (const auto& dataType : columnOrder) {
                    header += _T(",");
                    header += CString(dataType.c_str()); // 直接使用中文列名
                }
                header += _T("\n");
                csvContent += header;
                // 检查是否有数据
                if (machinePair.second.empty()) {
                    csvContent += _T("无传感器数据\n");
                    continue;
                }
                // 使用第一个数据类型的时间序列作为基准
                const std::string& firstDataType = columnOrder[0];
                auto firstDataTypeIt = machinePair.second.find(firstDataType);
                if (firstDataTypeIt == machinePair.second.end() || firstDataTypeIt->second.empty()) {
                    csvContent += _T("无基准数据类型数据\n");
                    continue;
                }
                const auto& timeSeries = firstDataTypeIt->second;
                // 对于每个时间点,输出一行数据
                for (size_t i = 0; i < timeSeries.size(); i++) {
                    auto timestamp = timeSeries[i].timestamp;
                    // 时间戳(毫秒)
                    auto ms = timePointToMs(timestamp);
                    CString row;
                    row.Format(_T("%lld,"), ms);
                    // 本地时间字符串
                    CString localTime = CString(timePointToString(timestamp).c_str());
                    row += localTime;
                    // 按照预定义的列顺序输出数据
                    for (const auto& dataType : columnOrder) {
                        row += _T(",");
                        auto dataTypeIt = machinePair.second.find(dataType);
                        if (dataTypeIt != machinePair.second.end() && i < dataTypeIt->second.size()) {
                            // 直接按索引获取数据
                            CString valueStr;
                            valueStr.Format(_T("%.3f"), dataTypeIt->second[i].value);
                            row += valueStr;
                        }
                        else {
                            // 理论上不应该发生,因为您说没有空值
                            row += _T("N/A");
                        }
                    }
                    row += _T("\n");
                    csvContent += row;
                }
            }
        }
        else {
            csvContent += _T("无法解析传感器数据\n");
        }
    }
    else {
        csvContent += _T("无传感器数据\n");
    }
}
@@ -1797,4 +1909,29 @@
    }
    return CDialogEx::PreTranslateMessage(pMsg);
}
// 获取机器预定义的列顺序
std::vector<std::string> CPageGlassList::getMachineColumnOrder(int machineId)
{
    auto dataTypes = SERVO::CServoUtilsTool::getEqDataTypes();
    auto it = dataTypes.find(machineId);
    return it != dataTypes.end() ? it->second : std::vector<std::string>();
}
// 时间戳转换为字符串
std::string CPageGlassList::timePointToString(const std::chrono::system_clock::time_point& tp)
{
    auto time_t = std::chrono::system_clock::to_time_t(tp);
    std::tm tm;
    localtime_s(&tm, &time_t);
    char buffer[20];
    std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm);
    return buffer;
}
// 时间戳转换为毫秒
int64_t CPageGlassList::timePointToMs(const std::chrono::system_clock::time_point& tp)
{
    return std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch()).count();
}
SourceCode/Bond/Servo/CPageGlassList.h
@@ -56,6 +56,14 @@
    bool eraseGlassInVector(SERVO::CGlass* pGlass, std::vector<SERVO::CGlass*>& glasses);
    void UpdateWipRow(unsigned int index, SERVO::CGlass* pGlass);
    bool WriteAnsiStringAsUtf8ToFile(const CString& ansiContent, const CString& filePath);
    void ExportToCsv(const GlassLogDb::Row& row, const CString& filePath);
    void ExportToJson(const GlassLogDb::Row& row, const CString& filePath);
    void ExportBasicInfo(CString& csvContent, const GlassLogDb::Row& row);
    void ExportProcessParams(CString& csvContent, const GlassLogDb::Row& row);
    void ExportSensorData(CString& csvContent, const GlassLogDb::Row& row);
    static std::vector<std::string> getMachineColumnOrder(int machineId);
    static std::string timePointToString(const std::chrono::system_clock::time_point& tp);
    static int64_t timePointToMs(const std::chrono::system_clock::time_point& tp);
// 对话框数据
#ifdef AFX_DESIGN_TIME
SourceCode/Bond/Servo/CServoUtilsTool.cpp
@@ -4,6 +4,32 @@
namespace SERVO {
    static std::unordered_map<int, std::vector<std::string>> EQ_DATA_TYPES = {
        {EQ_ID_Bonder1, {
            "气囊压力", "上腔压力", "管道真空规值", "腔体真空规值",
            "上腔温度1", "上腔温度2", "上腔温度3", "上腔温度4",
            "上腔温度5", "上腔温度6", "下腔温度1", "下腔温度2",
            "下腔温度3", "下腔温度4", "下腔温度5", "下腔温度6"
        }},
        {EQ_ID_Bonder2, {
            "气囊压力", "上腔压力", "管道真空规值", "腔体真空规值",
            "上腔温度1", "上腔温度2", "上腔温度3", "上腔温度4",
            "上腔温度5", "上腔温度6", "下腔温度1", "下腔温度2",
            "下腔温度3", "下腔温度4", "下腔温度5", "下腔温度6"
        }},
        {EQ_ID_VACUUMBAKE, {
            "A腔真空规值", "A腔温控1", "A腔温控2", "A腔温控4",
            "A腔温控5", "A腔温控6", "A腔温控7", "B腔真空规值",
            "B腔温控1", "B腔温控2", "B腔温控4", "B腔温控5",
            "B腔温控6", "B腔温控7"
        }},
        {EQ_ID_BAKE_COOLING, {
            "A烘烤温控1", "A烘烤温控2", "A烘烤温控4", "A烘烤温控5",
            "A烘烤温控6", "A烘烤温控7", "B烘烤温控1", "B烘烤温控2",
            "B烘烤温控4", "B烘烤温控5", "B烘烤温控6", "B烘烤温控7"
        }}
    };
    CServoUtilsTool::CServoUtilsTool()
    {
@@ -12,6 +38,43 @@
    CServoUtilsTool::~CServoUtilsTool()
    {
    }
    std::string CServoUtilsTool::getEqName(int eqid)
    {
        switch (eqid)
        {
        case EQ_ID_LOADPORT1:
            return "Port1";
        case EQ_ID_LOADPORT2:
            return "Port2";
        case EQ_ID_LOADPORT3:
            return "Port3";
        case EQ_ID_LOADPORT4:
            return "Port4";
        case EQ_ID_ALIGNER:
            return "Aligner";
        case EQ_ID_FLIPER:
            return "Fliper";
        case EQ_ID_VACUUMBAKE:
            return "VacuumBake";
        case EQ_ID_Bonder1:
            return "Bonder1";
        case EQ_ID_Bonder2:
            return "Bonder2";
        case EQ_ID_BAKE_COOLING:
            return "BakeCooling";
        case EQ_ID_MEASUREMENT:
            return "AOI";
        case EQ_ID_ARM_TRAY1:
            return "ArmTray1";
        case EQ_ID_ARM_TRAY2:
            return "ArmTray2";
        default:
            break;
        }
        return "";
    }
    std::string CServoUtilsTool::getEqUnitName(int eqid, int unit)
@@ -198,4 +261,9 @@
            break;
        }
    }
    std::unordered_map<int, std::vector<std::string>>& CServoUtilsTool::getEqDataTypes()
    {
        return EQ_DATA_TYPES;
    }
}
SourceCode/Bond/Servo/CServoUtilsTool.h
@@ -11,11 +11,13 @@
        virtual ~CServoUtilsTool();
    public:
        static std::string getEqName(int eqid);
        static std::string getEqUnitName(int eqid, int unit);
        static std::string getEqUnitName(int eqid, int unit, int slot);
        static std::string getMaterialsTypeText(MaterialsType type);
        static std::string getGlassStateText(SERVO::GlsState state);
        static std::string getInspResultText(SERVO::InspResult result);
        static std::unordered_map<int, std::vector<std::string>>& getEqDataTypes();
    };
}