diff --git a/src/components/LogicAnalyzer/LogicAnalyzerManager.ts b/src/components/LogicAnalyzer/LogicAnalyzerManager.ts index a2841dc..546f7ee 100644 --- a/src/components/LogicAnalyzer/LogicAnalyzerManager.ts +++ b/src/components/LogicAnalyzer/LogicAnalyzerManager.ts @@ -298,9 +298,8 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( return; } - const release = await operationMutex.acquire(); isCapturing.value = true; - + const release = await operationMutex.acquire(); try { const client = AuthManager.createAuthenticatedLogicAnalyzerClient(); @@ -313,17 +312,14 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( alert?.info("开始捕获信号...", 2000); // 2. 轮询捕获状态 - const pollCaptureStatus = async (): Promise => { - // 如果不再处于捕获状态,说明被停止了 - if (!isCapturing.value) { - return false; - } - + let captureCompleted = false; + while (isCapturing.value) { const status = await client.getCaptureStatus(); // 检查是否捕获完成 if (status === CaptureStatus.CaptureDone) { - return true; + captureCompleted = true; + break; } // 检查是否仍在捕获中 @@ -334,22 +330,19 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( ) { // 等待500毫秒后继续轮询 await new Promise((resolve) => setTimeout(resolve, 500)); - return await pollCaptureStatus(); + continue; } // 其他状态视为错误 - throw new Error(`捕获状态异常: ${status}`); - }; - - // 等待捕获完成 - const captureCompleted = await pollCaptureStatus(); + // throw new Error(`捕获状态异常: ${status}`); + } // 如果捕获被停止,不继续处理数据 if (!captureCompleted) { alert?.info("捕获已停止", 2000); return; } - + await getCaptureData(); alert.success(`捕获完成!`, 3000); } catch (error) { @@ -371,27 +364,45 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( return; } + // 设置捕获状态为false,这会使轮询停止 + isCapturing.value = false; + + const release = await operationMutex.acquire(); try { const client = AuthManager.createAuthenticatedLogicAnalyzerClient(); // 执行强制捕获来停止当前捕获 - const forceSuccess = await client.setCaptureMode(false, true); + const forceSuccess = await client.setCaptureMode(false, false); if (!forceSuccess) { - throw new Error("无法执行强制捕获"); + throw new Error("无法停止捕获"); } - // 设置捕获状态为false,这会使轮询停止 - isCapturing.value = false; - alert.info("已停止强制捕获...", 2000); } catch (error) { console.error("停止捕获失败:", error); + alert.error( + `停止捕获失败: ${error instanceof Error ? error.message : "未知错误"}`, + 3000, + ); + } finally { + release(); } }; const forceCapture = async () => { + // 设置捕获状态为false,这会使轮询停止 + isCapturing.value = false; + + const release = await operationMutex.acquire(); try { - await stopCapture(); + const client = AuthManager.createAuthenticatedLogicAnalyzerClient(); + + // 执行强制捕获来停止当前捕获 + const forceSuccess = await client.setCaptureMode(true, true); + if (!forceSuccess) { + throw new Error("无法执行强制捕获"); + } + await getCaptureData(); alert.success(`捕获完成!`, 3000); } catch (error) { @@ -400,6 +411,8 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( `强制捕获失败: ${error instanceof Error ? error.message : "未知错误"}`, 3000, ); + } finally{ + release(); } }; diff --git a/src/components/LogicAnalyzer/LogicalWaveFormDisplay.vue b/src/components/LogicAnalyzer/LogicalWaveFormDisplay.vue index f527e88..0573cb6 100644 --- a/src/components/LogicAnalyzer/LogicalWaveFormDisplay.vue +++ b/src/components/LogicAnalyzer/LogicalWaveFormDisplay.vue @@ -46,9 +46,6 @@ 'from-red-500 to-red-600 hover:from-red-600 hover:to-red-700 focus:ring-red-300': analyzer.isCapturing.value, }" - :disabled=" - analyzer.isOperationInProgress.value && !analyzer.isCapturing.value - " @click=" analyzer.isCapturing.value ? analyzer.stopCapture() @@ -71,7 +68,6 @@