From 331f447bb0e5eccf0b3161ab287c1372b14b8480 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 08 八月 2025 11:53:58 +0800
Subject: [PATCH] 1.增加千传计数,保存计数,重启软件时恢复; 2.千传测试模式,打印相关日志,方便后期提取,用于统计; 3.千传模式时烘烤两腔体都要进入; 4.千传模式时,Fliper到Bonder修改为用手臂2取料; 5.修复千传模式不计运行时的问题; 6.千传模式,最后收料强制放入第一层; 6.修复Buf, 当任务未生成(在符合条件后仍有1秒间隙)而机器单元发送FetchOutJob时,数据检验失败的问题,增加Sleep, 缩小间隙;

---
 SourceCode/Bond/Servo/Configuration.h   |    2 
 SourceCode/Bond/Servo/CEquipment.cpp    |    4 
 SourceCode/Bond/Servo/CMaster.cpp       |   90 +++++++++++++++++++++++++++--
 SourceCode/Bond/Servo/PageLog.cpp       |    9 ++
 SourceCode/Bond/Servo/Configuration.cpp |   11 +++
 SourceCode/Bond/Servo/CMaster.h         |   12 ++++
 SourceCode/Bond/Servo/Model.cpp         |    4 +
 SourceCode/Bond/Servo/ServoDlg.cpp      |   10 +++
 8 files changed, 129 insertions(+), 13 deletions(-)

diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index 322923d..7560957 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -1990,14 +1990,14 @@
 	 */
 	int CEquipment::onSendAble(int port)
 	{
-		LOGI("<CEquipment-%s>onSendAble.port:%d", m_strName.c_str(), port);
+		// LOGI("<CEquipment-%s>onSendAble.port:%d", m_strName.c_str(), port);
 
 		return 0;
 	}
 
 	int CEquipment::onReceiveAble(int port)
 	{
-		LOGI("<CEquipment-%s>onReceiveAble.port:%d", m_strName.c_str(), port);
+		// LOGI("<CEquipment-%s>onReceiveAble.port:%d", m_strName.c_str(), port);
 
 		return 0;
 	}
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 9635e7a..455804a 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -55,6 +55,8 @@
 		m_bEnableEventReport = true;
 		m_bEnableAlarmReport = true;
 		m_bContinuousTransfer = false;
+		m_nContinuousTransferCount = 0;
+		m_nContinuousTransferStep = CTStep_begin;
 		InitializeCriticalSection(&m_criticalSection);
 	}
 
@@ -294,7 +296,7 @@
 
 	ULONGLONG CMaster::getRunTime()
 	{
-		if (m_state == MASTERSTATE::RUNNING)
+		if (m_state == MASTERSTATE::RUNNING || m_state == MASTERSTATE::RUNNING_CONTINUOUS_TRANSFER)
 			return m_ullRunTime + (GetTickCount64() - m_ullStartTime);
 		else
 			return m_ullRunTime;
@@ -345,7 +347,7 @@
 		while (1) {
 			// 待退出信号或时间到
 			HANDLE hEvents[] = { m_hEventDispatchThreadExit[0], m_hDispatchEvent };
-			int nRet = WaitForMultipleObjects(2, hEvents, FALSE, 1000);
+			int nRet = WaitForMultipleObjects(2, hEvents, FALSE, 500);
 			if (nRet == WAIT_OBJECT_0) {
 				break;
 			}
@@ -713,6 +715,7 @@
 							m_pActiveRobotTask = createTransferTask_continuous_transfer(pMeasurement,
 								0, pLoadPorts[s], slot);
 							if (m_pActiveRobotTask != nullptr) {
+								m_nContinuousTransferStep = CTStep_end;
 								goto CT_PORT_PUT;
 							}
 						}
@@ -727,6 +730,9 @@
 				if (!rmd.armState[0]) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pBakeCooling,
 						3, pMeasurement, 0);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(BakeCooling -> Measurement)...");
+					}
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
@@ -735,44 +741,75 @@
 				if (!rmd.armState[0]) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pBakeCooling,
 						2, pBakeCooling, 3);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(BakeCooling-2 -> BakeCooling-3)...");
+					}
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 				if (!rmd.armState[0]) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pBakeCooling,
 						1, pBakeCooling, 2);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(BakeCooling-1 -> BakeCooling-2)...");
+					}
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 				if (!rmd.armState[0]) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pBakeCooling,
 						0, pBakeCooling, 1);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(BakeCooling-0 -> BakeCooling-1)...");
+					}
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
 				// VacuumBake(G1) -> BakeCooling
 				if (!rmd.armState[0]) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pVacuumBake,
-						0, pBakeCooling, 0);
+						1, pBakeCooling, 0);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(VacuumBake(G1) -> BakeCooling)...");
+					}
+					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
+				}
+
+				// VacuumBake(G1) -> VacuumBake(G1)
+				if (!rmd.armState[0]) {
+					m_pActiveRobotTask = createTransferTask_continuous_transfer(pVacuumBake,
+						0, pVacuumBake, 1);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(VacuumBake(G1-0) -> VacuumBake(G1-1))...");
+					}
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
 				// Bonder2 -> VacuumBake(G1)
 				if (!rmd.armState[0]) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pBonder2,
-						0, pVacuumBake, 0);
+						1, pVacuumBake, 0);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(Bonder2 -> VacuumBake(G1))...");
+					}
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
-
+				
 				// Bonder1 -> Bonder2
 				if (!rmd.armState[0] && !pBonder2->hasBondClass()) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pBonder1,
-						0, pBonder2, 0);
+						1, pBonder2, 1);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(Bonder1 -> Bonder2)...");
+					}
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
 				// Fliper(G2) -> Bonder1
 				if (!rmd.armState[0] && !pBonder1->hasBondClass()) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pFliper,
-						0, pBonder1, 1);
+						0, pBonder1, 1, 2);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(Fliper(G2) -> Bonder1)...");
+					}
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
@@ -780,6 +817,9 @@
 				if (!rmd.armState[1]) {
 					m_pActiveRobotTask = createTransferTask_continuous_transfer(pAligner,
 						0, pFliper, 0);
+					if (m_pActiveRobotTask != nullptr) {
+						LOGI("<ContinuousTransfer>千传测试,开始搬送任务(Aligner -> Fliper(G2))...");
+					}
 					CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 				}
 
@@ -793,6 +833,7 @@
 							m_pActiveRobotTask = createTransferTask_continuous_transfer(pLoadPorts[s], 
 								slot, pAligner, 0);
 							if (m_pActiveRobotTask != nullptr) {
+								LOGI("<ContinuousTransfer>千传测试,开始搬送任务(LoadPort -> Aligner)...");
 								pEFEM->setContext(m_pActiveRobotTask->getContext());
 								goto CT_PORT_GET;
 							}
@@ -801,6 +842,10 @@
 				}
 
 			CT_PORT_GET:
+				if (m_pActiveRobotTask != nullptr) {
+					m_nContinuousTransferStep = CTStep_begin;
+					LOGI("<ContinuousTransfer>千传测试,开始第 %d 轮", m_nContinuousTransferCount + 1);
+				}
 				CHECK_RUN_ACTIVE_ROBOT_TASK(m_pActiveRobotTask);
 
 
@@ -892,6 +937,8 @@
 		listener.onPreFethedOutJob = [&](void* pEquipment, int port, CJobDataB* pJobDataB) -> BOOL {
 			CEquipment* p = (CEquipment*)pEquipment;
 
+			// 可能要加这一句
+			Sleep(750);
 
 			// 取片,更新当前搬送任务
 			BOOL bOk = FALSE;
@@ -925,6 +972,8 @@
 		listener.onPreStoredJob = [&](void* pEquipment, int port, CJobDataB* pJobDataB, short& slot) -> BOOL {
 			CEquipment* p = (CEquipment*)pEquipment;
 
+			// 可能要加这一句
+			Sleep(750);
 
 			// 放片,更新当前搬送任务
 			BOOL bOk = FALSE;
@@ -1002,6 +1051,17 @@
 					&& m_pActiveRobotTask->getTarPosition() == p->getID()) {
 					m_pActiveRobotTask->stored();
 					m_pActiveRobotTask->completed();
+
+					if (m_state == MASTERSTATE::RUNNING_CONTINUOUS_TRANSFER) {
+						if (m_nContinuousTransferStep == CTStep_end) {
+							m_nContinuousTransferCount++;
+							LOGI("<ContinuousTransfer>千传测试,第 %d 轮结束", m_nContinuousTransferCount);
+							if (m_listener.onCTRoundEnd != nullptr) {
+								m_listener.onCTRoundEnd(this, m_nContinuousTransferCount);
+							}
+						}
+					}
+
 					LOGI("放片完成...");
 					// 完成此条搬送任务,但要把数据和消息上抛应用层
 					unlock();
@@ -1592,8 +1652,12 @@
 		}
 
 		CRobotTask* pTask = nullptr;
-		CSlot* pTarSlot = pTarEq->isSlotAvailable(nTarSlot);
 		CSlot* pSrcSlot = pSrcEq->getProcessedSlotCt(nSrcSlot);
+		if (pSrcSlot != nullptr && pSrcEq->getID() == EQ_ID_MEASUREMENT
+			&& (pTarEq->getID() == EQ_ID_LOADPORT1 || pTarEq->getID() == EQ_ID_LOADPORT2 || pTarEq->getID() == EQ_ID_LOADPORT3 || pTarEq->getID() == EQ_ID_LOADPORT4)) {
+			pTarEq->removeGlass(1);
+		}
+		CSlot* pTarSlot = pTarEq->isSlotAvailable(nTarSlot);
 		if (pSrcSlot != nullptr && nullptr != pTarSlot) {
 			pTask = new CRobotTask();
 			pTask->setContext(pSrcSlot->getContext());
@@ -1733,4 +1797,14 @@
 		pPort->sendCassetteCtrlCmd(CCC_PROCESS_CANCEL, nullptr, 0, 0, 0, nullptr, nullptr);
 		return 0;
 	}
+
+	int CMaster::getContinuousTransferCount()
+	{
+		return m_nContinuousTransferCount;
+	}
+
+	void CMaster::setContinuousTransferCount(int round)
+	{
+		m_nContinuousTransferCount = round;
+	}
 }
diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index 27d0973..e5f868d 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -15,6 +15,9 @@
 #include "CRobotTask.h"
 
 
+#define CTStep_begin        0
+#define CTStep_end          99
+
 namespace SERVO {
     enum class MASTERSTATE {
         READY = 0,
@@ -33,6 +36,7 @@
     typedef std::function<void(void* pMaster, CEquipment* pEquipment, int code)> ONEQDATACHANGED;
     typedef std::function<void(void* pMaster, CRobotTask* pTask, int code)> ONROBOTTASKEVENT;
     typedef std::function<void(void* pMaster, CEquipment* pEquipment, short status, __int64 data)> ONLOADPORTSTATUSCHANGED;
+    typedef std::function<void(void* pMaster, int round)> ONCTROUNDEND;
     typedef struct _MasterListener
     {
         ONMASTERSTATECHANGED    onMasterStateChanged;
@@ -43,6 +47,7 @@
         ONEQDATACHANGED         onEqDataChanged;
         ONROBOTTASKEVENT        onRobotTaskEvent;
         ONLOADPORTSTATUSCHANGED	onLoadPortStatusChanged;
+        ONCTROUNDEND            onCTRoundEnd;
     } MasterListener;
 
     class CMaster
@@ -83,6 +88,8 @@
         bool isAlarmReportEnable();
         int proceedWithCarrier(unsigned int port);
         int carrierRelease(unsigned int port);
+        int getContinuousTransferCount();
+        void setContinuousTransferCount(int round);
 
     private:
         inline void lock() { EnterCriticalSection(&m_criticalSection); }
@@ -150,6 +157,11 @@
 
         // 在开始工艺前是否先需要先比较map
         BOOL m_isCompareMapsBeforeProceeding;
+
+        // 千传圈数计数
+        int m_nContinuousTransferCount;
+        int m_nContinuousTransferStep;
+
     private:
         bool m_bEnableEventReport;
         bool m_bEnableAlarmReport;
diff --git a/SourceCode/Bond/Servo/Configuration.cpp b/SourceCode/Bond/Servo/Configuration.cpp
index 08fd582..18ee806 100644
--- a/SourceCode/Bond/Servo/Configuration.cpp
+++ b/SourceCode/Bond/Servo/Configuration.cpp
@@ -160,3 +160,14 @@
 	return GetPrivateProfileInt(_T("Master"), _T("CompareMapsBeforeProceeding"), 0, m_strFilepath);
 }
 
+void CConfiguration::setContinuousTransferCount(int round)
+{
+	WritePrivateProfileString(_T("Master"), _T("CTRound"),
+		std::to_string(round).c_str(), m_strFilepath);
+}
+
+int CConfiguration::getContinuousTransferCount()
+{
+	return GetPrivateProfileInt(_T("Master"), _T("CTRound"), 0, m_strFilepath);
+}
+
diff --git a/SourceCode/Bond/Servo/Configuration.h b/SourceCode/Bond/Servo/Configuration.h
index 8e0d569..96f0e7f 100644
--- a/SourceCode/Bond/Servo/Configuration.h
+++ b/SourceCode/Bond/Servo/Configuration.h
@@ -27,6 +27,8 @@
 	BOOL setPortCassetteType(unsigned int index, int cassetteType);
 	BOOL setPortEnable(unsigned int index, BOOL bEnable);
 	BOOL isCompareMapsBeforeProceeding();
+	void setContinuousTransferCount(int round);
+	int getContinuousTransferCount();
 
 public:
 	void setP2RemoteEqReconnectInterval(int second);
diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index a65aa90..a6299e5 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -362,7 +362,11 @@
 		}
 		notifyPtr(RX_CODE_LOADPORT_STATUS_CHANGED, pEquipment);
 	};
+	masterListener.onCTRoundEnd = [&](void* pMaster, int round) {
+		m_configuration.setContinuousTransferCount(round);
+	};
 	m_master.setListener(masterListener);
+	m_master.setContinuousTransferCount(m_configuration.getContinuousTransferCount());
 
 
 	// master 设置缓存文件
diff --git a/SourceCode/Bond/Servo/PageLog.cpp b/SourceCode/Bond/Servo/PageLog.cpp
index 7fe626a..c5cd4a9 100644
--- a/SourceCode/Bond/Servo/PageLog.cpp
+++ b/SourceCode/Bond/Servo/PageLog.cpp
@@ -79,8 +79,13 @@
 							else {
 								CString strTemp = strText;
 								strTemp.TrimRight();
-								bMatch = std::regex_match((LPTSTR)(LPCTSTR)strTemp,
-									std::regex((LPTSTR)(LPCTSTR)m_strFilterText));
+								try {
+									bMatch = std::regex_match((LPTSTR)(LPCTSTR)strTemp,
+										std::regex((LPTSTR)(LPCTSTR)m_strFilterText));
+								}
+								catch (const std::regex_error& e) {
+
+								}
 							}
 							if (m_filterMode == FilterMode::Exclude) {
 								bMatch = !bMatch;
diff --git a/SourceCode/Bond/Servo/ServoDlg.cpp b/SourceCode/Bond/Servo/ServoDlg.cpp
index 84b1f21..746549b 100644
--- a/SourceCode/Bond/Servo/ServoDlg.cpp
+++ b/SourceCode/Bond/Servo/ServoDlg.cpp
@@ -235,7 +235,15 @@
 						pEq2 = theApp.m_model.getMaster().getEquipment(pTask->getTarPosition());
 						if (pEq1 != nullptr && pEq2 != nullptr) {
 							CString strText;
-							strText.Format(_T("%s --> %s"), pEq1->getName().c_str(), pEq2->getName().c_str());
+							if (theApp.m_model.getMaster().getContinuousTransferCount() > 0) {
+								strText.Format(_T("[%d]%s --> %s"),
+									theApp.m_model.getMaster().getContinuousTransferCount(),
+									pEq1->getName().c_str(), pEq2->getName().c_str());
+							}
+							else {
+								strText.Format(_T("%s --> %s"),
+									pEq1->getName().c_str(), pEq2->getName().c_str());
+							}
 							m_pMyStatusbar->setCurTaskBtnText((LPTSTR)(LPCTSTR)strText);
 						}
 					}

--
Gitblit v1.9.3