From 0ba3414c4745224a7ee6f68fbc640bf74e3ee87d Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期四, 09 一月 2025 15:30:20 +0800
Subject: [PATCH] 1. 获取PLC数据更新CPlcView 2. 修复删除节点
---
SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp | 2
SourceCode/Bond/BoounionPLC/Model.cpp | 126 ++++++++++++++++++++++++++++++++++++++++++
SourceCode/Bond/BoounionPLC/Model.h | 14 ++++
SourceCode/Bond/BoounionPLC/PagePlcList.cpp | 3
4 files changed, 144 insertions(+), 1 deletions(-)
diff --git a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
index d31d1c0..2d941e7 100644
--- a/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
+++ b/SourceCode/Bond/BoounionPLC/BoounionPLCDlg.cpp
@@ -123,6 +123,8 @@
m_pActiveView->SetContext(pPlc);
m_pActiveView->SendMessage(WM_NCPAINT, 0, 0);
}
+
+ theApp.m_model.setCurrentPlc(pPlc);
}
}
else if (code == RX_CODE_ALARM_ON) {
diff --git a/SourceCode/Bond/BoounionPLC/Model.cpp b/SourceCode/Bond/BoounionPLC/Model.cpp
index d89bf61..b915b33 100644
--- a/SourceCode/Bond/BoounionPLC/Model.cpp
+++ b/SourceCode/Bond/BoounionPLC/Model.cpp
@@ -2,7 +2,10 @@
#include "Model.h"
#include "Log.h"
#include "Common.h"
+#include "ToolUnits.h"
+// 常量
+#define ADDR_NIGHT_SHIFT_CAPACTITY 2027
CModel* g_pModel = NULL;
void CALLBACK ModerTimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime)
@@ -335,5 +338,128 @@
notifyPtr(RX_CODE_REMOVE_PLC, iter->second);
delete iter->second;
m_mapPlc.erase(iter);
+
+ m_strCurrPlc = "";
return 0;
}
+
+void CModel::setCurrentPlc(CPLC* pPlc)
+{
+ if (pPlc != nullptr) {
+ m_strCurrPlc = pPlc->getName();
+ }
+}
+
+CPLC* CModel::getCurrentPlc()
+{
+ auto item = m_mapPlc.find(m_strCurrPlc);
+ if (item != m_mapPlc.end()) {
+ return item->second;
+ }
+
+ return nullptr;
+}
+
+void CModel::readPLCDataRegularly()
+{
+ CPLC* pPlc = getCurrentPlc();
+ if (pPlc == nullptr || !pPlc->isConnected()) return;
+
+ {
+ auto funOnReadData = [this](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) -> void {
+ if (nDataSize == 2 && flag == 0) {
+ int nVelocityRatio = CToolUnits::toInt16(&pData[0]);
+ if (nVelocityRatio != m_nVelocityRatio) {
+ m_nVelocityRatio = nVelocityRatio;
+ notifyInt(RX_CODE_VELOCITY_RATIO, m_nVelocityRatio);
+ }
+ }
+ };
+ pPlc->readData(MC::D, 530, 2, funOnReadData);
+ }
+
+ {
+ auto funOnReadData = [this](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) -> void {
+ if (nDataSize == 2 && flag == 0) {
+ double dTactTime = (double)CToolUnits::toInt16(&pData[0]);
+ if (dTactTime != m_dTactTime) {
+ m_dTactTime = dTactTime;
+ notifyDouble(RX_CODE_TACT_TIME, m_dTactTime);
+ }
+ }
+ };
+ pPlc->readData(MC::ZR, 1500, 2, funOnReadData);
+ }
+
+ {
+ auto funOnReadData = [this](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) -> void {
+ if (nDataSize == (ADDR_NIGHT_SHIFT_CAPACTITY - 2012 + 1) * 2 && flag == 0) {
+ int nDayShiftCapacity = CToolUnits::toInt16(&pData[0]);
+ int nNightShiftCapacity = CToolUnits::toInt16(&pData[(ADDR_NIGHT_SHIFT_CAPACTITY - 2012) * 2]);
+ if (nDayShiftCapacity != m_nDayShiftCapacity) {
+ m_nDayShiftCapacity = nDayShiftCapacity;
+ notifyInt(RX_CODE_DAY_SHIFT_CAPACTITY, nDayShiftCapacity);
+ }
+ if (nNightShiftCapacity != m_nNightShiftCapacity) {
+ m_nNightShiftCapacity = nNightShiftCapacity;
+ notifyInt(RX_CODE_NIGHT_SHIFT_CAPACTITY, nNightShiftCapacity);
+ }
+
+ }
+ };
+ pPlc->readData(MC::ZR, 2012, (ADDR_NIGHT_SHIFT_CAPACTITY - 2012 + 1) * 2, funOnReadData);
+ }
+
+ {
+ int nStartAddress = 1000;
+ int nEndAddress = 1200;
+ int nReadSize = (nEndAddress - nStartAddress + 1) * 2;
+ auto funOnReadData = [this, nStartAddress, nReadSize](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) -> void {
+ if (nDataSize == nReadSize && flag == 0) {
+ bool bRun = CToolUnits::toInt16(&pData[(1103 - nStartAddress) * 2]) != 0; // 启动
+ bool bAuto = CToolUnits::toInt16(&pData[(1100 - nStartAddress) * 2]) != 0; // 自动
+ bool bPuase = CToolUnits::toInt16(&pData[(1104 - nStartAddress) * 2]) != 0; // 暂停
+ bool bManual = CToolUnits::toInt16(&pData[(1100 - nStartAddress) * 2]) != 0; // 手动
+ bool bBeep = CToolUnits::toInt16(&pData[(1003 - nStartAddress) * 2]) != 0; // 静音
+ bool bResetting = CToolUnits::toInt16(&pData[(1150 - nStartAddress) * 2]) != 0; // 复位
+ bool bStop = CToolUnits::toInt16(&pData[(1114 - nStartAddress) * 2]) != 0; // 停止
+
+ if (m_bBlBtnsStates[0] != bRun) {
+ m_bBlBtnsStates[0] = bRun;
+ notifyInt(RX_CODE_ACTIVATE, bRun);
+ }
+
+ if (m_bBlBtnsStates[1] != bAuto) {
+ m_bBlBtnsStates[1] = bAuto;
+ notifyInt(RX_CODE_AUTO, bAuto);
+ }
+
+ if (m_bBlBtnsStates[2] != bPuase) {
+ m_bBlBtnsStates[2] = bPuase;
+ notifyInt(RX_CODE_PUASE, bPuase);
+ }
+
+ if (m_bBlBtnsStates[3] != bManual) {
+ m_bBlBtnsStates[3] = bManual;
+ notifyInt(RX_CODE_MANUAL, bManual);
+ }
+
+ if (m_bBlBtnsStates[4] != bBeep) {
+ m_bBlBtnsStates[4] = bBeep;
+ notifyInt(RX_CODE_BEEP, bBeep);
+ }
+
+ if (m_bBlBtnsStates[5] != bResetting) {
+ m_bBlBtnsStates[5] = bResetting;
+ notifyInt(RX_CODE_RESETTING, bResetting);
+ }
+
+ if (m_bBlBtnsStates[6] != bStop) {
+ m_bBlBtnsStates[6] = bStop;
+ notifyInt(RX_CODE_STOP, bStop);
+ }
+ }
+ };
+ pPlc->readData(MC::M, nStartAddress, nReadSize, funOnReadData);
+ }
+}
\ No newline at end of file
diff --git a/SourceCode/Bond/BoounionPLC/Model.h b/SourceCode/Bond/BoounionPLC/Model.h
index b02b2de..cbdf836 100644
--- a/SourceCode/Bond/BoounionPLC/Model.h
+++ b/SourceCode/Bond/BoounionPLC/Model.h
@@ -20,6 +20,10 @@
int addPlc(const char* pszName, const char* pszIp, const unsigned int port);
int removePlc(const char* pszName);
+ // 设置/获取当前PLC
+ void setCurrentPlc(CPLC* pPlc);
+ CPLC* getCurrentPlc();
+
public:
int notify(int code);
int notifyPtr(int code, void* ptr = NULL);
@@ -34,15 +38,25 @@
int notifyTextAndInt(int code, const char* pszText, int exCode);
int notifyMesMsg(int code, int stream, int function, const char* pszText);
+private:
+ void readPLCDataRegularly();
+
public:
CConfiguration m_configuration;
+private:
+ int m_nVelocityRatio; // 速度比
+ double m_dTactTime; // 周期时间
+ int m_nDayShiftCapacity; // 白班产能
+ int m_nNightShiftCapacity; // 夜班产能
+ bool m_bBlBtnsStates[7]; // PLC View按钮状态
private:
IObservable* m_pObservable;
IObservableEmitter* m_pObservableEmitter;
CString m_strWorkDir;
std::map<std::string, CPLC*> m_mapPlc;
+ std::string m_strCurrPlc;
private:
int m_nTimerID;
diff --git a/SourceCode/Bond/BoounionPLC/PagePlcList.cpp b/SourceCode/Bond/BoounionPLC/PagePlcList.cpp
index 980fac0..937c6cf 100644
--- a/SourceCode/Bond/BoounionPLC/PagePlcList.cpp
+++ b/SourceCode/Bond/BoounionPLC/PagePlcList.cpp
@@ -196,12 +196,13 @@
HTREEITEM CPagePlcList::FindItem(CPLC* pPlc)
{
-
HTREEITEM item = m_treeCtrl.GetChildItem(nullptr);
while (item != nullptr) {
if (m_treeCtrl.GetItemData(item) == (DWORD_PTR)pPlc) {
return item;
}
+
+ item = m_treeCtrl.GetNextItem(item, TVGN_NEXT);
}
return nullptr;
--
Gitblit v1.9.3