From 446da525153967172b19c7b01d5686d1fd058865 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Tue, 15 Jul 2025 20:37:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=88=86=E6=9E=90=E4=BB=AA=E7=9A=84=E6=8D=95=E8=8E=B7=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LogicAnalyzer/LogicAnalyzerManager.ts | 43 ++++++++++++++++++- .../LogicAnalyzer/LogicalWaveFormDisplay.vue | 32 +++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/components/LogicAnalyzer/LogicAnalyzerManager.ts b/src/components/LogicAnalyzer/LogicAnalyzerManager.ts index 966169e..16f8dee 100644 --- a/src/components/LogicAnalyzer/LogicAnalyzerManager.ts +++ b/src/components/LogicAnalyzer/LogicAnalyzerManager.ts @@ -262,6 +262,11 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( // 2. 轮询捕获状态 const pollCaptureStatus = async (): Promise => { + // 如果不再处于捕获状态,说明被停止了 + if (!isCapturing.value) { + return false; + } + const status = await client.getCaptureStatus(); // 检查是否捕获完成 @@ -285,7 +290,13 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( }; // 等待捕获完成 - await pollCaptureStatus(); + const captureCompleted = await pollCaptureStatus(); + + // 如果捕获被停止,不继续处理数据 + if (!captureCompleted) { + alert?.info("捕获已停止", 2000); + return; + } // 3. 获取捕获数据 const base64Data = await client.getCaptureData(); @@ -341,6 +352,35 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( } }; + const stopCapture = async () => { + // 检查是否正在捕获 + if (!isCapturing.value) { + alert.warn("当前没有正在进行的捕获操作", 2000); + return; + } + + try { + const client = AuthManager.createAuthenticatedLogicAnalyzerClient(); + + // 执行强制捕获来停止当前捕获 + const forceSuccess = await client.setCaptureMode(false, true); + if (!forceSuccess) { + throw new Error("无法执行强制捕获"); + } + + // 设置捕获状态为false,这会使轮询停止 + isCapturing.value = false; + + alert?.info("正在停止捕获...", 2000); + } catch (error) { + console.error("停止捕获失败:", error); + alert?.error( + `停止捕获失败: ${error instanceof Error ? error.message : "未知错误"}`, + 3000, + ); + } + }; + // 添加检查操作状态的计算属性 const isOperationInProgress = computed( () => isApplying.value || isCapturing.value || operationMutex.isLocked(), @@ -446,6 +486,7 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( resetConfiguration, setLogicData, startCapture, + stopCapture, // 添加停止捕获方法 generateTestData, }; }, diff --git a/src/components/LogicAnalyzer/LogicalWaveFormDisplay.vue b/src/components/LogicAnalyzer/LogicalWaveFormDisplay.vue index 92f81c2..0ab7e12 100644 --- a/src/components/LogicAnalyzer/LogicalWaveFormDisplay.vue +++ b/src/components/LogicAnalyzer/LogicalWaveFormDisplay.vue @@ -24,7 +24,7 @@

点击下方按钮生成测试数据用于观察

- --> + @@ -45,7 +73,7 @@