From c1c4d51585fd2bf07ecde55224ef241f5b553cfa Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期二, 10 六月 2025 08:42:11 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang

---
 SourceCode/Bond/Servo/CPagePortProperty.cpp |    2 
 SourceCode/Bond/Servo/CPortStatusReport.h   |    7 +
 SourceCode/Bond/Servo/Servo.rc              |    0 
 SourceCode/Bond/Servo/CMaster.cpp           |   51 ++++++--
 SourceCode/Bond/Servo/CLoadPort.cpp         |  203 ++++++++++++++++++---------------
 SourceCode/Bond/Servo/CPortStatusReport.cpp |   41 ++++++
 6 files changed, 197 insertions(+), 107 deletions(-)

diff --git a/SourceCode/Bond/Servo/CLoadPort.cpp b/SourceCode/Bond/Servo/CLoadPort.cpp
index 566faef..6e19e45 100644
--- a/SourceCode/Bond/Servo/CLoadPort.cpp
+++ b/SourceCode/Bond/Servo/CLoadPort.cpp
@@ -20,7 +20,7 @@
 		m_portMode = PortMode::ReadyToLoad;
 		m_cassetteType = CassetteType::G1;
 		m_transferMode = TransferMode::AGVMode;
-		m_bEnable = TRUE;
+		m_bEnable = FALSE;
 		m_bAutoChangeEnable = FALSE;
 	}
 
@@ -376,6 +376,28 @@
 	void CLoadPort::serialize(CArchive& ar)
 	{
 		CEquipment::serialize(ar);
+
+		if (ar.IsStoring()) {
+			ar << m_nIndex;
+			ar << (int)m_portType;
+			ar << (int)m_portMode;
+			ar << (int)m_cassetteType;
+			ar << (int)m_transferMode;
+			ar << m_bEnable;
+			ar << m_bAutoChangeEnable;
+			m_portStatusReport.serialize(ar);
+		}
+		else {
+			int temp;
+			ar >> m_nIndex;
+			ar >> temp; m_portType = (PortType)temp;
+			ar >> temp; m_portMode = (PortMode)temp;
+			ar >> temp; m_cassetteType = (CassetteType)temp;
+			ar >> temp; m_transferMode = (TransferMode)temp;
+			ar >> m_bEnable;
+			ar >> m_bAutoChangeEnable;
+			m_portStatusReport.serialize(ar);
+		}
 	}
 
 	void CLoadPort::getAttributeVector(CAttributeVector& attrubutes)
@@ -891,21 +913,22 @@
 
 		LOGI("<CLoadPort-%d>准备设置Port type<%d>", m_nIndex, (int)type);
 		short value = (short)type;
-		if (onWritedBlock != nullptr) {
-			pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
-		}
-		else {
-			pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
-				if (code == WOK) {
-					LOGI("<CLoadPort-%d>设置Port type成功.", m_nIndex);
-				}
-				else {
-					LOGI("<CLoadPort-%d>设置Port type失败,code:%d", m_nIndex, code);
-				}
+		pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
+			// test
+			code = WOK;
+			if (code == WOK) {
+				m_portType = type;
+				LOGI("<CLoadPort-%d>设置Port type成功.", m_nIndex);
+			}
+			else {
+				LOGI("<CLoadPort-%d>设置Port type失败,code:%d", m_nIndex, code);
+			}
+			if (onWritedBlock != nullptr) {
+				return onWritedBlock(code);
+			}
 
-				return 0;
-				});
-		}
+			return 0;
+			});
 
 		return 0;
 	}
@@ -920,21 +943,21 @@
 
 		LOGI("<CLoadPort-%d>准备%s Port", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
 		short value = bEnable ? 1 : 2;
-		if (onWritedBlock != nullptr) {
-			pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
-		}
-		else {
-			pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
-				if (code == WOK) {
-					LOGI("<CLoadPort-%d>%s Port成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
-				}
-				else {
-					LOGI("<CLoadPort-%d>%s  Port失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
-				}
-
-				return 0;
-				});
-		}
+		pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
+			// test
+			code = WOK;
+			if (code == WOK) {
+				m_bEnable = bEnable;
+				LOGI("<CLoadPort-%d>%s Port成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
+			}
+			else {
+				LOGI("<CLoadPort-%d>%s  Port失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
+			}
+			if (onWritedBlock != nullptr) {
+				return onWritedBlock(code);
+			}
+			return 0;
+			});
 
 		return 0;
 	}
@@ -949,21 +972,21 @@
 
 		LOGI("<CLoadPort-%d>准备设置Port mode<%d>", m_nIndex, (int)mode);
 		short value = (short)mode;
-		if (onWritedBlock != nullptr) {
-			pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
-		}
-		else {
-			pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
-				if (code == WOK) {
-					LOGI("<CLoadPort-%d>设置Port mode成功.", m_nIndex);
-				}
-				else {
-					LOGI("<CLoadPort-%d>设置Port mode失败,code:%d", m_nIndex, code);
-				}
-
-				return 0;
-				});
-		}
+		pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
+			// test
+			code = WOK;
+			if (code == WOK) {
+				m_portMode = mode;
+				LOGI("<CLoadPort-%d>设置Port mode成功.", m_nIndex);
+			}
+			else {
+				LOGI("<CLoadPort-%d>设置Port mode失败,code:%d", m_nIndex, code);
+			}
+			if (onWritedBlock != nullptr) {
+				return onWritedBlock(code);
+			}
+			return 0;
+			});
 
 		return 0;
 	}
@@ -978,21 +1001,21 @@
 
 		LOGI("<CLoadPort-%d>准备设置Cassette Type<%d>", m_nIndex, (int)type);
 		short value = (short)type;
-		if (onWritedBlock != nullptr) {
-			pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
-		}
-		else {
-			pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
-				if (code == WOK) {
-					LOGI("<CLoadPort-%d>设置Cassette Type成功.", m_nIndex);
-				}
-				else {
-					LOGI("<CLoadPort-%d>设置Cassette Type失败,code:%d", m_nIndex, code);
-				}
-
-				return 0;
-				});
-		}
+		pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
+			// test
+			code = WOK;
+			if (code == WOK) {
+				m_cassetteType = type;
+				LOGI("<CLoadPort-%d>设置Cassette Type成功.", m_nIndex);
+			}
+			else {
+				LOGI("<CLoadPort-%d>设置Cassette Type失败,code:%d", m_nIndex, code);
+			}
+			if (onWritedBlock != nullptr) {
+				return onWritedBlock(code);
+			}
+			return 0;
+			});
 
 		return 0;
 	}
@@ -1007,21 +1030,21 @@
 
 		LOGI("<CLoadPort-%d>准备设置Transfer mode<%d>", m_nIndex, (int)mode);
 		short value = (short)mode;
-		if (onWritedBlock != nullptr) {
-			pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
-		}
-		else {
-			pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
-				if (code == WOK) {
-					LOGI("<CLoadPort-%d>设置Transfer mode成功.", m_nIndex + 1);
-				}
-				else {
-					LOGI("<CLoadPort-%d>设置Transfer mode失败,code:%d", m_nIndex + 1, code);
-				}
-
-				return 0;
-				});
-		}
+		pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
+			// test
+			code = WOK;
+			if (code == WOK) {
+				m_transferMode = mode;
+				LOGI("<CLoadPort-%d>设置Transfer mode成功.", m_nIndex + 1);
+			}
+			else {
+				LOGI("<CLoadPort-%d>设置Transfer mode失败,code:%d", m_nIndex + 1, code);
+			}
+			if (onWritedBlock != nullptr) {
+				return onWritedBlock(code);
+			}
+			return 0;
+			});
 
 		return 0;
 	}
@@ -1036,21 +1059,21 @@
 
 		LOGI("<CLoadPort-%d>准备%s Auto Change", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
 		short value = bEnable ? 1 : 2;
-		if (onWritedBlock != nullptr) {
-			pStep->writeDataEx((const char*)&value, sizeof(short), onWritedBlock);
-		}
-		else {
-			pStep->writeDataEx((const char*)&value, sizeof(short), [&](int code) -> int {
-				if (code == WOK) {
-					LOGI("<CLoadPort-%d>%s Auto Change成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
-				}
-				else {
-					LOGI("<CLoadPort-%d>%s  Auto Change失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
-				}
-
-				return 0;
-				});
-		}
+		pStep->writeDataEx((const char*)&value, sizeof(short), [&, onWritedBlock](int code) -> int {
+			// test
+			code = WOK;
+			if (code == WOK) {
+				m_bAutoChangeEnable = bEnable;
+				LOGI("<CLoadPort-%d>%s Auto Change成功.", m_nIndex, bEnable ? _T("启用") : _T("禁用"));
+			}
+			else {
+				LOGI("<CLoadPort-%d>%s  Auto Change失败,code:%d", m_nIndex, bEnable ? _T("启用") : _T("禁用"), code);
+			}
+			if (onWritedBlock != nullptr) {
+				return onWritedBlock(code);
+			}
+			return 0;
+			});
 
 		return 0;
 	}
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index 0a3b906..7b24735 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -375,6 +375,37 @@
 				}
 
 
+				// Measurement -> LoadPort
+				CLoadPort* pEqLoadPort[] = { pLoadPort1, pLoadPort2, pLoadPort3, pLoadPort4 };
+				CEquipment* pEqTar[] = { pVacuumBack, pFliper };
+				if (primaryType == MaterialsType::G2) {
+					pEqTar[0] = pFliper;
+					pEqTar[1] = pVacuumBack;
+				}
+				for (int s = 0; s < 4; s++) {
+					if (pEqLoadPort[s]->isEnable()
+						&& pEqLoadPort[s]->getPortType() == PortType::Unloading
+						&& pEqLoadPort[s]->getPortMode() == PortMode::ReadyToUnload) {
+						m_pActiveRobotTask = createTransferTask(pMeasurement, pEqLoadPort[s], primaryType, secondaryType);
+						if (m_pActiveRobotTask != nullptr) {
+							goto PORT_PUT;
+						}
+					}
+				}
+
+			PORT_PUT:
+				if (m_pActiveRobotTask != nullptr) {
+					m_pActiveRobotTask->run();
+					std::string strDescription = m_pActiveRobotTask->getDescription();
+					unlock();
+					if (m_listener.onRobotTaskEvent != nullptr) {
+						m_listener.onRobotTaskEvent(this, m_pActiveRobotTask, ROBOT_EVENT_CREATE);
+					}
+					LOGI("创建新任务<%s>...", strDescription.c_str());
+					continue;
+				}
+
+
 				// BakeCooling ->Measurement
 				m_pActiveRobotTask = createTransferTask_bakecooling_to_measurement(pBakeCooling, pMeasurement);
 				if (m_pActiveRobotTask != nullptr) {
@@ -484,18 +515,12 @@
 
 				// LoadPort -> Fliper(G2)
 				// LoadPort -> VacuumBake(G1)
-				CLoadPort* pEqSrc[] = { pLoadPort1, pLoadPort2, pLoadPort3, pLoadPort4 };
-				CEquipment* pEqTar[] = { pVacuumBack, pFliper };
-				if (primaryType == MaterialsType::G2) {
-					pEqTar[0] = pFliper;
-					pEqTar[1] = pVacuumBack;
-				}
 				for (int s = 0; s < 4; s++) {
 					for (int t = 0; t < 2; t++) {
-						if (pEqSrc[s]->isEnable()
-							&& pEqSrc[s]->getPortType() == PortType::Loading
-							&& pEqSrc[s]->getPortMode() == PortMode::ReadyToLoad) {
-							m_pActiveRobotTask = createTransferTask(pEqSrc[s], pEqTar[t], primaryType, secondaryType);
+						if (pEqLoadPort[s]->isEnable()
+							&& pEqLoadPort[s]->getPortType() == PortType::Loading
+							&& pEqLoadPort[s]->getPortMode() == PortMode::ReadyToLoad) {
+							m_pActiveRobotTask = createTransferTask(pEqLoadPort[s], pEqTar[t], primaryType, secondaryType);
 							if (m_pActiveRobotTask != nullptr) {
 								goto PORT_GET;
 							}
@@ -514,11 +539,6 @@
 					LOGI("创建新任务<%s>...", strDescription.c_str());
 					continue;
 				}
-
-
-				// Measurement -> LoadPort
-
-
 
 				unlock();
 
@@ -1187,6 +1207,7 @@
 		if (pSrcSlot != nullptr && nullptr != pTarSlot) {
 			pTask = new CRobotTask();
 			pTask->setContext(pSrcSlot->getContext());
+			pTask->setEFEM((CEFEM*)getEquipment(EQ_ID_EFEM));
 			pTask->setRobotTransferParam(++taskSeqNo, 1, pSrcSlot->getPosition(),
 				pTarSlot->getPosition(), pSrcSlot->getNo(), pTarSlot->getNo());
 		}
diff --git a/SourceCode/Bond/Servo/CPagePortProperty.cpp b/SourceCode/Bond/Servo/CPagePortProperty.cpp
index 2ce463e..2cdc999 100644
--- a/SourceCode/Bond/Servo/CPagePortProperty.cpp
+++ b/SourceCode/Bond/Servo/CPagePortProperty.cpp
@@ -69,7 +69,7 @@
 
 	pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_PORT_MODE);
 	for (int i = 0; i <= 5; i++) {
-		pComboBox->InsertString(i - 1, SERVO::CLoadPort::getPortModeDescription((SERVO::PortMode)i, strTemp).c_str());
+		pComboBox->InsertString(i, SERVO::CLoadPort::getPortModeDescription((SERVO::PortMode)i, strTemp).c_str());
 	}
 	int portMode = (int)m_pPort->getPortMode();
 	if (0 <= portMode && portMode <= 5) {
diff --git a/SourceCode/Bond/Servo/CPortStatusReport.cpp b/SourceCode/Bond/Servo/CPortStatusReport.cpp
index 6b2b7ca..03864e2 100644
--- a/SourceCode/Bond/Servo/CPortStatusReport.cpp
+++ b/SourceCode/Bond/Servo/CPortStatusReport.cpp
@@ -176,6 +176,34 @@
 			std::to_string(m_nCassetteStatus).c_str(), "", weight++));
 	}
 
+	void CPortStatusReport::serialize(CArchive& ar)
+	{
+		if (ar.IsStoring()) {
+			ar << m_nPortStatus;
+			ar << m_nCassetteSequenceNo;
+			WriteString(ar, m_strCassetteID);
+			for (int i = 0; i < 12; i++) {
+				ar << m_nJobExistenceSlot[i];
+			}
+			ar << m_nLoadingCassetteType;
+			ar << m_nQTimeFlag;
+			ar << m_nCassetteMappingState;
+			ar << m_nCassetteStatus;
+		}
+		else {
+			ar >> m_nPortStatus;
+			ar >> m_nCassetteSequenceNo;
+			ReadString(ar, m_strCassetteID);
+			for (int i = 0; i < 12; i++) {
+				ar >> m_nJobExistenceSlot[i];
+			}
+			ar >> m_nLoadingCassetteType;
+			ar >> m_nQTimeFlag;
+			ar >> m_nCassetteMappingState;
+			ar >> m_nCassetteStatus;
+		}
+	}
+
 	bool CPortStatusReport::canPickFromPort()
 	{
 		// 1. Port 状态必须是 Load Ready(上料请求)
@@ -208,5 +236,18 @@
 
 		return false;
 	}
+
+	void CPortStatusReport::WriteString(CArchive& ar, std::string& string)
+	{
+		CString strTemp = string.c_str();
+		ar << strTemp;
+	}
+
+	void CPortStatusReport::ReadString(CArchive& ar, std::string& string)
+	{
+		CString strTemp;
+		ar >> strTemp;
+		string = (LPTSTR)(LPCTSTR)strTemp;
+	}
 }
 
diff --git a/SourceCode/Bond/Servo/CPortStatusReport.h b/SourceCode/Bond/Servo/CPortStatusReport.h
index 21d5048..526c94a 100644
--- a/SourceCode/Bond/Servo/CPortStatusReport.h
+++ b/SourceCode/Bond/Servo/CPortStatusReport.h
@@ -23,12 +23,17 @@
 		int serialize(char* pszBuffer, int nBufferSize);
 		int unserialize(const char* pszBuffer, int nBufferSize);
 		void getAttributeVector(CAttributeVector& attrubutes, int beginWeight);
-		
+		virtual void serialize(CArchive& ar);
+
 	public:
 		bool canPickFromPort();
 		bool isJobExistenceSlot();
 
 	private:
+		void WriteString(CArchive& ar, std::string& string);
+		void ReadString(CArchive& ar, std::string& string);
+
+	private:
 		short m_nPortStatus;
 		short m_nCassetteSequenceNo;
 		std::string m_strCassetteID;
diff --git a/SourceCode/Bond/Servo/Servo.rc b/SourceCode/Bond/Servo/Servo.rc
index 8a548dd..7f2c66a 100644
--- a/SourceCode/Bond/Servo/Servo.rc
+++ b/SourceCode/Bond/Servo/Servo.rc
Binary files differ

--
Gitblit v1.9.3