From aabaff9cdcf9bb279b762891aedda5a03571fbb5 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 01 七月 2025 08:55:07 +0800
Subject: [PATCH] 1.修改Glass的JobDataS的更新逻辑,在收到OnReceiveJob时,机器内未保存和管理Glass, 此时Glass在Arm上,应通过Arm来更新JobDataS;

---
 SourceCode/Bond/Servo/CEquipment.cpp |  105 ++++++++++++++++++++++++++++++++--------------------
 1 files changed, 65 insertions(+), 40 deletions(-)

diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index e565feb..817f4bc 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -406,10 +406,12 @@
 			m_bLinkSignalToUpstream[i][SIGNAL_INTERLOCK] = isBitOn(pszData, size, index + 2);
 			m_bLinkSignalToUpstream[i][SIGNAL_SEND_ABLE] = isBitOn(pszData, size, index + 3);
 			index += 0x40;
+
+			if (m_bLinkSignalToUpstream[i][SIGNAL_SEND_ABLE]) {
+				onSendAble(i+1);
+			}
 		}		 
-		if(m_bLinkSignalToUpstream[0][SIGNAL_SEND_ABLE]) {
-			onSendAble();
-		}
+
 
 		index += 0x40 * 2;
 		for (int i = 0; i < 8; i++) {
@@ -418,10 +420,12 @@
 			m_bLinkSignalToDownstream[i][SIGNAL_INTERLOCK] = isBitOn(pszData, size, index + 2);
 			m_bLinkSignalToDownstream[i][SIGNAL_RECEIVE_ABLE] = isBitOn(pszData, size, index + 3);
 			index += 0x40;
+
+			if (m_bLinkSignalToDownstream[0][SIGNAL_RECEIVE_ABLE]) {
+				onReceiveAble(i + 1);
+			}
 		}
-		if (m_bLinkSignalToDownstream[0][SIGNAL_RECEIVE_ABLE]) {
-			onReceiveAble();
-		}
+
 
 		// 其它信号及响应
 		index = 0x540;
@@ -836,7 +840,7 @@
 		return 0;
 	}
 
-	int CEquipment::fetchedOutJob(CJobDataB* pJobDataB)
+	int CEquipment::fetchedOutJob(int port, CJobDataB* pJobDataB)
 	{
 		if (m_pArm == nullptr) {
 			return -1;
@@ -859,7 +863,6 @@
 			return -3;
 		}
 
-
 		((CArm*)m_pArm)->tempStore(pContext);
 		pContext->release();
 		Unlock();
@@ -876,7 +879,7 @@
 		return 0;
 	}
 
-	int CEquipment::storedJob(CJobDataB* pJobDataB, short putSlot)
+	int CEquipment::storedJob(int port, CJobDataB* pJobDataB, short putSlot)
 	{
 		if (m_pArm == nullptr) {
 			return -1;
@@ -902,7 +905,7 @@
 		if (m_listener.onDataChanged != nullptr) {
 			m_listener.onDataChanged(this, EDCC_STORED_JOB);
 		}
-		
+
 		return 0;
 	}
 
@@ -950,7 +953,6 @@
 
 	CGlass* CEquipment::getGlassWithCassette(int cassetteSequenceNo, int jobSequenceNo)
 	{
-		CSlot* pSlot = nullptr;
 		for (int i = 0; i < SLOT_MAX; i++) {
 			if (!m_slot[i].isEnable()) continue;
 			CGlass* pGlass = (CGlass*)m_slot[i].getContext();
@@ -1304,6 +1306,7 @@
 			if (!m_slot[i].isEnable()) continue;
 			if (m_slot[i].isLock()) continue;
 			CGlass* pGlass = (CGlass*)m_slot[i].getContext();
+			if (!isSlotProcessed(i)) continue;
 			if (pGlass == nullptr) continue;
 			int lsPath = m_slot[i].getLinkSignalPath();
 			if(!m_bLinkSignalToUpstream[lsPath][SIGNAL_UPSTREAM_INLINE]
@@ -1330,6 +1333,7 @@
 					if (m_slot[i].isLock()) continue;
 					CGlass* pGlass = (CGlass*)m_slot[i].getContext();
 					if (pGlass == nullptr) continue;
+					if (!isSlotProcessed(i+1)) continue;
 					int lsPath = m_slot[i].getLinkSignalPath();
 					if (!m_bLinkSignalToUpstream[lsPath][SIGNAL_UPSTREAM_INLINE]
 						|| m_bLinkSignalToUpstream[lsPath][SIGNAL_UPSTREAM_TROUBLE]
@@ -1434,7 +1438,16 @@
 	int CEquipment::onReceivedJob(int port, CJobDataS* pJobDataS)
 	{
 		LOGI("<CEquipment-%s>onReceivedJob.", m_strName.c_str());
-		return 0;
+
+
+		// 可以在此更新JobDataS数据了
+		int nRet = ((CArm*)m_pArm)->glassUpdateJobDataS(pJobDataS);
+		if (nRet < 0) {
+			LOGE("<CEquipment-%s>onReceivedJob,更新JobDataS失败,glassUpdateJobDataS返回%d",
+				m_strName.c_str(), nRet);
+		}
+
+		return nRet;
 	}
 
 	int CEquipment::decodeSentOutJobReport(CStep* pStep, int port, const char* pszData, size_t size)
@@ -1455,17 +1468,6 @@
 	int CEquipment::onSentOutJob(int port, CJobDataS* pJobDataS)
 	{
 		LOGI("<CEquipment-%s>onSentOutJob.", m_strName.c_str());
-
-
-		// 可以在此更新JobDataS数据了
-		CGlass* pGlass = getGlass(pJobDataS->getGlass1Id().c_str());
-		if (pGlass == nullptr) {
-			LOGE("<CEquipment-%s>onSentOutJob,没有找到对应的Glass(CassetteSequenceNo:%d, JobSequenceNo:%d, ID=%s),请检查数据,注意风险。",
-				m_strName.c_str(), pJobDataS->getCassetteSequenceNo(), pJobDataS->getJobSequenceNo(),
-				pJobDataS->getGlass1Id().c_str());
-			return -1;
-		}
-		pGlass->updateJobDataS(pJobDataS);
 
 		return 0;
 	}
@@ -1517,7 +1519,7 @@
 		LOGI("<CEquipment-%s>onPreFetchedOutJob:port:%d|GlassId:%s",
 			m_strName.c_str(), port, pJobDataB->getGlassId().c_str());
 		if (m_listener.onPreFethedOutJob != nullptr) {
-			return m_listener.onPreFethedOutJob(this, pJobDataB);
+			return m_listener.onPreFethedOutJob(this, port, pJobDataB);
 		}
 
 		return TRUE;
@@ -1530,7 +1532,7 @@
 
 		BOOL bCheck = onPreFetchedOutJob(port, pJobDataB);
 		if (bCheck) {
-			return fetchedOutJob(pJobDataB);
+			return fetchedOutJob(port, pJobDataB);
 		}
 
 		// 数据异常,处理或显示
@@ -1678,7 +1680,9 @@
 
 	int CEquipment::decodeJobProcessStartReport(CStep* pStep, const char* pszData, size_t size)
 	{
-		LOGI("<CEquipment-%s>decodeJobProcessStartReport", getName().c_str());
+		int port = (int)(__int64)pStep->getProp("Port");
+		LOGI("<CEquipment-%s>decodeJobProcessStartReport, port:%d", getName().c_str(), port);
+
 		short cassetteNo, jobSequenceNo, unitNo, subUnitNo, slotNo;
 		int year, month, day, hour, minute, second;
 
@@ -1744,7 +1748,8 @@
 
 	int CEquipment::decodeJobProcessEndReport(CStep* pStep, const char* pszData, size_t size)
 	{
-		LOGI("<CEquipment-%s>decodeJobProcessEndReport", getName().c_str());
+		int port = (int)(__int64)pStep->getProp("Port");
+		LOGI("<CEquipment-%s>decodeJobProcessEndReport, port:%d", getName().c_str(), port);
 
 		short cassetteNo, jobSequenceNo, unitNo, subUnitNo, slotNo;
 		int year, month, day, hour, minute, second;
@@ -1789,6 +1794,28 @@
 		if (m_processState != PROCESS_STATE::Complete) {
 			setProcessState(PROCESS_STATE::Complete);
 		}
+		
+		CGlass* pGlass = getGlassFromSlot(slotNo);
+		if (pGlass == nullptr) {
+			LOGE("<CEquipment-%s>decodeJobProcessEndReport, 找不到对应glass", getName().c_str());
+		}
+		else {
+			CJobDataS* pJs = pGlass->getJobDataS();
+			if (pJs->getCassetteSequenceNo() == cassetteNo
+				&& pJs->getJobSequenceNo() == jobSequenceNo) {
+				pGlass->processEnd(m_nID, getSlotUnit(slotNo));
+				if (m_processState != PROCESS_STATE::Complete) {
+					setProcessState(PROCESS_STATE::Complete);
+				}
+			}
+			else {
+				LOGE("<CEquipment-%s>decodeJobProcessEndReport, jobSequenceNo或jobSequenceNo不匹配",
+					getName().c_str());
+			}
+		}
+
+
+
 
 		// 缓存Attribute,用于调试时显示信息
 		unsigned int weight = 201;
@@ -1833,17 +1860,18 @@
 
 		// 如果没有可用位置,报错
 		Lock();
-		CSlot* pSlot = getAvailableSlotForGlassExcludeSignal((MaterialsType)pJobDataS->getMaterialsType());
-		if (pSlot == nullptr) {
+		CSlot* pSlot = getSlot(putSlot - 1);
+		ASSERT(pSlot);
+		if (pSlot->getContext() != nullptr) {
 			Unlock();
-			LOGE("<CEquipemnt-%s>onPreFetchedOutJob,找不到匹配的Slot,不能进料,请注意风险!", m_strName.c_str());
+			LOGE("<CEquipemnt-%s>onPreStoredJob,指定slot(port:%d)有料,请注意风险!", m_strName.c_str(), port);
 			return FALSE;
 		}
 		Unlock();
 
 
 		if (m_listener.onPreStoredJob != nullptr) {
-			if (!m_listener.onPreStoredJob(this, pJobDataB, putSlot)) {
+			if (!m_listener.onPreStoredJob(this, port, pJobDataB, putSlot)) {
 				return FALSE;
 			}
 
@@ -1863,11 +1891,11 @@
 		short putSlot = 0;
 		BOOL bCheck = onPreStoredJob(port, pJobDataB, putSlot);
 		if (bCheck) {
-			return storedJob(pJobDataB, putSlot);
+			return storedJob(port, pJobDataB, putSlot);
 		}
 
 		// 数据异常,处理或显示
-		LOGI("<CEquipment-%s>onStoredJob Error.ort:%d|GlassId:%s",
+		LOGI("<CEquipment-%s>onStoredJob Error.port:%d|GlassId:%s",
 			m_strName.c_str(), port, pJobDataB->getGlassId().c_str());
 		return -1;
 	}
@@ -1883,19 +1911,16 @@
 	 * 当从CC-Link检测到设备Send Able为On时调用此函数
 	 * 可能会多次重复调用(根据扫描频率), 注意防呆
 	 */
-	int CEquipment::onSendAble()
+	int CEquipment::onSendAble(int port)
 	{
-		LOGI("<CEquipment-%s>onSendAble.", m_strName.c_str());
-		if (m_processState != PROCESS_STATE::Complete) {
-			setProcessState(PROCESS_STATE::Complete);
-		}
+		LOGI("<CEquipment-%s>onSendAble.port:%d", m_strName.c_str(), port);
 
 		return 0;
 	}
 
-	int CEquipment::onReceiveAble()
+	int CEquipment::onReceiveAble(int port)
 	{
-		LOGI("<CEquipment-%s>onReceiveAble.", m_strName.c_str());
+		LOGI("<CEquipment-%s>onReceiveAble.port:%d", m_strName.c_str(), port);
 
 		return 0;
 	}

--
Gitblit v1.9.3