From 3318c720b71f0a3290443f52117fc786ddab03e9 Mon Sep 17 00:00:00 2001 From: hsc Date: Mon, 13 Jul 2026 15:10:49 +0800 Subject: [PATCH] =?UTF-8?q?IO=E6=9D=BF=E5=8D=A1=E7=B3=BB=E7=BB=9F=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ADP/ViewModels/ShellViewModel.cs | 11 +++++- ADP/Views/ShellView.xaml | 4 +-- DeviceCommand/Base/ModbusTcp.cs | 9 +++-- DeviceCommand/Devices/IOBoard.cs | 7 ++-- .../ViewModels/AutomatedTestingViewModel.cs | 22 +++++++++++- .../ViewModels/ParametersManagerViewModel.cs | 2 +- UIShare/GlobalVariable/SystemConfig.cs | 35 +++++++++++++++++-- UIShare/PubEvent/SilenceBuzzerEvent.cs | 12 +++++++ UIShare/UIViewModel/ParameterVM.cs | 6 ++++ 9 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 UIShare/PubEvent/SilenceBuzzerEvent.cs diff --git a/ADP/ViewModels/ShellViewModel.cs b/ADP/ViewModels/ShellViewModel.cs index cc1e510..71e3e72 100644 --- a/ADP/ViewModels/ShellViewModel.cs +++ b/ADP/ViewModels/ShellViewModel.cs @@ -1,4 +1,5 @@  +using DeviceCommand.Device; using Logger; using MaterialDesignThemes.Wpf; using Microsoft.Win32; @@ -152,6 +153,7 @@ namespace ADP.ViewModels public ICommand SelectCANMessageCommand { get; set; } public ICommand MonitorValueSettingCommand { get; set; } public ICommand GetFileStringCommand { get; set; } + public ICommand SilenceBuzzerCommand { get; set; } #endregion public ShellViewModel(IContainerProvider containerProvider) @@ -185,6 +187,7 @@ namespace ADP.ViewModels SelectCANMessageCommand = new DelegateCommand(SelectCANMessage); MonitorValueSettingCommand = new DelegateCommand(MonitorValueSetting); GetFileStringCommand = new DelegateCommand(GetFileString); + SilenceBuzzerCommand = new AsyncDelegateCommand(SilenceBuzzer); _globalInfo.ContextDic.Add("default", new ScopedContext()); @@ -207,7 +210,7 @@ namespace ADP.ViewModels _uiRefreshTimer.Start(); } - + private void RefreshAllContextProperties() { RaisePropertyChanged(nameof(RunState)); @@ -218,6 +221,12 @@ namespace ADP.ViewModels } #region 命令处理与事件 + + private async Task SilenceBuzzer() + { + _eventAggregator.GetEvent().Publish(_globalInfo.CurrentScope); + + } private void GetFileString() { var openFileDialog = new OpenFileDialog diff --git a/ADP/Views/ShellView.xaml b/ADP/Views/ShellView.xaml index 310b365..db1c730 100644 --- a/ADP/Views/ShellView.xaml +++ b/ADP/Views/ShellView.xaml @@ -193,8 +193,8 @@ Command="{Binding GetFileStringCommand}"> Foreground="Black" /> - - + + _tcpClient?.Connected ?? false; protected readonly SemaphoreSlim _commLock = new(1, 1); - + public ModbusTcp(TcpConfig config) : this() + { + if (config == null) return; + ConfigureDevice(config.IPAddress, config.Port, config.SendTimeout, config.ReceiveTimeout); + } public ModbusTcp() { _tcpClient = new TcpClient(); diff --git a/DeviceCommand/Devices/IOBoard.cs b/DeviceCommand/Devices/IOBoard.cs index 216f2aa..3e37c85 100644 --- a/DeviceCommand/Devices/IOBoard.cs +++ b/DeviceCommand/Devices/IOBoard.cs @@ -1,5 +1,6 @@ using Common.Attributes; using DeviceCommand.Base; +using Model.Models; using NModbus; using System; using System.Collections.Generic; @@ -13,10 +14,10 @@ namespace DeviceCommand.Device [ADPCommand] public class IOBoard : ModbusTcp { - //只有两个,八台产品公用两两分组各用一个 - public IOBoard(string Ip地址, int 端口, int 发送超时, int 接收超时) + + public IOBoard(TcpConfig config) : base(config) { - ConfigureDevice(Ip地址, 端口, 发送超时, 接收超时); + } diff --git a/MainModule/ViewModels/AutomatedTestingViewModel.cs b/MainModule/ViewModels/AutomatedTestingViewModel.cs index f608534..77cb05c 100644 --- a/MainModule/ViewModels/AutomatedTestingViewModel.cs +++ b/MainModule/ViewModels/AutomatedTestingViewModel.cs @@ -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().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().Unsubscribe(async (scope) => await SilenceBuzzer(scope)); // 2. 显式释放硬件资源(防止端口占用/死锁) if (_deviceManager is IDisposable disposableDevice) { diff --git a/TestingModule/ViewModels/ParametersManagerViewModel.cs b/TestingModule/ViewModels/ParametersManagerViewModel.cs index 8b0b9e0..486105a 100644 --- a/TestingModule/ViewModels/ParametersManagerViewModel.cs +++ b/TestingModule/ViewModels/ParametersManagerViewModel.cs @@ -187,7 +187,7 @@ namespace TestingModule.ViewModels private void ParameterEdit() { - if (!_globalInfo.IsAdmin) return; + if (!_globalInfo.IsAdmin||!SelectedParameter.IsEditable) return; var param = new DialogParameters { { "Mode",SelectedParameter==null?"ADD":"Edit" }, diff --git a/UIShare/GlobalVariable/SystemConfig.cs b/UIShare/GlobalVariable/SystemConfig.cs index d120c88..868e47b 100644 --- a/UIShare/GlobalVariable/SystemConfig.cs +++ b/UIShare/GlobalVariable/SystemConfig.cs @@ -47,22 +47,48 @@ namespace UIShare.GlobalVariable { Category = ParameterCategory.Input, Type = typeof(int), - Name = "继电器占位1", + Name = "单相充电", Value = 0, + IsEditable=false }, new ParameterVM { Category = ParameterCategory.Input, Type = typeof(int), - Name = "继电器占位2", + Name = "抛负载", Value = 1, - }, + IsEditable=false + }, + new ParameterVM + { + Category = ParameterCategory.Input, + Type = typeof(int), + Name = "短路测试", + Value = 0, + IsEditable=false + }, new ParameterVM + { + Category = ParameterCategory.Input, + Type = typeof(int), + Name = "初始化供电", + Value = 0, + IsEditable=false + }, + new ParameterVM + { + Category = ParameterCategory.Input, + Type = typeof(int), + Name = "蜂鸣器", + Value = 1, + IsEditable=false + }, new ParameterVM { Category = ParameterCategory.Input, Type = typeof(int), Name = "CAN通道", Value = 0, + IsEditable=false }, new ParameterVM { @@ -70,6 +96,7 @@ namespace UIShare.GlobalVariable Type = typeof(int), Name = "示波器通道", Value = 0, + IsEditable=false }, new ParameterVM { @@ -77,6 +104,7 @@ namespace UIShare.GlobalVariable Type = typeof(int), Name = "功率分析仪通道1", Value = 0, + IsEditable=false }, new ParameterVM { @@ -84,6 +112,7 @@ namespace UIShare.GlobalVariable Type = typeof(int), Name = "功率分析仪通道2", Value = 0, + IsEditable=false }, }; // public ObservableCollection DeviceList { get; set; } = new() diff --git a/UIShare/PubEvent/SilenceBuzzerEvent.cs b/UIShare/PubEvent/SilenceBuzzerEvent.cs new file mode 100644 index 0000000..8495f90 --- /dev/null +++ b/UIShare/PubEvent/SilenceBuzzerEvent.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UIShare.PubEvent +{ + public class SilenceBuzzerEvent:PubSubEvent + { + } +} diff --git a/UIShare/UIViewModel/ParameterVM.cs b/UIShare/UIViewModel/ParameterVM.cs index 68ac020..d3160b9 100644 --- a/UIShare/UIViewModel/ParameterVM.cs +++ b/UIShare/UIViewModel/ParameterVM.cs @@ -44,6 +44,12 @@ namespace UIShare.UIViewModel { get => _isVisible; set => SetProperty(ref _isVisible, value); + } + private bool _isEditable = true; + public bool IsEditable + { + get => _isEditable; + set => SetProperty(ref _isEditable, value); } private string _name;