From bea6407b376a4e426f0b120bae569fba6ab867db Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期六, 08 十一月 2025 17:55:47 +0800
Subject: [PATCH] 1.CMaster.cpp 第 1644/1667/1691 行在记录 SV 曲线时通过 getGlassFromSlot(0) 取玻璃,而各设备的 initSlots() 都是从 1 开始编号(例如 CBonder.cpp (line 408)、CVacuumBake.cpp (line 415) 等)。槽位 0 永远不存在,所以 pGlass 始终是 nullptr,pGlass->addSVData(...) 的分支从未执行。结果 SERVO::CGlass::m_svDatas 里没有任何曲线数据,GlassJson::ToPrettyString 生成的 pretty 字符串也就没有 sv_datas,导出 CSV 时自然读不到曲线。 同一段代码还有一个潜在 Bug:虽然判断了 channel - 1 < bonderTypes.size(),但真正索引却用的是 bonderTypes[channel]。索引偏移会导致数据类型错位,最后一个通道甚至可能越界。即使修正了槽位,这里也需要同步改成 bonderTypes[channel - 1](另外两处 vacuumbakeTypes、coolingTypes 也一样)。
---
SourceCode/Bond/BondEq/CPLC.cpp | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/SourceCode/Bond/BondEq/CPLC.cpp b/SourceCode/Bond/BondEq/CPLC.cpp
index a488937..3c4d175 100644
--- a/SourceCode/Bond/BondEq/CPLC.cpp
+++ b/SourceCode/Bond/BondEq/CPLC.cpp
@@ -101,7 +101,7 @@
// mc channel
McChannelListener m_mcChannellistener;
m_mcChannellistener.funOnConnected = [&](IMcChannel* pChannel, int nErrorCode) -> void {
- MYTRACE1("<PLC-%s>连接结果<code= %d>", m_strName.c_str(), nErrorCode);
+ LOGI("<PLC-%s>连接结果<code= %d>", m_strName.c_str(), nErrorCode);
if (nErrorCode == 0) {
setState(PLCSTATE::CONNECTED);
}
@@ -118,7 +118,7 @@
CString strText;
dataToHexString(pData, nDataSize, strText);
if (nDecodeRet != 0) {
- MYTRACE1("<PLC-%s>funOnRead[%s], nDecodeRet=%d", m_strName.c_str(), (LPTSTR)(LPCTSTR)strText, nDecodeRet);
+ LOGE("<PLC-%s>funOnRead[%s], nDecodeRet=%d", m_strName.c_str(), (LPTSTR)(LPCTSTR)strText, nDecodeRet);
}
m_nUnHeartBeat = 0;
};
@@ -130,7 +130,7 @@
&& m_pChannel != NULL) {
m_pChannel->setChannelListener(&m_mcChannellistener);
m_pChannel->setActionInterval(m_nActionInterval);
- MYTRACE1("<PLC-%s>正在连接PLC.", m_strName.c_str());
+ LOGI("<PLC-%s>正在连接PLC.", m_strName.c_str());
setState(PLCSTATE::CONNECTING);
m_pChannel->connect();
}
@@ -214,11 +214,11 @@
s.AppendFormat(" %x", (BYTE)pData[i]);
}
s.Append("]");
- MYTRACE1("<CPLC-%d-%d>Received plc data.%s", m_nIndex, monitor.id, (LPTSTR)(LPCTSTR)s);
+ LOGD("<CPLC-%d-%d>Received plc data.%s", m_nIndex, monitor.id, (LPTSTR)(LPCTSTR)s);
}
}
else {
- MYTRACE1("<CPLC-%d-%d>PLC批读取数据位超时.flag=%d", m_nIndex, monitor.id, flag);
+ LOGE("<CPLC-%d-%d>PLC批读取数据位超时.flag=%d", m_nIndex, monitor.id, flag);
}
if (nDataSize == monitor.readLen && flag == 0) {
@@ -242,7 +242,7 @@
bool CPLC::isConnected()
{
- return m_pChannel->isConnected();
+ return m_pChannel != nullptr && m_pChannel->isConnected();
}
int CPLC::readWord(MC::SOFT_COMPONENT softComponent, unsigned int addr,
@@ -267,6 +267,12 @@
int value, ONWRITE funOnWrite)
{
return m_pChannel->writeWord(softComponent, addr, value, funOnWrite);
+}
+
+int CPLC::writeDWord(MC::SOFT_COMPONENT softComponent, unsigned int addr,
+ int value, ONWRITE funOnWrite)
+{
+ return m_pChannel->writeDWord(softComponent, addr, value, funOnWrite);
}
int CPLC::writeData(MC::SOFT_COMPONENT softComponent, unsigned int addr,
@@ -308,7 +314,7 @@
static int iii = 0;
iii++;
if (iii % 5 == 3) {
- if (!m_pChannel->isConnected())
+ if (m_pChannel != nullptr && !m_pChannel->isConnected())
m_pChannel->connect();
}
}
\ No newline at end of file
--
Gitblit v1.9.3