1.PLC模拟从文件加载,连接;
2.修复内存泄露问题;
| | |
| | | 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; |
| | |
| | | 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); |
| | |
| | | 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; |
| | | } |
| | |
| | | |
| | | 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; |
| | | } |
| | |
| | | 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); |
| | |
| | | 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); |
| | | |
| | |
| | | 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; |
| | |
| | | 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(); |
| | |
| | | |
| | | 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) |