From be01318968aed5e55c511eedc6c1f72a961c3f13 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 19 六月 2025 14:49:02 +0800
Subject: [PATCH] 1.重新梳理JobDataS的传递和更新;

---
 SourceCode/Bond/Servo/CMaster.cpp |  140 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 123 insertions(+), 17 deletions(-)

diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 96ad405..6efd863 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -1,6 +1,8 @@
 #include "stdafx.h"
 #include "Common.h"
 #include "CMaster.h"
+#include <future>
+#include <vector>
 
 
 namespace SERVO {
@@ -48,6 +50,7 @@
 		m_ullRunTime = 0;
 		m_state = MASTERSTATE::READY;
 		m_pActiveRobotTask = nullptr;
+		m_nLastError = 0;
 		InitializeCriticalSection(&m_criticalSection);
 	}
 
@@ -264,6 +267,13 @@
 		return 0;
 	}
 
+	void CMaster::clearError()
+	{
+		m_nLastError = 0;
+		m_strLastError = "";
+		setState(MASTERSTATE::READY);
+	}
+
 	ULONGLONG CMaster::getRunTime()
 	{
 		if (m_state == MASTERSTATE::RUNNING)
@@ -325,8 +335,113 @@
 			// 如果状态为STARTING,开始工作并切换到RUNNING状态
 			lock();
 			if (m_state == MASTERSTATE::STARTING) {
+				// 发送indexerOperationModeChange到各个机台,成功后切换到RUNNING状态
+				// 否则切换到MSERROR状态
+				int nRet;
+				CEquipment* pEq[6] = { pEFEM, pBonder1, pBonder2, pBakeCooling, 
+					pVacuumBake, pMeasurement};
+				BOOL bIomcOk[7] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE};
+				std::vector<std::promise<void>> promises(6);
+				std::vector<std::future<void>> futures;
+
+				nRet = pEq[0]->indexerOperationModeChange(IDNEXER_OPERATION_MODE::Start,
+					[&](int writeCode, int retCode) -> void {
+						bIomcOk[0] = retCode == (int)RET::OK;
+						promises[0].set_value();
+						TRACE("a0001\n", writeCode, retCode);
+					});
+				if (nRet != 0) {
+					LOGI("<Master>EFEM切换Start状态失败");
+					m_strLastError = "EFEM切换Start状态失败.";
+					goto WAIT;
+				}
+				futures.push_back(promises[0].get_future());
+
+				nRet = pEq[1]->indexerOperationModeChange(IDNEXER_OPERATION_MODE::Start,
+					[&](int writeCode, int retCode) -> void {
+						bIomcOk[1] = retCode == (int)RET::OK;
+						promises[1].set_value();
+						TRACE("a0002\n");
+					});
+				if (nRet != 0) {
+					LOGI("<Master>Bonder1切换Start状态失败");
+					m_strLastError = "Bonder1切换Start状态失败.";
+					goto WAIT;
+				}
+				futures.push_back(promises[1].get_future());
+
+				nRet = pEq[2]->indexerOperationModeChange(IDNEXER_OPERATION_MODE::Start,
+					[&](int writeCode, int retCode) -> void {
+						bIomcOk[2] = retCode == (int)RET::OK;
+						promises[2].set_value();
+						TRACE("a0003\n");
+					});
+				if (nRet != 0) {
+					LOGI("<Master>Bonder2切换Start状态失败");
+					m_strLastError = "Bonder2切换Start状态失败.";
+					goto WAIT;
+				}
+				futures.push_back(promises[2].get_future());
+
+				nRet = pEq[3]->indexerOperationModeChange(IDNEXER_OPERATION_MODE::Start,
+					[&](int writeCode, int retCode) -> void {
+						bIomcOk[3] = retCode == (int)RET::OK;
+						promises[3].set_value();
+						TRACE("a0004\n");
+					});
+				if (nRet != 0) {
+					LOGI("<Master>BakeCooling切换Start状态失败");
+					m_strLastError = "BakeCooling切换Start状态失败.";
+					goto WAIT;
+				}
+				futures.push_back(promises[3].get_future());
+
+				nRet = pEq[4]->indexerOperationModeChange(IDNEXER_OPERATION_MODE::Start,
+					[&](int writeCode, int retCode) -> void {
+						bIomcOk[4] = retCode == (int)RET::OK;
+						promises[4].set_value();
+						TRACE("a0005\n");
+					});
+				if (nRet != 0) {
+					LOGI("<Master>VacuumBake切换Start状态失败");
+					m_strLastError = "VacuumBake切换Start状态失败.";
+					goto WAIT;
+				}
+				futures.push_back(promises[4].get_future());
+
+				nRet = pEq[5]->indexerOperationModeChange(IDNEXER_OPERATION_MODE::Start,
+					[&](int writeCode, int retCode) -> void {
+						bIomcOk[5] = retCode == (int)RET::OK;
+						promises[5].set_value();
+						TRACE("a0006\n");
+					});
+				if (nRet != 0) {
+					LOGI("<Master>Measurement切换Start状态失败");
+					m_strLastError = "Measurement切换Start状态失败.";
+					goto WAIT;
+				}
+				futures.push_back(promises[5].get_future());
+
+WAIT:
+				for (auto& f : futures) {
+					f.wait();  // 阻塞等待对应设备完成
+				}
+				for (int i = 0; i < 6; i++) {
+					if (!bIomcOk[i]) {
+						bIomcOk[6] = FALSE;
+						LOGI("<Master>%s切换Start状态失败", pEq[i]->getName().c_str());
+					}
+				}
+				
+				// 检查看是否都已经切换到START状态
+				if (!bIomcOk[6]) {
+					unlock();
+					setState(MASTERSTATE::MSERROR);
+					continue;
+				}
+
+
 				unlock();
-				Sleep(1000);
 				setState(MASTERSTATE::RUNNING);
 				continue;
 			}
@@ -613,17 +728,6 @@
 
 			// 读标志位
 			for (auto item : m_listEquipment) {
-				//if (item->getID() == EQ_ID_Bonder1 ||
-				//	item->getID() == EQ_ID_Bonder2) {
-				//	const StationIdentifier& station = item->getStation();
-				//	MemoryBlock& block = item->getReadBitBlock();
-
-				//	int nRet = m_cclink.ReadData2(station, (DeviceType)block.type,
-				//		block.start, block.size, block.buffer);
-				//	if (0 == nRet) {
-				//		item->onReceiveLBData(block.buffer, block.size);
-				//	}
-				//}
 				const StationIdentifier& station = item->getStation();
 				MemoryBlock& block = item->getReadBitBlock();
 
@@ -682,10 +786,10 @@
 				if (m_pActiveRobotTask->getSrcPosition() == p->getID()) {
 					CGlass* pGlass = p->getGlassFromSlot(m_pActiveRobotTask->getSrcSlot());
 					if (pGlass != nullptr) {
-						CJobDataB* pJobDataBSrc = pGlass->getJobDataB();
-						if (pJobDataBSrc != nullptr
-							&& pJobDataBSrc->getCassetteSequenceNo() == pJobDataB->getCassetteSequenceNo()
-							&& pJobDataBSrc->getJobSequenceNo() == pJobDataB->getJobSequenceNo()) {
+						CJobDataS* pJobDataS = pGlass->getJobDataS();
+						if (pJobDataS != nullptr
+							&& pJobDataS->getCassetteSequenceNo() == pJobDataB->getCassetteSequenceNo()
+							&& pJobDataS->getJobSequenceNo() == pJobDataB->getJobSequenceNo()) {
 							bOk = TRUE;
 							LOGI("<CMaster>onPreFethedOutJob, 已校验数据一致性.");
 						}
@@ -788,7 +892,9 @@
 				unlock();
 			}
 		};
-
+		listener.onProcessStateChanged = [&](void* pEquipment, PROCESS_STATE state) -> void {
+			LOGI("<Master>onProcessStateChanged<%d>", (int)state);
+		};
 		pEquipment->setListener(listener);
 		pEquipment->setCcLink(&m_cclink);
 		m_listEquipment.push_back(pEquipment);

--
Gitblit v1.9.3