IO板卡系统优化
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Input;
|
||||
using DeviceCommand.Device;
|
||||
using Logger;
|
||||
using Prism.Ioc;
|
||||
using TestingModule.ViewModels;
|
||||
@@ -78,9 +79,27 @@ namespace MainModule.ViewModels
|
||||
RefreshCommand = new DelegateCommand(OnRefresh);
|
||||
BackToProtocolCommand = new DelegateCommand(OnBackToProtocol);
|
||||
LoadedCommand = new AsyncDelegateCommand(OnLoad);
|
||||
_eventAggregator.GetEvent<SilenceBuzzerEvent>().Subscribe(async (scope) => await SilenceBuzzer(scope));
|
||||
}
|
||||
|
||||
private async Task SilenceBuzzer(string scope)
|
||||
{
|
||||
if (_deviceManager.DeviceMap.TryGetValue("IO板卡(蜂鸣器)", out var lazyIoBoard))
|
||||
{
|
||||
if (lazyIoBoard is IOBoard io)
|
||||
{
|
||||
if (scope == "default")
|
||||
await io.批量写输出开关(1, 0, [false, false, false, false, false, false, false, false]);
|
||||
else if (scope != TestStatus) return;
|
||||
else
|
||||
{
|
||||
int index = _systemConfig.SharedParameterList.Where(x => x.ParameterName == "蜂鸣器").FirstOrDefault().Value;
|
||||
await io.写输出开关(1, (ushort)index, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// 1. 如果 TestStatus 为空,说明还没走到 OnNavigatedTo 赋值,直接释放 scope 即可
|
||||
@@ -92,6 +111,7 @@ namespace MainModule.ViewModels
|
||||
|
||||
try
|
||||
{
|
||||
_eventAggregator.GetEvent<SilenceBuzzerEvent>().Unsubscribe(async (scope) => await SilenceBuzzer(scope));
|
||||
// 2. 显式释放硬件资源(防止端口占用/死锁)
|
||||
if (_deviceManager is IDisposable disposableDevice)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user