设备初始化

This commit is contained in:
hsc
2026-06-10 14:24:45 +08:00
parent 59d047d8e6
commit 5452857299
6 changed files with 60 additions and 20 deletions

View File

@@ -17,6 +17,9 @@ using UIShare.PubEvent;
using static System.Runtime.InteropServices.JavaScript.JSType;
using UIShare.GlobalVariable;
using UIShare;
using System;
using DeviceCommand.Device;
using DeviceCommand.Base;
namespace ADP
{
@@ -76,6 +79,7 @@ namespace ADP
containerRegistry.RegisterScoped<SystemConfig>();
containerRegistry.RegisterScoped<StepRunning>();
containerRegistry.RegisterScoped<ScopedContext>();
containerRegistry.RegisterScoped<DeviceManager>();
containerRegistry.RegisterSingleton<GlobalInfo>();
}
//指定模块加载方式(需要手动将模块生成的dll放入Modules文件夹中)

View File

@@ -1,3 +1,5 @@
using DeviceCommand.Base;
using DeviceCommand.Device;
using MainModule.Views;
using System.Reflection;
using UIShare.GlobalVariable;
@@ -18,11 +20,6 @@ namespace MainModule
containerRegistry.RegisterForNavigation<MainView>("MainView");
containerRegistry.RegisterForNavigation<AutomatedTestingView>("AutomatedTestingView");
containerRegistry.RegisterForNavigation<ProtocolStartView>("ProtocolStartView");
// Scoped: one ScopedContext per container scope.
// AutomatedTestingViewModel creates its own scope (IContainerExtension.CreateScope)
// and resolves the 5 child VMs from it, so all siblings inside one parent share
// the same ScopedContext, while different parents get isolated instances.
}
}
}

View File

@@ -9,6 +9,7 @@ using UIShare.GlobalVariable;
using UIShare.PubEvent;
using UIShare.UIViewModel;
using UIShare.ViewModelBase;
using static System.Formats.Asn1.AsnWriter;
namespace MainModule.ViewModels
{
@@ -33,6 +34,7 @@ namespace MainModule.ViewModels
public StepRunning _stepRunning { get; }
public GlobalInfo _globalInfo { get; }
public SystemConfig _systemConfig { get; set; }
public DeviceManager _deviceManager { get; set; }
// 5 个子 ViewModel 全部从同一个 scope 解析,自动注入同一个 ScopedContext
public CommandTreeViewModel CommandTreeVM { get; }
@@ -45,15 +47,15 @@ namespace MainModule.ViewModels
public ICommand RefreshCommand { get; set; }
public ICommand BackToProtocolCommand { get; set; }
public AutomatedTestingViewModel(IContainerExtension container) : base(container)
public AutomatedTestingViewModel(IContainerProvider container) : base(container)
{
// 每个 AutomatedTestingViewModel 实例创建独立的容器作用域
_scope = container.CreateScope();
_globalInfo=container.Resolve<GlobalInfo>();
_globalInfo =container.Resolve<GlobalInfo>();
// 在该作用域内解析 ScopedContext —— 当前作用域唯一
_scopedContext = _scope.Resolve<ScopedContext>();
_stepRunning = _scope.Resolve<StepRunning>();
_systemConfig = _scope.Resolve<SystemConfig>();
_systemConfig = _scope.Resolve<SystemConfig>();;
// 关键:从同一个 _scope 解析 5 个子 VMDI 会把同一个 ScopedContext 注入它们
CommandTreeVM = _scope.Resolve<CommandTreeViewModel>();
StepsManagerVM = _scope.Resolve<StepsManagerViewModel>();
@@ -62,6 +64,7 @@ namespace MainModule.ViewModels
ParametersManagerVM = _scope.Resolve<ParametersManagerViewModel>();
RefreshCommand = new DelegateCommand(OnRefresh);
BackToProtocolCommand = new DelegateCommand(OnBackToProtocol);
}
public void Dispose()
@@ -144,6 +147,7 @@ namespace MainModule.ViewModels
_scopedContext.Program.StepCollection = program.StepCollection;
_scopedContext.Program.ErrorStepCollection = program.ErrorStepCollection;
_scopedContext.CurrentFilePath = filePath;
_deviceManager = _scope.Resolve<DeviceManager>();
}
}

View File

@@ -61,7 +61,6 @@ namespace SettingModule.ViewModels
#region
public ICommand RefreshCommand { get; }
public ICommand SaveCommand { get; }
public ICommand ResetCommand { get; }
public ICommand OpenConnectionConfigCommand { get; }
#endregion
#region
@@ -80,7 +79,6 @@ namespace SettingModule.ViewModels
_globalInfo = container.Resolve<GlobalInfo>();
RefreshCommand = new DelegateCommand(OnExpand);
SaveCommand = new DelegateCommand(OnSave);
ResetCommand = new DelegateCommand(OnReset);
OpenConnectionConfigCommand = new DelegateCommand(OnOpenConnectionConfig);
}
@@ -132,15 +130,7 @@ namespace SettingModule.ViewModels
}
/// <summary>重置当前选中设备的配置(占位)。</summary>
private void OnReset()
{
if (SelectedDevice == null)
{
StatusMessage = "无可重置的设备";
return;
}
StatusMessage = $"已重置设备 [{SelectedDevice.DeviceName}] 的配置";
}
/// <summary>
/// 打开"连接配置"对话框。按 SelectedDevice.ConnectionType 决定开 TCP 还是串口对话框。

View File

@@ -205,7 +205,7 @@
<Run Text="{Binding SelectedDevice.DeviceName, FallbackValue=未选中}"/>
</TextBlock>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Button Content="重置" Command="{Binding ResetCommand}" Padding="12,4"/>
<Button Content="保存" Command="{Binding SaveCommand}" Padding="12,4" Margin="6,0,0,0"/>
</StackPanel>
</Grid>

View File

@@ -0,0 +1,45 @@
using DeviceCommand.Base;
using DeviceCommand.Device;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UIShare.GlobalVariable
{
public class DeviceManager
{
public SystemConfig _systemConfig { get; set; }
public IContainerProvider _containerProvider { get; set; }
public IT7800E _iT7800E { get; set; }
public N36200 _n36200 { get; set; }
public N36600 _n36600 { get; set; }
public N69200 _n69200 { get; set; }
public SDS2000X_HD _sDS2000X_HD { get; set; }
public SPAW7000 _sPAW7000 { get; set; }
public IList<IBaseInterface> DeviceList { get; set; }
public DeviceManager(IContainerProvider containerProvider,SystemConfig systemConfig)
{
_containerProvider = containerProvider;
_systemConfig = systemConfig;
InitDevices();
}
private void InitDevices()
{
foreach(var Config in _systemConfig.DeviceList)
{
if (Config.ConnectionType == "Tcp")
{
}
else if (Config.ConnectionType == "Serial")
{
}
}
}
}
}