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/Model.cpp | 126 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 126 insertions(+), 0 deletions(-)
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
--
Gitblit v1.9.3