IO板卡系统优化

This commit is contained in:
hsc
2026-07-13 15:10:49 +08:00
parent b6b767cf0a
commit 3318c720b7
9 changed files with 95 additions and 13 deletions

View File

@@ -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<SilenceBuzzerEvent>().Publish(_globalInfo.CurrentScope);
}
private void GetFileString()
{
var openFileDialog = new OpenFileDialog

View File

@@ -193,8 +193,8 @@ Command="{Binding GetFileStringCommand}">
Foreground="Black" />
</MenuItem.Icon>
</MenuItem>
<!-- 蜂鸣器消音 -->
<!-- 弹窗管理器 -->
<MenuItem Header="弹窗管理器"
FontSize="14"
Height="50"

View File

@@ -1,4 +1,5 @@
using NModbus;
using Model.Models;
using NModbus;
using System;
using System.Net;
using System.Net.Sockets;
@@ -19,7 +20,11 @@ namespace DeviceCommand.Base
public bool IsConnected => _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();

View File

@@ -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地址, , , );
}

View File

@@ -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)
{

View File

@@ -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" },

View File

@@ -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<DeviceInfoVM> DeviceList { get; set; } = new()

View File

@@ -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<string>
{
}
}

View File

@@ -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;