From 889044f1c7cdb76254c49dd078fa1ef8e93c3f3a Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 09 一月 2025 11:44:23 +0800
Subject: [PATCH] 1.PLC模拟从文件加载,连接; 2.修复内存泄露问题;
---
SourceCode/Bond/BoounionPLC/Model.cpp | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/SourceCode/Bond/BoounionPLC/Model.cpp b/SourceCode/Bond/BoounionPLC/Model.cpp
index e5c97c6..d89bf61 100644
--- a/SourceCode/Bond/BoounionPLC/Model.cpp
+++ b/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);
--
Gitblit v1.9.3