IO板卡系统优化
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
using DeviceCommand.Device;
|
||||||
using Logger;
|
using Logger;
|
||||||
using MaterialDesignThemes.Wpf;
|
using MaterialDesignThemes.Wpf;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
@@ -152,6 +153,7 @@ namespace ADP.ViewModels
|
|||||||
public ICommand SelectCANMessageCommand { get; set; }
|
public ICommand SelectCANMessageCommand { get; set; }
|
||||||
public ICommand MonitorValueSettingCommand { get; set; }
|
public ICommand MonitorValueSettingCommand { get; set; }
|
||||||
public ICommand GetFileStringCommand { get; set; }
|
public ICommand GetFileStringCommand { get; set; }
|
||||||
|
public ICommand SilenceBuzzerCommand { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public ShellViewModel(IContainerProvider containerProvider)
|
public ShellViewModel(IContainerProvider containerProvider)
|
||||||
@@ -185,6 +187,7 @@ namespace ADP.ViewModels
|
|||||||
SelectCANMessageCommand = new DelegateCommand(SelectCANMessage);
|
SelectCANMessageCommand = new DelegateCommand(SelectCANMessage);
|
||||||
MonitorValueSettingCommand = new DelegateCommand(MonitorValueSetting);
|
MonitorValueSettingCommand = new DelegateCommand(MonitorValueSetting);
|
||||||
GetFileStringCommand = new DelegateCommand(GetFileString);
|
GetFileStringCommand = new DelegateCommand(GetFileString);
|
||||||
|
SilenceBuzzerCommand = new AsyncDelegateCommand(SilenceBuzzer);
|
||||||
|
|
||||||
_globalInfo.ContextDic.Add("default", new ScopedContext());
|
_globalInfo.ContextDic.Add("default", new ScopedContext());
|
||||||
|
|
||||||
@@ -218,6 +221,12 @@ namespace ADP.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region 命令处理与事件
|
#region 命令处理与事件
|
||||||
|
|
||||||
|
private async Task SilenceBuzzer()
|
||||||
|
{
|
||||||
|
_eventAggregator.GetEvent<SilenceBuzzerEvent>().Publish(_globalInfo.CurrentScope);
|
||||||
|
|
||||||
|
}
|
||||||
private void GetFileString()
|
private void GetFileString()
|
||||||
{
|
{
|
||||||
var openFileDialog = new OpenFileDialog
|
var openFileDialog = new OpenFileDialog
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ Command="{Binding GetFileStringCommand}">
|
|||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
<!-- 蜂鸣器消音 -->
|
<!-- 弹窗管理器 -->
|
||||||
<MenuItem Header="弹窗管理器"
|
<MenuItem Header="弹窗管理器"
|
||||||
FontSize="14"
|
FontSize="14"
|
||||||
Height="50"
|
Height="50"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using NModbus;
|
using Model.Models;
|
||||||
|
using NModbus;
|
||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
@@ -19,7 +20,11 @@ namespace DeviceCommand.Base
|
|||||||
public bool IsConnected => _tcpClient?.Connected ?? false;
|
public bool IsConnected => _tcpClient?.Connected ?? false;
|
||||||
|
|
||||||
protected readonly SemaphoreSlim _commLock = new(1, 1);
|
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()
|
public ModbusTcp()
|
||||||
{
|
{
|
||||||
_tcpClient = new TcpClient();
|
_tcpClient = new TcpClient();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Common.Attributes;
|
using Common.Attributes;
|
||||||
using DeviceCommand.Base;
|
using DeviceCommand.Base;
|
||||||
|
using Model.Models;
|
||||||
using NModbus;
|
using NModbus;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -13,10 +14,10 @@ namespace DeviceCommand.Device
|
|||||||
[ADPCommand]
|
[ADPCommand]
|
||||||
public class IOBoard : ModbusTcp
|
public class IOBoard : ModbusTcp
|
||||||
{
|
{
|
||||||
//只有两个,八台产品公用两两分组各用一个
|
|
||||||
public IOBoard(string Ip地址, int 端口, int 发送超时, int 接收超时)
|
public IOBoard(TcpConfig config) : base(config)
|
||||||
{
|
{
|
||||||
ConfigureDevice(Ip地址, 端口, 发送超时, 接收超时);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using DeviceCommand.Device;
|
||||||
using Logger;
|
using Logger;
|
||||||
using Prism.Ioc;
|
using Prism.Ioc;
|
||||||
using TestingModule.ViewModels;
|
using TestingModule.ViewModels;
|
||||||
@@ -78,8 +79,26 @@ namespace MainModule.ViewModels
|
|||||||
RefreshCommand = new DelegateCommand(OnRefresh);
|
RefreshCommand = new DelegateCommand(OnRefresh);
|
||||||
BackToProtocolCommand = new DelegateCommand(OnBackToProtocol);
|
BackToProtocolCommand = new DelegateCommand(OnBackToProtocol);
|
||||||
LoadedCommand = new AsyncDelegateCommand(OnLoad);
|
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()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
@@ -92,6 +111,7 @@ namespace MainModule.ViewModels
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_eventAggregator.GetEvent<SilenceBuzzerEvent>().Unsubscribe(async (scope) => await SilenceBuzzer(scope));
|
||||||
// 2. 显式释放硬件资源(防止端口占用/死锁)
|
// 2. 显式释放硬件资源(防止端口占用/死锁)
|
||||||
if (_deviceManager is IDisposable disposableDevice)
|
if (_deviceManager is IDisposable disposableDevice)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ namespace TestingModule.ViewModels
|
|||||||
|
|
||||||
private void ParameterEdit()
|
private void ParameterEdit()
|
||||||
{
|
{
|
||||||
if (!_globalInfo.IsAdmin) return;
|
if (!_globalInfo.IsAdmin||!SelectedParameter.IsEditable) return;
|
||||||
var param = new DialogParameters
|
var param = new DialogParameters
|
||||||
{
|
{
|
||||||
{ "Mode",SelectedParameter==null?"ADD":"Edit" },
|
{ "Mode",SelectedParameter==null?"ADD":"Edit" },
|
||||||
|
|||||||
@@ -47,15 +47,40 @@ namespace UIShare.GlobalVariable
|
|||||||
{
|
{
|
||||||
Category = ParameterCategory.Input,
|
Category = ParameterCategory.Input,
|
||||||
Type = typeof(int),
|
Type = typeof(int),
|
||||||
Name = "继电器占位1",
|
Name = "单相充电",
|
||||||
Value = 0,
|
Value = 0,
|
||||||
|
IsEditable=false
|
||||||
},
|
},
|
||||||
new ParameterVM
|
new ParameterVM
|
||||||
{
|
{
|
||||||
Category = ParameterCategory.Input,
|
Category = ParameterCategory.Input,
|
||||||
Type = typeof(int),
|
Type = typeof(int),
|
||||||
Name = "继电器占位2",
|
Name = "抛负载",
|
||||||
Value = 1,
|
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
|
new ParameterVM
|
||||||
{
|
{
|
||||||
@@ -63,6 +88,7 @@ namespace UIShare.GlobalVariable
|
|||||||
Type = typeof(int),
|
Type = typeof(int),
|
||||||
Name = "CAN通道",
|
Name = "CAN通道",
|
||||||
Value = 0,
|
Value = 0,
|
||||||
|
IsEditable=false
|
||||||
},
|
},
|
||||||
new ParameterVM
|
new ParameterVM
|
||||||
{
|
{
|
||||||
@@ -70,6 +96,7 @@ namespace UIShare.GlobalVariable
|
|||||||
Type = typeof(int),
|
Type = typeof(int),
|
||||||
Name = "示波器通道",
|
Name = "示波器通道",
|
||||||
Value = 0,
|
Value = 0,
|
||||||
|
IsEditable=false
|
||||||
},
|
},
|
||||||
new ParameterVM
|
new ParameterVM
|
||||||
{
|
{
|
||||||
@@ -77,6 +104,7 @@ namespace UIShare.GlobalVariable
|
|||||||
Type = typeof(int),
|
Type = typeof(int),
|
||||||
Name = "功率分析仪通道1",
|
Name = "功率分析仪通道1",
|
||||||
Value = 0,
|
Value = 0,
|
||||||
|
IsEditable=false
|
||||||
},
|
},
|
||||||
new ParameterVM
|
new ParameterVM
|
||||||
{
|
{
|
||||||
@@ -84,6 +112,7 @@ namespace UIShare.GlobalVariable
|
|||||||
Type = typeof(int),
|
Type = typeof(int),
|
||||||
Name = "功率分析仪通道2",
|
Name = "功率分析仪通道2",
|
||||||
Value = 0,
|
Value = 0,
|
||||||
|
IsEditable=false
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// public ObservableCollection<DeviceInfoVM> DeviceList { get; set; } = new()
|
// public ObservableCollection<DeviceInfoVM> DeviceList { get; set; } = new()
|
||||||
|
|||||||
12
UIShare/PubEvent/SilenceBuzzerEvent.cs
Normal file
12
UIShare/PubEvent/SilenceBuzzerEvent.cs
Normal 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>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,6 +45,12 @@ namespace UIShare.UIViewModel
|
|||||||
get => _isVisible;
|
get => _isVisible;
|
||||||
set => SetProperty(ref _isVisible, value);
|
set => SetProperty(ref _isVisible, value);
|
||||||
}
|
}
|
||||||
|
private bool _isEditable = true;
|
||||||
|
public bool IsEditable
|
||||||
|
{
|
||||||
|
get => _isEditable;
|
||||||
|
set => SetProperty(ref _isEditable, value);
|
||||||
|
}
|
||||||
|
|
||||||
private string _name;
|
private string _name;
|
||||||
public string Name
|
public string Name
|
||||||
|
|||||||
Reference in New Issue
Block a user