From b48dbe316b557f9cd0698cfbb4a4230cb4685a98 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 12 二月 2026 16:52:39 +0800
Subject: [PATCH] 1.ProcessStart后,停止再启动软件,不能创建调度任务,需要重启软件。修复:启动时复位千传相关变是。注:待测试验证。

---
 SourceCode/Bond/Servo/CMaster.cpp |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index cbdcc22..0252eaa 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -372,6 +372,20 @@
 			return -1;
 		}
 
+		lock();
+		// Ensure stale transfer state does not leak across runs.
+		m_nContinuousTransferStep = CTStep_Unknow;
+		m_nContinuousWorkingPort = 0;
+		m_nContinuousWorkingSlot = 0;
+		if (m_pActiveRobotTask != nullptr) {
+			LOGW("<Master>start: stale active robot task found in READY, clearing it.");
+			delete m_pActiveRobotTask;
+			m_pActiveRobotTask = nullptr;
+		}
+		unlock();
+		LOGI("<Master>start reset transfer state(step=%d, port=%d, slot=%d).",
+			m_nContinuousTransferStep, m_nContinuousWorkingPort, m_nContinuousWorkingSlot);
+
 		m_bContinuousTransfer = false;
 		m_bBatch = false;
 		setState(MASTERSTATE::STARTING);
@@ -386,6 +400,20 @@
 			return -1;
 		}
 
+		lock();
+		// Continuous transfer must start from a clean state every time.
+		m_nContinuousTransferStep = CTStep_Unknow;
+		m_nContinuousWorkingPort = 0;
+		m_nContinuousWorkingSlot = 0;
+		if (m_pActiveRobotTask != nullptr) {
+			LOGW("<Master>startContinuousTransfer: stale active robot task found in READY, clearing it.");
+			delete m_pActiveRobotTask;
+			m_pActiveRobotTask = nullptr;
+		}
+		unlock();
+		LOGI("<Master>startContinuousTransfer reset transfer state(step=%d, port=%d, slot=%d).",
+			m_nContinuousTransferStep, m_nContinuousWorkingPort, m_nContinuousWorkingSlot);
+
 		m_bContinuousTransfer = true;
 		m_bBatch = false;
 		setState(MASTERSTATE::STARTING);
@@ -400,6 +428,20 @@
 			return -1;
 		}
 
+		lock();
+		// Keep behavior consistent with other start paths.
+		m_nContinuousTransferStep = CTStep_Unknow;
+		m_nContinuousWorkingPort = 0;
+		m_nContinuousWorkingSlot = 0;
+		if (m_pActiveRobotTask != nullptr) {
+			LOGW("<Master>startBatch: stale active robot task found in READY, clearing it.");
+			delete m_pActiveRobotTask;
+			m_pActiveRobotTask = nullptr;
+		}
+		unlock();
+		LOGI("<Master>startBatch reset transfer state(step=%d, port=%d, slot=%d).",
+			m_nContinuousTransferStep, m_nContinuousWorkingPort, m_nContinuousWorkingSlot);
+
 		m_bContinuousTransfer = false;
 		m_bBatch = true;
 		setState(MASTERSTATE::STARTING);

--
Gitblit v1.9.3