fix: 修复后端数码管无法正常读取/关闭的问题

This commit is contained in:
SikongJueluo 2025-08-15 15:25:37 +08:00
parent a00cc84e48
commit 774c9575d4
No known key found for this signature in database
2 changed files with 9 additions and 3 deletions

View File

@ -100,7 +100,7 @@ public class DigitalTubesHub : Hub<IDigitalTubesReceiver>, IDigitalTubesHub
return Task.Run(async () =>
{
var cntError = 0;
while (info.IsRunning && !info.CTS.IsCancellationRequested)
while (!info.CTS.IsCancellationRequested)
{
var beginTime = DateTime.Now;
var waitTime = TimeSpan.FromMilliseconds(1000 / info.Frequency);
@ -142,6 +142,11 @@ public class DigitalTubesHub : Hub<IDigitalTubesReceiver>, IDigitalTubesHub
if (!info.IsRunning)
{
info.IsRunning = true;
if (info.CTS.IsCancellationRequested)
{
info.CTS.Dispose();
info.CTS = new CancellationTokenSource();
}
_ = ScanAllTubes(info);
}
}
@ -167,7 +172,8 @@ public class DigitalTubesHub : Hub<IDigitalTubesReceiver>, IDigitalTubesHub
new SevenDigitalTubesCtrl(board.IpAddr, board.Port, 2))
) is DigitalTubeInfo info)
{
if (info.IsRunning) info.IsRunning = false;
info.IsRunning = false;
info.CTS.Cancel();
}
return Task.FromResult(true);

View File

@ -52,7 +52,7 @@ public class SevenDigitalTubesCtrl
if (ret.Value.Options.Data == null || ret.Value.Options.Data.Length < 4)
return new(new Exception("Data length is too short"));
var data = Number.BytesToUInt32(ret.Value.Options.Data, 0, 4, true).Value;
var data = Number.BytesToUInt32(ret.Value.Options.Data, 0, 4).Value;
if ((data >> 8) != num)
{