From 96266d494fe227a0481c305f9c859e69421da6ae Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期三, 18 六月 2025 14:36:37 +0800
Subject: [PATCH] 1.CEqWriteStep, 写数据时,有时还要读取对方的返回值,增加获取返回数据的功能;

---
 SourceCode/Bond/Servo/CEqWriteStep.h   |    2 +
 SourceCode/Bond/Servo/CWriteStep.h     |   12 ++++++
 SourceCode/Bond/Servo/CWriteStep.cpp   |   29 ++++++++++++++
 SourceCode/Bond/Servo/CEqWriteStep.cpp |    9 ++++
 SourceCode/Bond/Servo/CEquipment.cpp   |   36 ++++++++++--------
 SourceCode/Bond/Servo/CEFEM.cpp        |    3 +
 SourceCode/Bond/Servo/CEquipment.h     |    3 +
 SourceCode/Bond/Servo/CBonder.cpp      |   12 ++++++
 SourceCode/Bond/Servo/Common.h         |    2 
 9 files changed, 89 insertions(+), 19 deletions(-)

diff --git a/SourceCode/Bond/Servo/CBonder.cpp b/SourceCode/Bond/Servo/CBonder.cpp
index 51c064b..0943eea 100644
--- a/SourceCode/Bond/Servo/CBonder.cpp
+++ b/SourceCode/Bond/Servo/CBonder.cpp
@@ -337,6 +337,18 @@
 		}
 
 		{
+			// Indexer Operation Mode Change
+			CEqWriteStep* pStep = new CEqWriteStep();
+			pStep->setName(STEP_EQ_IN_OP_MODE_CHANGE);
+			pStep->setWriteSignalDev(0x370);
+			pStep->setDataDev(0x923);
+			pStep->setRetDataDev(0xa00e, 2);
+			if (addStep(STEP_ID_IN_OP_CMD_REPLY, pStep) != 0) {
+				delete pStep;
+			}
+		}
+
+		{
 			// Panel Data Report
 			CEqReadStep* pStep = new CEqReadStep(0xA17f, 386 * 2,
 				[&](void* pFrom, int code, const char* pszData, size_t size) -> int {
diff --git a/SourceCode/Bond/Servo/CEFEM.cpp b/SourceCode/Bond/Servo/CEFEM.cpp
index dd297b1..c9f4f2e 100644
--- a/SourceCode/Bond/Servo/CEFEM.cpp
+++ b/SourceCode/Bond/Servo/CEFEM.cpp
@@ -580,9 +580,10 @@
 		{
 			// Indexer Operation Mode Change
 			CEqWriteStep* pStep = new CEqWriteStep();
-			pStep->setName(STEP_EFEM_IN_OP_MODE_CHANGE);
+			pStep->setName(STEP_EQ_IN_OP_MODE_CHANGE);
 			pStep->setWriteSignalDev(0x070);
 			pStep->setDataDev(0x023);
+			pStep->setRetDataDev(0x600e, 2);
 			if (addStep(STEP_ID_IN_OP_CMD_REPLY, pStep) != 0) {
 				delete pStep;
 			}
diff --git a/SourceCode/Bond/Servo/CEqWriteStep.cpp b/SourceCode/Bond/Servo/CEqWriteStep.cpp
index 5bd1025..0546675 100644
--- a/SourceCode/Bond/Servo/CEqWriteStep.cpp
+++ b/SourceCode/Bond/Servo/CEqWriteStep.cpp
@@ -64,4 +64,13 @@
 
 		return 0;
 	}
+
+	int CEqWriteStep::onReadRetDataError()
+	{
+		if (m_onWritedBlock != nullptr) {
+			m_onWritedBlock(WREAD_RET_ERR);
+		}
+
+		return 0;
+	}
 }
diff --git a/SourceCode/Bond/Servo/CEqWriteStep.h b/SourceCode/Bond/Servo/CEqWriteStep.h
index 2ec74ba..0684a30 100644
--- a/SourceCode/Bond/Servo/CEqWriteStep.h
+++ b/SourceCode/Bond/Servo/CEqWriteStep.h
@@ -5,6 +5,7 @@
 
 #define WOK				0
 #define WTIMEOUT		-1
+#define WREAD_RET_ERR	-2
 
 namespace SERVO {
 	typedef std::function<int(int code)> ONWRITED;
@@ -23,6 +24,7 @@
 		int writeDataEx(const char* pszData, int size, ONWRITED onWritedBlock = nullptr);
 		virtual int onComplete();
 		virtual int onTimeout();
+		virtual int onReadRetDataError();
 
 	private:
 		int m_nDataDev;
diff --git a/SourceCode/Bond/Servo/CEquipment.cpp b/SourceCode/Bond/Servo/CEquipment.cpp
index d380f13..ef24f61 100644
--- a/SourceCode/Bond/Servo/CEquipment.cpp
+++ b/SourceCode/Bond/Servo/CEquipment.cpp
@@ -1012,30 +1012,34 @@
 		return 0;
 	}
 
-	int CEquipment::indexerOperationModeChange(IDNEXER_OPERATION_MODE mode, ONWRITED onWritedBlock/* = nullptr*/)
+	int CEquipment::indexerOperationModeChange(IDNEXER_OPERATION_MODE mode, ONWRITEDRET onWritedRetBlock)
 	{
-		SERVO::CEqWriteStep* pStep = (SERVO::CEqWriteStep*)getStepWithName(STEP_EFEM_IN_OP_MODE_CHANGE);
+		SERVO::CEqWriteStep* pStep = (SERVO::CEqWriteStep*)getStepWithName(STEP_EQ_IN_OP_MODE_CHANGE);
 		if (pStep == nullptr) {
 			return -1;
 		}
 
 		unsigned short operationMode = (unsigned short)((unsigned short)mode + getIndexerOperationModeBaseValue());
 		LOGI("<CEquipment-%s>准备设置indexerOperationMode<%d>", m_strName.c_str(), (int)mode);
-		if (onWritedBlock != nullptr) {
-			pStep->writeShort(operationMode, onWritedBlock);
-		}
-		else {
-			pStep->writeShort(operationMode, [&, mode](int code) -> int {
-				if (code == WOK) {
-					LOGI("<CEquipment-%s>设置indexerOperationMode成功.", m_strName.c_str());
-				}
-				else {
-					LOGI("<CEquipment-%s>设置indexerOperationMode失败,code:%d", m_strName.c_str(), code);
-				}
+		pStep->writeShort(operationMode, [&, mode](int code) -> int {
+			int retCode = 0;
+			if (code == WOK) {
+				LOGI("<CEquipment-%s>设置indexerOperationMode成功.", m_strName.c_str());
+				const char* pszRetData = nullptr;
+				pStep->getReturnData(pszRetData);
+				ASSERT(pszRetData);
+				retCode = (unsigned int)CToolUnits::toInt16(pszRetData);	
+			}
+			else {
+				LOGI("<CEquipment-%s>设置indexerOperationMode失败,code:%d", m_strName.c_str(), code);
+			}
 
-				return 0;
-				});
-		}
+			if (onWritedRetBlock != nullptr) {
+				onWritedRetBlock(code, retCode);
+			}
+
+			return 0;
+		});
 
 		return 0;
 	}
diff --git a/SourceCode/Bond/Servo/CEquipment.h b/SourceCode/Bond/Servo/CEquipment.h
index c694bf6..76e78b0 100644
--- a/SourceCode/Bond/Servo/CEquipment.h
+++ b/SourceCode/Bond/Servo/CEquipment.h
@@ -43,6 +43,7 @@
 #define SIGNAL_UPSTREAM_TROUBLE	1
 #define SIGNAL_INTERLOCK		2
 #define SIGNAL_SEND_ABLE		3
+	typedef std::function<int(int writeCode, int retCode)> ONWRITEDRET;
 
 	typedef std::function<void(void* pEiuipment, BOOL bAlive)> ONALIVE;
 	typedef std::function<void(void* pEiuipment, int code)> ONDATACHANGED;
@@ -140,7 +141,7 @@
 		int clearCimMessage(short id, short nTouchPanelNo);
 		int setDateTime(short year, short month, short day, short hour, short minute, short second);
 		int setDispatchingMode(DISPATCHING_MODE mode, ONWRITED onWritedBlock = nullptr);
-		int indexerOperationModeChange(IDNEXER_OPERATION_MODE mode, ONWRITED onWritedBlock = nullptr);
+		int indexerOperationModeChange(IDNEXER_OPERATION_MODE mode, ONWRITEDRET onWritedRetBlock);
 
 
 
diff --git a/SourceCode/Bond/Servo/CWriteStep.cpp b/SourceCode/Bond/Servo/CWriteStep.cpp
index 0470421..2e79b5a 100644
--- a/SourceCode/Bond/Servo/CWriteStep.cpp
+++ b/SourceCode/Bond/Servo/CWriteStep.cpp
@@ -55,6 +55,18 @@
 		m_nWriteSignalDev = dev;
 	}
 
+	void CWriteStep::setRetDataDev(int dev, int size)
+	{
+		m_nReturnDevNo = dev;
+		m_nReturnDataSize = size;
+	}
+
+	int CWriteStep::getReturnData(const char*& pszData)
+	{
+		pszData = m_szReturnBuf;
+		return m_nReturnDataSize;
+	}
+
 	void CWriteStep::onRecvSignal(BOOL bSignal)
 	{
 		Lock();
@@ -111,6 +123,18 @@
 					goto RESET;
 				}
 				ResetEvent(m_hRecvSignalOn);
+
+
+				// 3.9读数据,如果有
+				if (m_nReturnDataSize > 0) {
+					int nRet = m_pCclink->ReadData2(m_station, DeviceType::W, m_nReturnDevNo,
+						(long)min(READ_BUFFER_MAX, m_nReturnDataSize), m_szReturnBuf);
+					if (0 != nRet) {
+						LOGI("<CEqReadStep>Read return data error.");
+						onReadRetDataError();
+						return -1;
+					}
+				}
 
 
 				// 4.写OFF
@@ -196,4 +220,9 @@
 	{
 		return 0;
 	}
+
+	int CWriteStep::onReadRetDataError()
+	{
+		return 0;
+	}
 }
diff --git a/SourceCode/Bond/Servo/CWriteStep.h b/SourceCode/Bond/Servo/CWriteStep.h
index 6bb6b30..e8e66cf 100644
--- a/SourceCode/Bond/Servo/CWriteStep.h
+++ b/SourceCode/Bond/Servo/CWriteStep.h
@@ -19,8 +19,14 @@
 		virtual void getAttributeVector(CAttributeVector& attrubutes);
 		virtual int onComplete();
 		virtual int onTimeout();
+		virtual int onReadRetDataError();
 		inline void nextStep();
 		inline void resetStep();
+		virtual void setRetDataDev(int dev, int size);
+
+	public:
+		int getReturnData(const char*& pszData);
+
 
 	protected:
 		HANDLE m_hWorkThreadHandle;
@@ -33,6 +39,12 @@
 		char m_szBuffer[1024];
 		int m_nWriteDataSize;
 		int m_nWriteDevNo;
+
+	protected:
+		// return code or data
+		char m_szReturnBuf[1024];
+		int m_nReturnDataSize;
+		int m_nReturnDevNo;
 	};
 }
 
diff --git a/SourceCode/Bond/Servo/Common.h b/SourceCode/Bond/Servo/Common.h
index a3296d6..3a3055d 100644
--- a/SourceCode/Bond/Servo/Common.h
+++ b/SourceCode/Bond/Servo/Common.h
@@ -218,7 +218,7 @@
 #define STEP_EQ_STORED_JOB15			_T("EQStoredJobReport15")
 #define STEP_EQ_DISPATCHINT_MODE_CHANGE	_T("EQDispatchingModeChangeCommand")
 #define STEP_EFEM_ROBOT_CMD				_T("EFEMRobotCmd")
-#define STEP_EFEM_IN_OP_MODE_CHANGE		_T("EFEMIndexerOperationModeChangeCommand")
+#define STEP_EQ_IN_OP_MODE_CHANGE		_T("EQIndexerOperationModeChangeCommand")
 #define STEP_PORT1_TYPE_CHANGE			_T("Port1TypeChange")
 #define STEP_PORT2_TYPE_CHANGE			_T("Port2TypeChange")
 #define STEP_PORT3_TYPE_CHANGE			_T("Port3TypeChange")

--
Gitblit v1.9.3