LAPTOP-SNT8I5JK\Boounion
2025-01-09 889044f1c7cdb76254c49dd078fa1ef8e93c3f3a
1.PLC模拟从文件加载,连接;
2.修复内存泄露问题;
已添加1个文件
已修改6个文件
51 ■■■■ 文件已修改
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Model.cpp 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/Model.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/PLC.cpp 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/PLC.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/PagePlcList.cpp 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/x64/BoounionPLC/Debug/Res/logcat_include.ico 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
@@ -358,6 +358,12 @@
        m_pPagePlcList = nullptr;
    }
    
    if (m_pPageLogcat != nullptr) {
        m_pPageLogcat->DestroyWindow();
        delete m_pPageLogcat;
        m_pPageLogcat = nullptr;
    }
    if (m_pMainContainer != nullptr) {
        m_pMainContainer->DestroyWindow();
        delete m_pMainContainer;
@@ -447,14 +453,12 @@
    m_bShowLogWnd = !m_bShowLogWnd;
    if (m_bShowLogWnd) {
        LOGD("显示日志窗口");
        m_pPageLogcat->ShowWindow(SW_SHOW);
        m_pPageLogcat->SetParent(m_pMainContainer);
        m_pMainContainer->SetBottomWnd(m_pPageLogcat, LOG_WND_HEIGHT);
        m_pMainContainer->Resize();
    }
    else {
        LOGD("隐藏日志窗口");
        m_pPageLogcat->ShowWindow(SW_HIDE);
        m_pPageLogcat->SetParent(this);
        m_pMainContainer->SetBottomWnd(nullptr, 0);
SourceCode/Bond/BoounionPLC/Model.cpp
@@ -72,11 +72,19 @@
    g_pModel = this;
    // 模拟从文档或数据库加载PLC列表
    addPlc("Test1", "127.0.0.1", 1001);
    addPlc("Test2", "127.0.0.1", 1002);
    return 0;
}
int CModel::term()
{
    for (auto item : m_mapPlc) {
        item.second->term();
    }
    CLog::GetLog()->SetOnLogCallback(nullptr);
    return 0;
}
@@ -288,10 +296,21 @@
void CModel::onTimer(UINT nTimerid)
{
    static int ii = 0;
    ii++;
    // 检测是否断开,重连
    if (ii % 5 == 0) {
        for (auto item : m_mapPlc) {
            if (!item.second->isConnected()) {
                item.second->connect();
            }
        }
    }
}
std::map<std::string, CPLC*>& CModel::gtPlcMap()
std::map<std::string, CPLC*>& CModel::getPlcMap()
{
    return m_mapPlc;
}
@@ -301,6 +320,7 @@
    auto iter = m_mapPlc.find(pszName);
    if (iter != m_mapPlc.end()) return -1;
    CPLC* pPLC = new CPLC(pszName, pszIp, port);
    pPLC->init();
    m_mapPlc[pszName] = pPLC;
    notifyPtr(RX_CODE_ADD_PLC, pPLC);
SourceCode/Bond/BoounionPLC/Model.h
@@ -16,7 +16,7 @@
    int init();
    int term();
    void onTimer(UINT nTimerid);
    std::map<std::string, CPLC*>& gtPlcMap();
    std::map<std::string, CPLC*>& getPlcMap();
    int addPlc(const char* pszName, const char* pszIp, const unsigned int port);
    int removePlc(const char* pszName);
SourceCode/Bond/BoounionPLC/PLC.cpp
@@ -185,6 +185,13 @@
    return m_pChannel != nullptr && m_pChannel->isConnected();
}
void CPLC::connect()
{
    if (m_pChannel != nullptr && !m_pChannel->isConnected()) {
        m_pChannel->connect();
    }
}
void CPLC::setState(PLCSTATE state)
{
    m_state = state;
SourceCode/Bond/BoounionPLC/PLC.h
@@ -48,6 +48,7 @@
    void sendBroadcast(CComponent* pSender, CIntent* pIntent);
    void onRecvBroadcast(CComponent* pSender, CIntent* pIntent);
    bool isConnected();
    void connect();
    void setActionInterval(unsigned int nInterval);
    std::string& getName();
    std::string& getIp();
SourceCode/Bond/BoounionPLC/PagePlcList.cpp
@@ -174,8 +174,15 @@
void CPagePlcList::ReadPLCList()
{
    //m_treeCtrl.InsertItem("PLC1", nullptr, nullptr);
    //m_treeCtrl.InsertItem("PLC2", nullptr, nullptr);
    std::map<std::string, CPLC*>& plcs = theApp.m_model.getPlcMap();
    for (auto item : plcs) {
        HTREEITEM hItem = m_treeCtrl.InsertItem(item.second->getName().c_str(), nullptr, nullptr);
        m_treeCtrl.SetItemData(hItem, (DWORD_PTR)item.second);
    }
    if (!plcs.empty()) {
        m_treeCtrl.ShowWindow(SW_SHOW);
        GetDlgItem(IDC_LABEL_NO_PLC)->ShowWindow(SW_HIDE);
    }
}
BOOL CPagePlcList::PreTranslateMessage(MSG* pMsg)
SourceCode/Bond/x64/BoounionPLC/Debug/Res/logcat_include.ico