fix: 尝试修复示波器与旋转编码器无法工作的问题

This commit is contained in:
SikongJueluo 2025-08-20 16:40:38 +08:00
parent 62c16c016d
commit 4c9b9cd3d6
3 changed files with 8 additions and 9 deletions

View File

@ -212,11 +212,10 @@ public class OscilloscopeHub : Hub<IOscilloscopeReceiver>, IOscilloscopeHub
var key = (board.ID.ToString(), Context.ConnectionId); var key = (board.ID.ToString(), Context.ConnectionId);
if (_scanTasks.TryRemove(key, out var scanInfo)) if (_scanTasks.TryRemove(key, out var taskInfo))
{ {
scanInfo.CTS.Cancel(); taskInfo.CTS.Cancel();
if (scanInfo.ScanTask != null) await scanInfo.ScanTask; if (taskInfo.ScanTask != null) taskInfo.ScanTask.Wait();
scanInfo.CTS.Dispose();
var result = await client.SetCaptureEnable(false); var result = await client.SetCaptureEnable(false);
if (!result.IsSuccessful) if (!result.IsSuccessful)

View File

@ -84,7 +84,7 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(
clearHub(); clearHub();
}); });
function initHub() { async function initHub() {
if (oscilloscopeHub.value) return; if (oscilloscopeHub.value) return;
const connection = AuthManager.createHubConnection("OscilloscopeHub"); const connection = AuthManager.createHubConnection("OscilloscopeHub");
@ -96,7 +96,7 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(
connection, connection,
oscilloscopeReceiver, oscilloscopeReceiver,
); );
connection.start(); await connection.start();
oscilloscopeHub.value = { connection, proxy }; oscilloscopeHub.value = { connection, proxy };
} }
@ -252,12 +252,12 @@ const [useProvideOscilloscope, useOscilloscopeState] = createInjectionState(
alert.warn("当前没有正在进行的捕获操作", 2000); alert.warn("当前没有正在进行的捕获操作", 2000);
return; return;
} }
isCapturing.value = false;
const release = await operationMutex.acquire(); const release = await operationMutex.acquire();
try { try {
const proxy = getHubProxy(); const proxy = getHubProxy();
const stopped = await proxy.stopCapture(); const stopped = await proxy.stopCapture();
if (!stopped) throw new Error("无法停止捕获"); if (!stopped) throw new Error("无法停止捕获");
isCapturing.value = false;
alert.info("捕获已停止", 2000); alert.info("捕获已停止", 2000);
} catch (error) { } catch (error) {
alert.error("停止捕获失败", 3000); alert.error("停止捕获失败", 3000);

View File

@ -30,7 +30,7 @@ export const useRotaryEncoder = defineStore("RotaryEncoder", () => {
clearHub(); clearHub();
}); });
function initHub() { async function initHub() {
if (rotaryEncoderHub.value) return; if (rotaryEncoderHub.value) return;
const connection = AuthManager.createHubConnection("RotaryEncoderHub"); const connection = AuthManager.createHubConnection("RotaryEncoderHub");
const proxy = const proxy =
@ -39,7 +39,7 @@ export const useRotaryEncoder = defineStore("RotaryEncoder", () => {
connection, connection,
rotaryEncoderReceiver, rotaryEncoderReceiver,
); );
connection.start(); await connection.start();
rotaryEncoderHub.value = { connection, proxy }; rotaryEncoderHub.value = { connection, proxy };
} }