From e8a27bb203fe2aff70390a5eca002d7438da9b0f Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期三, 22 十月 2025 14:24:34 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/BondEq/CBonder.cpp | 182 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 181 insertions(+), 1 deletions(-)
diff --git a/SourceCode/Bond/BondEq/CBonder.cpp b/SourceCode/Bond/BondEq/CBonder.cpp
index 9f81e4e..87bfdc3 100644
--- a/SourceCode/Bond/BondEq/CBonder.cpp
+++ b/SourceCode/Bond/BondEq/CBonder.cpp
@@ -5,6 +5,8 @@
#include "CDataMonitor1.h"
#include "AlarmMonitor.h"
#include "LoadMonitor.h"
+#include "ToolUnits.h"
+#include "Model.h"
CBonder* g_pBonder = NULL;
@@ -37,6 +39,12 @@
m_strEquipmentModelType = "2860";
m_strSoftRev = "1.01";
m_pPlcData = nullptr;
+ m_pModel = nullptr;
+ m_bMute = false;
+ m_nVelocityRatio = 0;
+ m_dTactTime = 0.0;
+ m_nDayShiftCapacity = 0;
+ m_nNightShiftCapacity = 0;
InitializeCriticalSection(&m_criticalSection);
}
@@ -62,6 +70,11 @@
m_listener.onPlcStateChanged = listener.onPlcStateChanged;
m_listener.onEfemStateChanged = listener.onEfemStateChanged;
m_listener.onRecvBroadcast = listener.onRecvBroadcast;
+}
+
+void CBonder::setModel(CModel* pModel)
+{
+ m_pModel = pModel;
}
const std::vector<CComponent*>& CBonder::getComponents()
@@ -133,6 +146,7 @@
AddComponent(pEQStateMonitor1);
pEQStateMonitor1->init();
+ m_bMute = false;
// 初始化各种组件
// 读PLC1配置
@@ -175,11 +189,18 @@
c->onData(id, &m_pPlcData[400], 184);
}
}
+ else if (id == MONITOR_ID_ALARM) {
+ for (auto c : m_components) {
+ c->onData(id, &m_pPlcData[600], 260);
+ }
+ }
};
pPlc->setListener(listener);
pPlc->addMonitor(1, 4400, 4499, MC::SOFT_COMPONENT::D, m_pPlcData);
pPlc->addMonitor(2, 4500, 4599, MC::SOFT_COMPONENT::D, &m_pPlcData[200]);
pPlc->addMonitor(3, 4700, 4791, MC::SOFT_COMPONENT::D, &m_pPlcData[400]);
+ pPlc->addMonitor(MONITOR_ID_ALARM, 10001, 10064, MC::SOFT_COMPONENT::M, &m_pPlcData[600]);
+
pPlc->setName("PLC(1)");
pPlc->setDescription("PLC");
pPlc->setIndex(0);
@@ -201,7 +222,6 @@
CAlarmMonitor* pAlarmMonitor1 = new CAlarmMonitor();
pAlarmMonitor1->setName("警告信息");
pAlarmMonitor1->setDescription("警告信息监控");
- pAlarmMonitor1->setBeginAddr(4461 - 4400);
pAlarmMonitor1->setIndex(0);
pAlarmMonitor1->readAlarmListFromFile((LPTSTR)(LPCTSTR)strAlarmFile);
AddComponent(pAlarmMonitor1);
@@ -422,6 +442,33 @@
iii++;
if (iii % 5 == 0) {
save();
+ }
+
+ // 需要定时读取的数据
+ readTaktTime();
+
+
+
+
+
+ // 测试
+ BOOL bTest = FALSE;
+ if (bTest) {
+ static int xx = 0;
+ xx++;
+ memset(&m_pPlcData[600], 0, 260);
+ if (xx == 12) {
+ m_pPlcData[600] = 0x01;
+ for (auto c : m_components) {
+ c->onData(MONITOR_ID_ALARM, &m_pPlcData[600], 260);
+ }
+ }
+ else if (xx == 20) {
+ m_pPlcData[600] = 0x00;
+ for (auto c : m_components) {
+ c->onData(MONITOR_ID_ALARM, &m_pPlcData[600], 260);
+ }
+ }
}
}
@@ -944,4 +991,137 @@
return iter->second;
}
+bool CBonder::isMute()
+{
+ return m_bMute;
+}
+void CBonder::setMute(bool bMute)
+{
+ m_bMute = bMute;
+}
+
+double CBonder::getTackTime()
+{
+ return m_dTactTime;
+}
+
+#define ADDR_NIGHT_SHIFT_CAPACTITY 2027
+void CBonder::readTaktTime()
+{
+ CPLC* pPlc = getPLC("PLC(1)");
+ 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) {
+ bool bMute = CToolUnits::toInt16(&pData[0]) != 0;
+ if (m_bMute != bMute) {
+ m_bMute = bMute;
+ m_pModel->notify(RX_CODE_BONDER_BEEP);
+ }
+ }
+ };
+ pPlc->readData(MC::M, 1003, 2, funOnReadData);
+ }
+
+ {
+ 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;
+ m_pModel->notifyInt(RX_CODE_BONDER_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;
+ m_pModel->notifyDouble(RX_CODE_BONDER_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;
+ m_pModel->notifyInt(RX_CODE_BONDER_DAY_SHIFT_CAPACTITY, nDayShiftCapacity);
+ }
+ if (nNightShiftCapacity != m_nNightShiftCapacity) {
+ m_nNightShiftCapacity = nNightShiftCapacity;
+ m_pModel->notifyInt(RX_CODE_BONDER_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 bValue0 = CToolUnits::toInt16(&pData[(1103 - nStartAddress) * 2]) != 0; // 启动
+ bool bValue1 = CToolUnits::toInt16(&pData[(1100 - nStartAddress) * 2]) != 0; // 自动
+ bool bValue2 = CToolUnits::toInt16(&pData[(1104 - nStartAddress) * 2]) != 0; // 暂停
+ bool bValue3 = CToolUnits::toInt16(&pData[(1100 - nStartAddress) * 2]) != 0; // 手动
+ bool bValue4 = CToolUnits::toInt16(&pData[(1003 - nStartAddress) * 2]) != 0; // 静音
+ bool bValue5 = CToolUnits::toInt16(&pData[(1150 - nStartAddress) * 2]) != 0; // 复位
+ bool bValue6 = CToolUnits::toInt16(&pData[(1114 - nStartAddress) * 2]) != 0; // 停止
+
+ bValue4 = pData[0] & 0x8;
+ bValue3 = pData[100*2/8] & 0x1;
+ if (m_bBlBtnsStates[0] != bValue0) {
+ m_bBlBtnsStates[0] = bValue0;
+ m_pModel->notifyInt(RX_CODE_BONDER_STATES_BTN0, bValue0);
+ }
+
+ if (m_bBlBtnsStates[1] != bValue1) {
+ m_bBlBtnsStates[1] = bValue1;
+ m_pModel->notifyInt(RX_CODE_BONDER_STATES_BTN1, bValue1);
+ }
+
+ if (m_bBlBtnsStates[2] != bValue2) {
+ m_bBlBtnsStates[2] = bValue2;
+ m_pModel->notifyInt(RX_CODE_BONDER_STATES_BTN2, bValue2);
+ }
+
+ if (m_bBlBtnsStates[3] != bValue3) {
+ m_bBlBtnsStates[3] = bValue3;
+ m_pModel->notifyInt(RX_CODE_BONDER_STATES_BTN3, bValue3);
+ }
+
+ if (m_bBlBtnsStates[4] != bValue4) {
+ m_bBlBtnsStates[4] = bValue4;
+ m_pModel->notifyInt(RX_CODE_BONDER_STATES_BTN4, bValue4);
+ }
+
+ if (m_bBlBtnsStates[5] != bValue5) {
+ m_bBlBtnsStates[5] = bValue5;
+ m_pModel->notifyInt(RX_CODE_BONDER_STATES_BTN5, bValue5);
+ }
+
+ if (m_bBlBtnsStates[6] != bValue6) {
+ m_bBlBtnsStates[6] = bValue6;
+ m_pModel->notifyInt(RX_CODE_BONDER_STATES_BTN6, bValue6);
+ }
+ }
+ };
+ pPlc->readData(MC::M, nStartAddress, nReadSize, funOnReadData);
+ }
+}
--
Gitblit v1.9.3