diff --git a/ADP.sln b/ADP.sln
index 35c3475..8070f1d 100644
--- a/ADP.sln
+++ b/ADP.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
-VisualStudioVersion = 17.12.35527.113 d17.12
+VisualStudioVersion = 17.12.35527.113
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ADP", "ADP\ADP.csproj", "{8B48B0CD-55F9-4623-9A10-BFE25B21EBD6}"
EndProject
@@ -37,6 +37,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonitorModule", "MonitorMod
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CAN驱动", "CAN驱动\CAN驱动.csproj", "{D1868672-0132-4B1A-A393-C2CF49A25E74}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceEditModule", "DeviceEditModule\DeviceEditModule.csproj", "{170AD4C1-189D-4FBE-B10D-2A4304527834}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -107,6 +109,10 @@ Global
{D1868672-0132-4B1A-A393-C2CF49A25E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1868672-0132-4B1A-A393-C2CF49A25E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1868672-0132-4B1A-A393-C2CF49A25E74}.Release|Any CPU.Build.0 = Release|Any CPU
+ {170AD4C1-189D-4FBE-B10D-2A4304527834}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {170AD4C1-189D-4FBE-B10D-2A4304527834}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {170AD4C1-189D-4FBE-B10D-2A4304527834}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {170AD4C1-189D-4FBE-B10D-2A4304527834}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -118,5 +124,6 @@ Global
{DFC084AE-FE45-4492-A2DA-EAE2941F26E9} = {1E92D601-68FC-45F6-8251-BD0F39226E5B}
{3456C3AC-E7FF-45F8-A68F-BEED9969812C} = {1E92D601-68FC-45F6-8251-BD0F39226E5B}
{850A5BE8-0BC1-4D6A-8351-DD812C9C4427} = {1E92D601-68FC-45F6-8251-BD0F39226E5B}
+ {170AD4C1-189D-4FBE-B10D-2A4304527834} = {1E92D601-68FC-45F6-8251-BD0F39226E5B}
EndGlobalSection
EndGlobal
diff --git a/ADP/ADP.csproj b/ADP/ADP.csproj
index 6c43360..f3a35ad 100644
--- a/ADP/ADP.csproj
+++ b/ADP/ADP.csproj
@@ -16,6 +16,7 @@
+
diff --git a/ADP/App.xaml b/ADP/App.xaml
index ec1b892..069a956 100644
--- a/ADP/App.xaml
+++ b/ADP/App.xaml
@@ -9,6 +9,7 @@
+
diff --git a/ADP/ViewModels/ShellViewModel.cs b/ADP/ViewModels/ShellViewModel.cs
index 1d1e396..eca07c9 100644
--- a/ADP/ViewModels/ShellViewModel.cs
+++ b/ADP/ViewModels/ShellViewModel.cs
@@ -144,6 +144,7 @@ namespace ADP.ViewModels
public ICommand OpenCommand { get; set; }
public ICommand NewCommand { get; set; }
public ICommand SetDefaultCommand { get; set; }
+ public ICommand ShowDialogManagerViewCommand { get; set; }
#endregion
public ShellViewModel(IContainerProvider containerProvider)
@@ -154,8 +155,8 @@ namespace ADP.ViewModels
_regionManager = containerProvider.Resolve();
_notificationManager = containerProvider.Resolve();
_moduleManager = containerProvider.Resolve();
-
LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen);
+ ShowDialogManagerViewCommand = new DelegateCommand(ShowDialogManagerView);
MinimizeCommand = new DelegateCommand(MinimizeWindow);
MaximizeCommand = new DelegateCommand(MaximizeWindow);
CloseCommand = new DelegateCommand(CloseWindow);
@@ -194,6 +195,8 @@ namespace ADP.ViewModels
_uiRefreshTimer.Start();
}
+
+
private void RefreshAllContextProperties()
{
RaisePropertyChanged(nameof(RunState));
@@ -204,6 +207,10 @@ namespace ADP.ViewModels
}
#region 命令处理与事件
+ private void ShowDialogManagerView()
+ {
+ _eventAggregator.GetEvent().Publish();
+ }
private async void OnRunning()
{
string runningScope = _globalInfo.CurrentScope;
diff --git a/ADP/Views/ShellView.xaml b/ADP/Views/ShellView.xaml
index f1049e0..eb17dcd 100644
--- a/ADP/Views/ShellView.xaml
+++ b/ADP/Views/ShellView.xaml
@@ -49,7 +49,7 @@
Command="{Binding NavigateCommand}"
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
Style="{StaticResource MaterialDesignFlatButton}"
- Margin="8" />
+ Margin="8" />
+ Margin="8" />
+
-
+
@@ -303,21 +314,25 @@
Identifier="Root">
-
+
+
+
+
+
+ Panel.ZIndex="1" Grid.ColumnSpan="2">
-
+
+ Panel.ZIndex="1" Grid.ColumnSpan="2">
diff --git a/DeviceCommand/Devices/IOBoard.cs b/DeviceCommand/Devices/IOBoard.cs
new file mode 100644
index 0000000..216f2aa
--- /dev/null
+++ b/DeviceCommand/Devices/IOBoard.cs
@@ -0,0 +1,48 @@
+using Common.Attributes;
+using DeviceCommand.Base;
+using NModbus;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DeviceCommand.Device
+{
+ [ADPCommand]
+ public class IOBoard : ModbusTcp
+ {
+ //只有两个,八台产品公用两两分组各用一个
+ public IOBoard(string Ip地址, int 端口, int 发送超时, int 接收超时)
+ {
+ ConfigureDevice(Ip地址, 端口, 发送超时, 接收超时);
+ }
+
+
+ public async Task 写输出开关(byte 站号, ushort 开始地址, bool data)
+ {
+ await Modbus.WriteSingleCoilAsync(站号, 开始地址, data);
+ }
+ public async Task 批量写输出开关(byte 站号, ushort 开始地址, bool[] datas)
+ {
+ var 批量写入 = await Modbus.ReadCoilsAsync(1, 0, 16);
+ for (int i = 0; i < datas.Length; i++)
+ {
+ if (开始地址 + i < 批量写入.Length)
+ {
+ 批量写入[开始地址 + i] = datas[i];
+ }
+ }
+ await Modbus.WriteMultipleCoilsAsync(站号, 0, 批量写入);
+ }
+ public async Task 读输出开关(byte 站号, ushort 开始地址)
+ {
+ await Modbus.ReadCoilsAsync(站号, 开始地址, 1);
+ }
+ public async Task 批量读输出开关(byte 站号, ushort 开始地址,ushort 数量)
+ {
+ return await Modbus.ReadCoilsAsync(站号, 开始地址, 数量);
+ }
+ }
+}
diff --git a/DeviceCommand/Devices/IT7800E.cs b/DeviceCommand/Devices/IT7800E.cs
index dee4377..1e20ebe 100644
--- a/DeviceCommand/Devices/IT7800E.cs
+++ b/DeviceCommand/Devices/IT7800E.cs
@@ -11,6 +11,7 @@ namespace DeviceCommand.Device
[ADPCommand]
public class IT7800E : Tcp
{
+ //只有一个,八台产品一起用一个
// 根据通用 SCPI 指令规范,使用换行符 (ASCII 字符 LF,即 \n) 作为标准结束符
private const string ScpiDelimiter = "\n";
diff --git a/DeviceCommand/Devices/N36200.cs b/DeviceCommand/Devices/N36200.cs
index dda310e..935e49b 100644
--- a/DeviceCommand/Devices/N36200.cs
+++ b/DeviceCommand/Devices/N36200.cs
@@ -11,6 +11,7 @@ namespace DeviceCommand.Device
[ADPCommand]
public class N36200 : Tcp
{
+ //只有一个,八台产品一起用一个
// 手册第 9 页 2.2.4 明确规定:命令结束符为换行符 (ASCII 字符 LF,即 \n)
private const string ScpiDelimiter = "\n";
diff --git a/DeviceCommand/Devices/SDS2000X_HD.cs b/DeviceCommand/Devices/SDS2000X_HD.cs
index fb309e1..88e0f5d 100644
--- a/DeviceCommand/Devices/SDS2000X_HD.cs
+++ b/DeviceCommand/Devices/SDS2000X_HD.cs
@@ -11,6 +11,7 @@ namespace DeviceCommand.Device
[ADPCommand]
public class SDS2000X_HD : Tcp
{
+ //只有两个,八台产品公用两两分组各用一个
// 示波器底层 Socket 字符串命令通常以换行符 \n 结束
private const string ScpiDelimiter = "\n";
diff --git a/DeviceCommand/Devices/SPAW7000.cs b/DeviceCommand/Devices/SPAW7000.cs
index 1804321..e58b9a6 100644
--- a/DeviceCommand/Devices/SPAW7000.cs
+++ b/DeviceCommand/Devices/SPAW7000.cs
@@ -11,6 +11,7 @@ namespace DeviceCommand.Device
[ADPCommand]
public class SPAW7000 : Tcp
{
+ //只有两个,八台产品公用两两分组各用一个
// 根据通用 SCPI 与远宽指令规范,使用换行符 (ASCII 字符 LF,即 \n) 作为标准结束符
private const string ScpiDelimiter = "\n";
diff --git a/DeviceEditModule/DeviceEditModule.cs b/DeviceEditModule/DeviceEditModule.cs
new file mode 100644
index 0000000..bb7a9dd
--- /dev/null
+++ b/DeviceEditModule/DeviceEditModule.cs
@@ -0,0 +1,26 @@
+using DeviceEditModule.ViewModels;
+using DeviceEditModule.Views;
+
+namespace DeviceEditModule
+{
+ public class DeviceEditModule : IModule
+ {
+ public void OnInitialized(IContainerProvider containerProvider)
+ {
+ }
+
+ public void RegisterTypes(IContainerRegistry containerRegistry)
+ {
+ // DialogMangerView 作为弹窗宿主,注册为 Dialog(支持 _dialogService.Show)
+ containerRegistry.RegisterDialog("DialogMangerView");
+
+ // 设备编辑 View 注册为 Navigation(被动态解析后作为 Tab 内容嵌入 DialogMangerView)
+ containerRegistry.RegisterForNavigation("IT7800EView");
+ containerRegistry.RegisterForNavigation("N36200View");
+ containerRegistry.RegisterForNavigation("N36600View");
+ containerRegistry.RegisterForNavigation("N69200View");
+ containerRegistry.RegisterForNavigation("SDS2000X_HDView");
+ containerRegistry.RegisterForNavigation("SPAW7000View");
+ }
+ }
+}
diff --git a/DeviceEditModule/DeviceEditModule.csproj b/DeviceEditModule/DeviceEditModule.csproj
new file mode 100644
index 0000000..df66d46
--- /dev/null
+++ b/DeviceEditModule/DeviceEditModule.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net8.0-windows
+ enable
+ true
+ enable
+
+
+
+
+
+
+
+
diff --git a/DeviceEditModule/ViewModels/DialogMangerViewModel.cs b/DeviceEditModule/ViewModels/DialogMangerViewModel.cs
new file mode 100644
index 0000000..1d29cdd
--- /dev/null
+++ b/DeviceEditModule/ViewModels/DialogMangerViewModel.cs
@@ -0,0 +1,149 @@
+using Prism.Commands;
+using Prism.Ioc;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Windows.Input;
+using UIShare.PubEvent;
+using UIShare.UIViewModel;
+using UIShare.ViewModelBase;
+
+namespace DeviceEditModule.ViewModels
+{
+ ///
+ /// 弹窗管理器 ViewModel。
+ ///
+ /// 职责:
+ /// 1. 订阅 ,将外部弹窗注册为 Tab;
+ /// 2. 维护 集合,控制选中/关闭逻辑;
+ /// 3. 最小化:通过 事件通知 View 执行 P/Invoke 窗口操作;
+ /// 4. 关闭:调用 。
+ ///
+ ///
+ public class DialogMangerViewModel : DialogViewModelBase, IDisposable
+ {
+ #region 属性
+
+ /// 所有 Tab 项集合,绑定到标签条的 ItemsControl。
+ public ObservableCollection TagItems { get; } = new();
+
+ /// 以 Tab 标题为 key 追踪已打开的 Tab,防止重复打开。
+ private readonly Dictionary _tabDictionary = new();
+
+ private DialogTabItemVM? _selectedTag;
+ /// 当前激活的 Tab,其 Content 显示在内容区。
+ public DialogTabItemVM? SelectedTag
+ {
+ get => _selectedTag;
+ set => SetProperty(ref _selectedTag, value);
+ }
+
+ /// 是否没有任何 Tab(用于绑定空状态提示的 Visibility)。
+ public bool HasNoTabs => TagItems.Count == 0;
+
+ #endregion
+
+ #region 命令
+
+ public ICommand MinimizeCommand { get; }
+ public ICommand CloseCommand { get; }
+
+ #endregion
+
+ #region 事件
+
+ ///
+ /// View 订阅此事件后,在事件回调里执行 P/Invoke 最小化。
+ /// 这样 ViewModel 无需引用任何 UI 或 Win32 类型。
+ ///
+ public event EventHandler? MinimizeRequested;
+ public event EventHandler? RestoreRequested;
+ #endregion
+
+ public DialogMangerViewModel(IContainerProvider containerProvider) : base(containerProvider)
+ {
+ MinimizeCommand = new DelegateCommand(OnMinimize);
+ CloseCommand = new DelegateCommand(OnClose);
+
+ // 订阅来自其他模块的"添加 Tab"事件
+ _eventAggregator.GetEvent().Subscribe(OnAddTab, ThreadOption.UIThread);
+ _eventAggregator.GetEvent().Subscribe(()=>RestoreRequested.Invoke(this, EventArgs.Empty));
+ }
+
+ #region 命令处理
+
+ private void OnMinimize() => MinimizeRequested?.Invoke(this, EventArgs.Empty);
+
+ private void OnClose()
+ {
+ // 关闭前清空所有 Tab,释放内容引用,并清除去重字典
+ _tabDictionary.Clear();
+ TagItems.Clear();
+ SelectedTag = null;
+ RequestClose.Invoke();
+ }
+
+ #endregion
+
+ #region Tab 管理
+
+ /// 收到事件:若 Tab 已存在则激活,否则创建并追加到集合。
+ private void OnAddTab(DialogTabInfo info)
+ {
+ // 已有相同标题的 Tab → 直接激活,不重复创建
+ if (_tabDictionary.TryGetValue(info.Title, out var existing))
+ {
+ ActivateTab(existing);
+ return;
+ }
+
+ var tab = new DialogTabItemVM(OnSelectTab, OnCloseTab)
+ {
+ Title = info.Title,
+ Content = info.Content
+ };
+
+ _tabDictionary[info.Title] = tab;
+ TagItems.Add(tab);
+ RaisePropertyChanged(nameof(HasNoTabs));
+ ActivateTab(tab);
+ }
+
+ /// 激活(选中)指定 Tab,其余全部取消选中。
+ private void OnSelectTab(DialogTabItemVM tab) => ActivateTab(tab);
+
+ /// 关闭指定 Tab,自动选中相邻 Tab(或清空内容区)。
+ private void OnCloseTab(DialogTabItemVM tab)
+ {
+ int idx = TagItems.IndexOf(tab);
+ _tabDictionary.Remove(tab.Title);
+ TagItems.Remove(tab);
+ RaisePropertyChanged(nameof(HasNoTabs));
+
+ if (TagItems.Count == 0)
+ {
+ SelectedTag = null;
+ return;
+ }
+
+ // 优先选左侧邻 Tab,无左侧则选当前索引(已向左移一位)
+ ActivateTab(TagItems[Math.Max(0, idx - 1)]);
+ }
+
+ private void ActivateTab(DialogTabItemVM tab)
+ {
+ foreach (var t in TagItems)
+ t.IsSelected = false;
+
+ tab.IsSelected = true;
+ SelectedTag = tab;
+ }
+
+ #endregion
+
+ public void Dispose()
+ {
+ _eventAggregator.GetEvent().Unsubscribe(OnAddTab);
+ }
+ }
+}
diff --git a/DeviceEditModule/ViewModels/IT7800EViewModel.cs b/DeviceEditModule/ViewModels/IT7800EViewModel.cs
new file mode 100644
index 0000000..5809fc3
--- /dev/null
+++ b/DeviceEditModule/ViewModels/IT7800EViewModel.cs
@@ -0,0 +1,310 @@
+using DeviceCommand.Device;
+using Prism.Commands;
+using Prism.Ioc;
+using System;
+using System.Threading;
+using System.Windows.Input;
+using UIShare.GlobalVariable;
+using UIShare.ViewModelBase;
+
+namespace DeviceEditModule.ViewModels
+{
+ ///
+ /// IT7800E 交直流电源控制面板 ViewModel。
+ ///
+ /// 注册为 Navigation View,既可由 Region 导航进入,
+ /// 也可由外部直接实例化后作为 Tab 内容塞入 DialogMangerView:
+ ///
+ /// var view = container.Resolve<IT7800EView>();
+ /// (view.DataContext as IT7800EViewModel)?.Initialize("IT7800E");
+ /// _eventAggregator.GetEvent<AddDialogTabEvent>().Publish(
+ /// new DialogTabInfo { Title = "IT7800E", Content = view });
+ ///
+ ///
+ ///
+ public class IT7800EViewModel : NavigateViewModelBase, IDisposable
+ {
+ #region 私有字段
+
+ private readonly DeviceManager _deviceManager;
+ private IT7800E? _device;
+ private CancellationTokenSource? _cts;
+
+ #endregion
+
+ #region 设备信息属性
+
+ private string _deviceName = "IT7800E";
+ public string DeviceName
+ {
+ get => _deviceName;
+ set => SetProperty(ref _deviceName, value);
+ }
+
+ private bool _isConnected;
+ public bool IsConnected
+ {
+ get => _isConnected;
+ set => SetProperty(ref _isConnected, value);
+ }
+
+ private bool _isBusy;
+ /// 正在执行设备命令时为 true,用于 UI 忙碌状态指示。
+ public bool IsBusy
+ {
+ get => _isBusy;
+ set => SetProperty(ref _isBusy, value);
+ }
+
+ #endregion
+
+ #region 输入参数属性
+
+ private double _acVoltage = 220.0;
+ /// 待设置的交流电压值(V)。
+ public double AcVoltage
+ {
+ get => _acVoltage;
+ set => SetProperty(ref _acVoltage, value);
+ }
+
+ private double _dcVoltage = 0.0;
+ /// 待设置的直流偏置电压值(V)。
+ public double DcVoltage
+ {
+ get => _dcVoltage;
+ set => SetProperty(ref _dcVoltage, value);
+ }
+
+ private double _frequency = 50.0;
+ /// 待设置的交流频率(Hz)。
+ public double Frequency
+ {
+ get => _frequency;
+ set => SetProperty(ref _frequency, value);
+ }
+
+ private double _currentLimit = 10.0;
+ /// 待设置的限流值(A)。
+ public double CurrentLimit
+ {
+ get => _currentLimit;
+ set => SetProperty(ref _currentLimit, value);
+ }
+
+ private string _selectedMode = "AC";
+ /// 待设置的电源工作模式:AC / DC / ACDC。
+ public string SelectedMode
+ {
+ get => _selectedMode;
+ set => SetProperty(ref _selectedMode, value);
+ }
+
+ private double _ovpValue = 260.0;
+ /// 过压保护值(V)。
+ public double OvpValue
+ {
+ get => _ovpValue;
+ set => SetProperty(ref _ovpValue, value);
+ }
+
+ private double _ocpValue = 15.0;
+ /// 过流保护值(A)。
+ public double OcpValue
+ {
+ get => _ocpValue;
+ set => SetProperty(ref _ocpValue, value);
+ }
+
+ #endregion
+
+ #region 测量结果属性
+
+ private string _measuredVoltage = "—";
+ public string MeasuredVoltage
+ {
+ get => _measuredVoltage;
+ set => SetProperty(ref _measuredVoltage, value);
+ }
+
+ private string _measuredCurrent = "—";
+ public string MeasuredCurrent
+ {
+ get => _measuredCurrent;
+ set => SetProperty(ref _measuredCurrent, value);
+ }
+
+ private string _measuredPower = "—";
+ public string MeasuredPower
+ {
+ get => _measuredPower;
+ set => SetProperty(ref _measuredPower, value);
+ }
+
+ private string _measuredFrequency = "—";
+ public string MeasuredFrequency
+ {
+ get => _measuredFrequency;
+ set => SetProperty(ref _measuredFrequency, value);
+ }
+
+ private string _responseLog = string.Empty;
+ /// 命令响应日志(最新消息在顶部)。
+ public string ResponseLog
+ {
+ get => _responseLog;
+ set => SetProperty(ref _responseLog, value);
+ }
+
+ #endregion
+
+ #region 命令
+
+ public ICommand QueryIdentityCommand { get; }
+ public ICommand ResetDeviceCommand { get; }
+ public ICommand OutputOnCommand { get; }
+ public ICommand OutputOffCommand { get; }
+ public ICommand SetModeCommand { get; }
+ public ICommand SetAcVoltageCommand { get; }
+ public ICommand SetDcVoltageCommand { get; }
+ public ICommand SetFrequencyCommand { get; }
+ public ICommand SetCurrentCommand { get; }
+ public ICommand QueryAllMeasureCommand { get; }
+ public ICommand SetRemoteModeCommand { get; }
+ public ICommand SetLocalModeCommand { get; }
+ public ICommand SetOvpCommand { get; }
+ public ICommand SetOcpCommand { get; }
+ public ICommand ClearAlarmCommand { get; }
+ public ICommand ClearErrorCommand { get; }
+
+ #endregion
+
+ public IT7800EViewModel(IContainerProvider containerProvider) : base(containerProvider)
+ {
+ _deviceManager = containerProvider.Resolve();
+
+ QueryIdentityCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("IDN: " + await _device!.查询设备标识(Ct()))));
+ ResetDeviceCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.重置设备(Ct()); AppendLog("设备已重置"); }));
+ OutputOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输出(true, Ct()); AppendLog("输出已开启"); }));
+ OutputOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输出(false, Ct()); AppendLog("输出已关闭"); }));
+ SetModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电源模式(SelectedMode, Ct()); AppendLog($"模式已设为 {SelectedMode}"); }));
+ SetAcVoltageCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置交流电压(AcVoltage, Ct()); AppendLog($"AC电压已设为 {AcVoltage} V"); }));
+ SetDcVoltageCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置直流电压(DcVoltage, Ct()); AppendLog($"DC偏置已设为 {DcVoltage} V"); }));
+ SetFrequencyCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置频率(Frequency, Ct()); AppendLog($"频率已设为 {Frequency} Hz"); }));
+ SetCurrentCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电流(CurrentLimit, Ct()); AppendLog($"限流已设为 {CurrentLimit} A"); }));
+ SetOvpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过压保护_OVP(OvpValue, Ct()); AppendLog($"OVP已设为 {OvpValue} V"); }));
+ SetOcpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过流保护_OCP(OcpValue, Ct()); AppendLog($"OCP已设为 {OcpValue} A"); }));
+ SetRemoteModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.切换远程控制模式(Ct()); AppendLog("已切换到远程控制模式"); }));
+ SetLocalModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.切换本地控制模式(Ct()); AppendLog("已切换到本地控制模式"); }));
+ ClearAlarmCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.清除保护告警(Ct()); AppendLog("保护告警已清除"); }));
+ ClearErrorCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.清除错误队列和状态字节(Ct()); AppendLog("错误队列已清除"); }));
+
+ QueryAllMeasureCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ MeasuredVoltage = await _device!.查询实际电压(Ct());
+ MeasuredCurrent = await _device!.查询实际电流(Ct());
+ MeasuredPower = await _device!.查询实际功率(Ct());
+ MeasuredFrequency = await _device!.查询实际频率(Ct());
+ AppendLog($"测量 → 电压:{MeasuredVoltage}V 电流:{MeasuredCurrent}A 功率:{MeasuredPower}W 频率:{MeasuredFrequency}Hz");
+ }));
+
+ Initialize();
+ }
+
+ #region 初始化 / Navigation
+
+ ///
+ /// 从 DeviceManager 中查找 IT7800E 设备实例。
+ /// 优先按 查找,否则取第一个匹配类型的设备。
+ ///
+ public void Initialize(string? deviceName = null)
+ {
+ IT7800E? found = null;
+ string? foundName = null;
+
+ if (deviceName != null &&
+ _deviceManager.DeviceMap.TryGetValue(deviceName, out var d) &&
+ d is IT7800E e)
+ {
+ found = e;
+ foundName = deviceName;
+ }
+ else
+ {
+ foreach (var kv in _deviceManager.DeviceMap)
+ {
+ if (kv.Value is IT7800E it)
+ {
+ found = it;
+ foundName = kv.Key;
+ break;
+ }
+ }
+ }
+
+ _device = found;
+ DeviceName = foundName ?? "IT7800E (未找到)";
+ IsConnected = _device?.IsConnected ?? false;
+
+ AppendLog(found != null
+ ? $"已关联设备 [{DeviceName}],连接状态:{(IsConnected ? "已连接" : "未连接")}"
+ : "未在 DeviceManager 中找到 IT7800E 设备,请先初始化设备配置。");
+ }
+
+ public override void OnNavigatedTo(NavigationContext context)
+ {
+ var name = context.Parameters.GetValue("DeviceName");
+ Initialize(name);
+ }
+
+ #endregion
+
+ #region 辅助
+
+ private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
+
+ private async Task Exec(Func action)
+ {
+ if (_device == null)
+ {
+ AppendLog("错误:未关联到设备实例,请检查设备配置。");
+ return;
+ }
+ if (IsBusy) return;
+ IsBusy = true;
+ try
+ {
+ await action();
+ IsConnected = _device.IsConnected;
+ }
+ catch (OperationCanceledException)
+ {
+ AppendLog("命令超时或已取消。");
+ }
+ catch (Exception ex)
+ {
+ AppendLog($"错误:{ex.Message}");
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ private void AppendLog(string message)
+ {
+ var line = $"[{DateTime.Now:HH:mm:ss}] {message}";
+ ResponseLog = ResponseLog.Length > 4000
+ ? line + "\n" + ResponseLog[..3000]
+ : line + "\n" + ResponseLog;
+ }
+
+ #endregion
+
+ public void Dispose()
+ {
+ _cts?.Cancel();
+ _cts?.Dispose();
+ }
+ }
+}
diff --git a/DeviceEditModule/ViewModels/N36200ViewModel.cs b/DeviceEditModule/ViewModels/N36200ViewModel.cs
new file mode 100644
index 0000000..77c31e0
--- /dev/null
+++ b/DeviceEditModule/ViewModels/N36200ViewModel.cs
@@ -0,0 +1,309 @@
+using DeviceCommand.Device;
+using Prism.Commands;
+using Prism.Ioc;
+using System;
+using System.Threading;
+using System.Windows.Input;
+using UIShare.GlobalVariable;
+using UIShare.ViewModelBase;
+
+namespace DeviceEditModule.ViewModels
+{
+ ///
+ /// N36200 宽范围可编程直流电源控制面板 ViewModel。
+ ///
+ /// 注册为 Navigation View,可通过 EventAggregator 添加为 DialogMangerView 中的 Tab:
+ ///
+ /// var view = container.Resolve<N36200View>();
+ /// (view.DataContext as N36200ViewModel)?.Initialize("N36200");
+ /// _eventAggregator.GetEvent<AddDialogTabEvent>().Publish(
+ /// new DialogTabInfo { Title = "N36200", Content = view });
+ ///
+ ///
+ ///
+ public class N36200ViewModel : NavigateViewModelBase, IDisposable
+ {
+ #region 私有字段
+
+ private readonly DeviceManager _deviceManager;
+ private N36200? _device;
+ private CancellationTokenSource? _cts;
+
+ #endregion
+
+ #region 设备信息属性
+
+ private string _deviceName = "N36200";
+ public string DeviceName
+ {
+ get => _deviceName;
+ set => SetProperty(ref _deviceName, value);
+ }
+
+ private bool _isConnected;
+ public bool IsConnected
+ {
+ get => _isConnected;
+ set => SetProperty(ref _isConnected, value);
+ }
+
+ private bool _isBusy;
+ public bool IsBusy
+ {
+ get => _isBusy;
+ set => SetProperty(ref _isBusy, value);
+ }
+
+ #endregion
+
+ #region 输入参数属性
+
+ private double _voltage = 12.0;
+ /// 待设置的输出电压值(V)。
+ public double Voltage
+ {
+ get => _voltage;
+ set => SetProperty(ref _voltage, value);
+ }
+
+ private double _currentLimit = 5.0;
+ /// 待设置的限流值(A)。
+ public double CurrentLimit
+ {
+ get => _currentLimit;
+ set => SetProperty(ref _currentLimit, value);
+ }
+
+ private string _selectedMode = "NORMal";
+ /// 待设置的运行模式:NORMal / CHARge / SEQuence / CPOWer / CARWave / APG。
+ public string SelectedMode
+ {
+ get => _selectedMode;
+ set => SetProperty(ref _selectedMode, value);
+ }
+
+ private double _ovpValue = 15.0;
+ /// 过压保护值(V)。
+ public double OvpValue
+ {
+ get => _ovpValue;
+ set => SetProperty(ref _ovpValue, value);
+ }
+
+ private double _ocpValue = 6.0;
+ /// 过流保护值(A)。
+ public double OcpValue
+ {
+ get => _ocpValue;
+ set => SetProperty(ref _ocpValue, value);
+ }
+
+ private double _uvpValue = 0.0;
+ /// 欠压保护值(V)。
+ public double UvpValue
+ {
+ get => _uvpValue;
+ set => SetProperty(ref _uvpValue, value);
+ }
+
+ private double _oppValue = 100.0;
+ /// 过功率保护值(W)。
+ public double OppValue
+ {
+ get => _oppValue;
+ set => SetProperty(ref _oppValue, value);
+ }
+
+ #endregion
+
+ #region 测量结果属性
+
+ private string _measuredVoltage = "—";
+ public string MeasuredVoltage
+ {
+ get => _measuredVoltage;
+ set => SetProperty(ref _measuredVoltage, value);
+ }
+
+ private string _measuredCurrent = "—";
+ public string MeasuredCurrent
+ {
+ get => _measuredCurrent;
+ set => SetProperty(ref _measuredCurrent, value);
+ }
+
+ private string _measuredPower = "—";
+ public string MeasuredPower
+ {
+ get => _measuredPower;
+ set => SetProperty(ref _measuredPower, value);
+ }
+
+ private string _deviceStatus = "—";
+ /// 设备状态字(OUTPut:STATe? 查询结果)。
+ public string DeviceStatus
+ {
+ get => _deviceStatus;
+ set => SetProperty(ref _deviceStatus, value);
+ }
+
+ private string _responseLog = string.Empty;
+ /// 命令响应日志(最新消息在顶部)。
+ public string ResponseLog
+ {
+ get => _responseLog;
+ set => SetProperty(ref _responseLog, value);
+ }
+
+ #endregion
+
+ #region 命令
+
+ public ICommand QueryIdentityCommand { get; }
+ public ICommand ResetDeviceCommand { get; }
+ public ICommand OutputOnCommand { get; }
+ public ICommand OutputOffCommand { get; }
+ public ICommand SetVoltageCommand { get; }
+ public ICommand SetCurrentCommand { get; }
+ public ICommand SetModeCommand { get; }
+ public ICommand QueryAllMeasureCommand { get; }
+ public ICommand QueryStatusCommand { get; }
+ public ICommand SetOvpCommand { get; }
+ public ICommand SetOcpCommand { get; }
+ public ICommand SetUvpCommand { get; }
+ public ICommand SetOppCommand { get; }
+ public ICommand ClearAlarmCommand { get; }
+
+ #endregion
+
+ public N36200ViewModel(IContainerProvider containerProvider) : base(containerProvider)
+ {
+ _deviceManager = containerProvider.Resolve();
+
+ QueryIdentityCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("IDN: " + await _device!.查询设备标识(Ct()))));
+ ResetDeviceCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.重置设备(Ct()); AppendLog("设备已重置(耗时约10s)"); }));
+ OutputOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输出(true, Ct()); AppendLog("输出已开启"); }));
+ OutputOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输出(false, Ct()); AppendLog("输出已关闭"); }));
+ SetVoltageCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电压(Voltage, Ct()); AppendLog($"电压已设为 {Voltage} V"); }));
+ SetCurrentCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电流(CurrentLimit, Ct()); AppendLog($"限流已设为 {CurrentLimit} A"); }));
+ SetModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置运行模式(SelectedMode, Ct()); AppendLog($"模式已设为 {SelectedMode}"); }));
+ SetOvpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过压保护_OVP(OvpValue, Ct()); AppendLog($"OVP已设为 {OvpValue} V"); }));
+ SetOcpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过流保护_OCP(OcpValue, Ct()); AppendLog($"OCP已设为 {OcpValue} A"); }));
+ SetUvpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过欠压保护_UVP(UvpValue, Ct()); AppendLog($"UVP已设为 {UvpValue} V"); }));
+ SetOppCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过功率保护_OPP(OppValue, Ct()); AppendLog($"OPP已设为 {OppValue} W"); }));
+ ClearAlarmCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.清除告警(Ct()); AppendLog("告警已清除"); }));
+
+ QueryStatusCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ DeviceStatus = await _device!.查询设备状态字(Ct());
+ AppendLog($"状态字: {DeviceStatus}");
+ }));
+
+ QueryAllMeasureCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ MeasuredVoltage = await _device!.查询实际电压(Ct());
+ MeasuredCurrent = await _device!.查询实际电流(Ct());
+ MeasuredPower = await _device!.查询实际功率(Ct());
+ AppendLog($"测量 → 电压:{MeasuredVoltage}V 电流:{MeasuredCurrent}A 功率:{MeasuredPower}W");
+ }));
+
+ Initialize();
+ }
+
+ #region 初始化 / Navigation
+
+ ///
+ /// 从 DeviceManager 中查找 N36200 设备实例。
+ /// 优先按 查找,否则取第一个匹配类型的设备。
+ ///
+ public void Initialize(string? deviceName = null)
+ {
+ N36200? found = null;
+ string? foundName = null;
+
+ if (deviceName != null &&
+ _deviceManager.DeviceMap.TryGetValue(deviceName, out var d) &&
+ d is N36200 n)
+ {
+ found = n;
+ foundName = deviceName;
+ }
+ else
+ {
+ foreach (var kv in _deviceManager.DeviceMap)
+ {
+ if (kv.Value is N36200 n36)
+ {
+ found = n36;
+ foundName = kv.Key;
+ break;
+ }
+ }
+ }
+
+ _device = found;
+ DeviceName = foundName ?? "N36200 (未找到)";
+ IsConnected = _device?.IsConnected ?? false;
+
+ AppendLog(found != null
+ ? $"已关联设备 [{DeviceName}],连接状态:{(IsConnected ? "已连接" : "未连接")}"
+ : "未在 DeviceManager 中找到 N36200 设备,请先初始化设备配置。");
+ }
+
+ public override void OnNavigatedTo(NavigationContext context)
+ {
+ var name = context.Parameters.GetValue("DeviceName");
+ Initialize(name);
+ }
+
+ #endregion
+
+ #region 辅助
+
+ private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
+
+ private async Task Exec(Func action)
+ {
+ if (_device == null)
+ {
+ AppendLog("错误:未关联到设备实例,请检查设备配置。");
+ return;
+ }
+ if (IsBusy) return;
+ IsBusy = true;
+ try
+ {
+ await action();
+ IsConnected = _device.IsConnected;
+ }
+ catch (OperationCanceledException)
+ {
+ AppendLog("命令超时或已取消。");
+ }
+ catch (Exception ex)
+ {
+ AppendLog($"错误:{ex.Message}");
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ private void AppendLog(string message)
+ {
+ var line = $"[{DateTime.Now:HH:mm:ss}] {message}";
+ ResponseLog = ResponseLog.Length > 4000
+ ? line + "\n" + ResponseLog[..3000]
+ : line + "\n" + ResponseLog;
+ }
+
+ #endregion
+
+ public void Dispose()
+ {
+ _cts?.Cancel();
+ _cts?.Dispose();
+ }
+ }
+}
diff --git a/DeviceEditModule/ViewModels/N36600ViewModel.cs b/DeviceEditModule/ViewModels/N36600ViewModel.cs
new file mode 100644
index 0000000..49f8eb2
--- /dev/null
+++ b/DeviceEditModule/ViewModels/N36600ViewModel.cs
@@ -0,0 +1,280 @@
+using DeviceCommand.Device;
+using Prism.Commands;
+using Prism.Ioc;
+using System;
+using System.Threading;
+using System.Windows.Input;
+using UIShare.GlobalVariable;
+using UIShare.ViewModelBase;
+
+namespace DeviceEditModule.ViewModels
+{
+ ///
+ /// N36600 便携式宽范围可编程直流电源控制面板 ViewModel。
+ ///
+ public class N36600ViewModel : NavigateViewModelBase, IDisposable
+ {
+ #region 私有字段
+
+ private readonly DeviceManager _deviceManager;
+ private N36600? _device;
+ private CancellationTokenSource? _cts;
+
+ #endregion
+
+ #region 设备信息属性
+
+ private string _deviceName = "N36600";
+ public string DeviceName
+ {
+ get => _deviceName;
+ set => SetProperty(ref _deviceName, value);
+ }
+
+ private bool _isConnected;
+ public bool IsConnected
+ {
+ get => _isConnected;
+ set => SetProperty(ref _isConnected, value);
+ }
+
+ private bool _isBusy;
+ public bool IsBusy
+ {
+ get => _isBusy;
+ set => SetProperty(ref _isBusy, value);
+ }
+
+ #endregion
+
+ #region 输入参数属性
+
+ private double _voltage = 12.0;
+ /// 待设置的输出电压值(V)。
+ public double Voltage
+ {
+ get => _voltage;
+ set => SetProperty(ref _voltage, value);
+ }
+
+ private double _currentLimit = 5.0;
+ /// 待设置的输出电流值(A)。
+ public double CurrentLimit
+ {
+ get => _currentLimit;
+ set => SetProperty(ref _currentLimit, value);
+ }
+
+ private double _power = 60.0;
+ /// 待设置的输出功率值(W)。
+ public double Power
+ {
+ get => _power;
+ set => SetProperty(ref _power, value);
+ }
+
+ private double _ovpValue = 15.0;
+ /// 过压保护值(V)。
+ public double OvpValue
+ {
+ get => _ovpValue;
+ set => SetProperty(ref _ovpValue, value);
+ }
+
+ private double _ocpValue = 6.0;
+ /// 过流保护值(A)。
+ public double OcpValue
+ {
+ get => _ocpValue;
+ set => SetProperty(ref _ocpValue, value);
+ }
+
+ #endregion
+
+ #region 测量结果属性
+
+ private string _measuredVoltage = "—";
+ public string MeasuredVoltage
+ {
+ get => _measuredVoltage;
+ set => SetProperty(ref _measuredVoltage, value);
+ }
+
+ private string _measuredCurrent = "—";
+ public string MeasuredCurrent
+ {
+ get => _measuredCurrent;
+ set => SetProperty(ref _measuredCurrent, value);
+ }
+
+ private string _measuredPower = "—";
+ public string MeasuredPower
+ {
+ get => _measuredPower;
+ set => SetProperty(ref _measuredPower, value);
+ }
+
+ private string _outputState = "—";
+ /// 当前 DC 输出状态(OUTPut? 查询结果)。
+ public string OutputState
+ {
+ get => _outputState;
+ set => SetProperty(ref _outputState, value);
+ }
+
+ private string _responseLog = string.Empty;
+ /// 命令响应日志(最新消息在顶部)。
+ public string ResponseLog
+ {
+ get => _responseLog;
+ set => SetProperty(ref _responseLog, value);
+ }
+
+ #endregion
+
+ #region 命令
+
+ public ICommand QueryIdentityCommand { get; }
+ public ICommand OutputOnCommand { get; }
+ public ICommand OutputOffCommand { get; }
+ public ICommand SetVoltageCommand { get; }
+ public ICommand SetCurrentCommand { get; }
+ public ICommand SetPowerCommand { get; }
+ public ICommand SetOvpCommand { get; }
+ public ICommand SetOcpCommand { get; }
+ public ICommand QueryAllMeasureCommand { get; }
+ public ICommand QueryOutputStateCommand { get; }
+ public ICommand SetRemoteModeCommand { get; }
+ public ICommand SetLocalModeCommand { get; }
+ public ICommand ClearVoltageProtectionCommand { get; }
+ public ICommand ClearCurrentProtectionCommand { get; }
+
+ #endregion
+
+ public N36600ViewModel(IContainerProvider containerProvider) : base(containerProvider)
+ {
+ _deviceManager = containerProvider.Resolve();
+
+ QueryIdentityCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("IDN: " + await _device!.查询设备标识(Ct()))));
+ OutputOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输出(true, Ct()); AppendLog("输出已开启"); }));
+ OutputOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输出(false, Ct()); AppendLog("输出已关闭"); }));
+ SetVoltageCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电压(Voltage, Ct()); AppendLog($"电压已设为 {Voltage} V"); }));
+ SetCurrentCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电流(CurrentLimit, Ct()); AppendLog($"电流已设为 {CurrentLimit} A"); }));
+ SetPowerCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置功率(Power, Ct()); AppendLog($"功率已设为 {Power} W"); }));
+ SetOvpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过压保护值(OvpValue, Ct()); AppendLog($"OVP已设为 {OvpValue} V"); }));
+ SetOcpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过流保护值(OcpValue, Ct()); AppendLog($"OCP已设为 {OcpValue} A"); }));
+ SetRemoteModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.切换远程控制模式(Ct()); AppendLog("已切换到远程控制模式"); }));
+ SetLocalModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.切换本地控制模式(Ct()); AppendLog("已切换到本地控制模式"); }));
+ ClearVoltageProtectionCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.清除电压保护状态(Ct()); AppendLog("电压保护状态已清除"); }));
+ ClearCurrentProtectionCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.清除电流保护状态(Ct()); AppendLog("电流保护状态已清除"); }));
+
+ QueryOutputStateCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ OutputState = await _device!.查询DC输出状态(Ct());
+ AppendLog($"输出状态: {OutputState}");
+ }));
+
+ QueryAllMeasureCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ MeasuredVoltage = await _device!.查询实际电压(Ct());
+ MeasuredCurrent = await _device!.查询实际电流(Ct());
+ MeasuredPower = await _device!.查询实际功率(Ct());
+ AppendLog($"测量 → 电压:{MeasuredVoltage}V 电流:{MeasuredCurrent}A 功率:{MeasuredPower}W");
+ }));
+
+ Initialize();
+ }
+
+ #region 初始化 / Navigation
+
+ public void Initialize(string? deviceName = null)
+ {
+ N36600? found = null;
+ string? foundName = null;
+
+ if (deviceName != null &&
+ _deviceManager.DeviceMap.TryGetValue(deviceName, out var d) &&
+ d is N36600 n)
+ {
+ found = n;
+ foundName = deviceName;
+ }
+ else
+ {
+ foreach (var kv in _deviceManager.DeviceMap)
+ {
+ if (kv.Value is N36600 n36)
+ {
+ found = n36;
+ foundName = kv.Key;
+ break;
+ }
+ }
+ }
+
+ _device = found;
+ DeviceName = foundName ?? "N36600 (未找到)";
+ IsConnected = _device?.IsConnected ?? false;
+
+ AppendLog(found != null
+ ? $"已关联设备 [{DeviceName}],连接状态:{(IsConnected ? "已连接" : "未连接")}"
+ : "未在 DeviceManager 中找到 N36600 设备,请先初始化设备配置。");
+ }
+
+ public override void OnNavigatedTo(NavigationContext context)
+ {
+ var name = context.Parameters.GetValue("DeviceName");
+ Initialize(name);
+ }
+
+ #endregion
+
+ #region 辅助
+
+ private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
+
+ private async Task Exec(Func action)
+ {
+ if (_device == null)
+ {
+ AppendLog("错误:未关联到设备实例,请检查设备配置。");
+ return;
+ }
+ if (IsBusy) return;
+ IsBusy = true;
+ try
+ {
+ await action();
+ IsConnected = _device.IsConnected;
+ }
+ catch (OperationCanceledException)
+ {
+ AppendLog("命令超时或已取消。");
+ }
+ catch (Exception ex)
+ {
+ AppendLog($"错误:{ex.Message}");
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ private void AppendLog(string message)
+ {
+ var line = $"[{DateTime.Now:HH:mm:ss}] {message}";
+ ResponseLog = ResponseLog.Length > 4000
+ ? line + "\n" + ResponseLog[..3000]
+ : line + "\n" + ResponseLog;
+ }
+
+ #endregion
+
+ public void Dispose()
+ {
+ _cts?.Cancel();
+ _cts?.Dispose();
+ }
+ }
+}
diff --git a/DeviceEditModule/ViewModels/N69200ViewModel.cs b/DeviceEditModule/ViewModels/N69200ViewModel.cs
new file mode 100644
index 0000000..e51a1e3
--- /dev/null
+++ b/DeviceEditModule/ViewModels/N69200ViewModel.cs
@@ -0,0 +1,316 @@
+using DeviceCommand.Device;
+using Prism.Commands;
+using Prism.Ioc;
+using System;
+using System.Threading;
+using System.Windows.Input;
+using UIShare.GlobalVariable;
+using UIShare.ViewModelBase;
+
+namespace DeviceEditModule.ViewModels
+{
+ ///
+ /// N69200 可编程直流电子负载控制面板 ViewModel。
+ ///
+ public class N69200ViewModel : NavigateViewModelBase, IDisposable
+ {
+ #region 私有字段
+
+ private readonly DeviceManager _deviceManager;
+ private N69200? _device;
+ private CancellationTokenSource? _cts;
+
+ #endregion
+
+ #region 设备信息属性
+
+ private string _deviceName = "N69200";
+ public string DeviceName
+ {
+ get => _deviceName;
+ set => SetProperty(ref _deviceName, value);
+ }
+
+ private bool _isConnected;
+ public bool IsConnected
+ {
+ get => _isConnected;
+ set => SetProperty(ref _isConnected, value);
+ }
+
+ private bool _isBusy;
+ public bool IsBusy
+ {
+ get => _isBusy;
+ set => SetProperty(ref _isBusy, value);
+ }
+
+ #endregion
+
+ #region 输入参数属性
+
+ private string _selectedMode = "CC";
+ /// 工作模式:CC / CV / CP / CR。
+ public string SelectedMode
+ {
+ get => _selectedMode;
+ set => SetProperty(ref _selectedMode, value);
+ }
+
+ private double _loadValue = 1.0;
+ /// 设定值(根据 SelectedMode 代表 A / V / W / Ω)。
+ public double LoadValue
+ {
+ get => _loadValue;
+ set => SetProperty(ref _loadValue, value);
+ }
+
+ private double _ovpValue = 60.0;
+ /// 过压保护值(V)。
+ public double OvpValue
+ {
+ get => _ovpValue;
+ set => SetProperty(ref _ovpValue, value);
+ }
+
+ private double _ocpValue = 10.0;
+ /// 过流保护值(A)。
+ public double OcpValue
+ {
+ get => _ocpValue;
+ set => SetProperty(ref _ocpValue, value);
+ }
+
+ private double _oppValue = 200.0;
+ /// 过功率保护值(W)。
+ public double OppValue
+ {
+ get => _oppValue;
+ set => SetProperty(ref _oppValue, value);
+ }
+
+ #endregion
+
+ #region 测量结果属性
+
+ private string _measuredVoltage = "—";
+ public string MeasuredVoltage
+ {
+ get => _measuredVoltage;
+ set => SetProperty(ref _measuredVoltage, value);
+ }
+
+ private string _measuredCurrent = "—";
+ public string MeasuredCurrent
+ {
+ get => _measuredCurrent;
+ set => SetProperty(ref _measuredCurrent, value);
+ }
+
+ private string _measuredPower = "—";
+ public string MeasuredPower
+ {
+ get => _measuredPower;
+ set => SetProperty(ref _measuredPower, value);
+ }
+
+ private string _currentMode = "—";
+ /// 当前负载模式(MODE? 查询结果)。
+ public string CurrentMode
+ {
+ get => _currentMode;
+ set => SetProperty(ref _currentMode, value);
+ }
+
+ private string _statusByte = "—";
+ /// 状态字节(*STB? 查询结果)。
+ public string StatusByte
+ {
+ get => _statusByte;
+ set => SetProperty(ref _statusByte, value);
+ }
+
+ private string _responseLog = string.Empty;
+ /// 命令响应日志(最新消息在顶部)。
+ public string ResponseLog
+ {
+ get => _responseLog;
+ set => SetProperty(ref _responseLog, value);
+ }
+
+ #endregion
+
+ #region 命令
+
+ public ICommand QueryIdentityCommand { get; }
+ public ICommand ResetDeviceCommand { get; }
+ public ICommand InputOnCommand { get; }
+ public ICommand InputOffCommand { get; }
+ public ICommand SetModeCommand { get; }
+ public ICommand QueryModeCommand { get; }
+ public ICommand SetLoadValueCommand { get; }
+ public ICommand QueryAllMeasureCommand { get; }
+ public ICommand QueryStatusCommand { get; }
+ public ICommand SetOvpCommand { get; }
+ public ICommand SetOcpCommand { get; }
+ public ICommand SetOppCommand { get; }
+ public ICommand ClearAlarmCommand { get; }
+ public ICommand SetRemoteModeCommand { get; }
+ public ICommand SetLocalModeCommand { get; }
+
+ #endregion
+
+ public N69200ViewModel(IContainerProvider containerProvider) : base(containerProvider)
+ {
+ _deviceManager = containerProvider.Resolve();
+
+ QueryIdentityCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("IDN: " + await _device!.查询设备标识(Ct()))));
+ ResetDeviceCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.重置设备(Ct()); AppendLog("设备已重置"); }));
+ InputOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输入(true, Ct()); AppendLog("输入已开启"); }));
+ InputOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输入(false, Ct()); AppendLog("输入已关闭"); }));
+ SetModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置负载模式(SelectedMode, Ct()); AppendLog($"模式已设为 {SelectedMode}"); }));
+ QueryModeCommand = new DelegateCommand(async () => await Exec(async () => { CurrentMode = await _device!.查询负载模式(Ct()); AppendLog($"当前模式: {CurrentMode}"); }));
+ SetOvpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过压保护值_OVP(OvpValue, Ct()); AppendLog($"OVP已设为 {OvpValue} V"); }));
+ SetOcpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过流保护值_OCP(OcpValue, Ct()); AppendLog($"OCP已设为 {OcpValue} A"); }));
+ SetOppCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置过功率保护值_OPP(OppValue, Ct()); AppendLog($"OPP已设为 {OppValue} W"); }));
+ ClearAlarmCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.清除保护告警(Ct()); AppendLog("保护告警已清除"); }));
+ SetRemoteModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.切换远程控制模式(Ct()); AppendLog("已切换到远程控制模式"); }));
+ SetLocalModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.切换本地控制模式(Ct()); AppendLog("已切换到本地控制模式"); }));
+
+ SetLoadValueCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ var mode = SelectedMode.ToUpperInvariant();
+ switch (mode)
+ {
+ case "CC":
+ await _device!.设置恒电流CC(LoadValue, Ct());
+ AppendLog($"恒流 CC 已设为 {LoadValue} A");
+ break;
+ case "CV":
+ await _device!.设置恒电压CV(LoadValue, Ct());
+ AppendLog($"恒压 CV 已设为 {LoadValue} V");
+ break;
+ case "CP":
+ await _device!.设置恒功率CP(LoadValue, Ct());
+ AppendLog($"恒功率 CP 已设为 {LoadValue} W");
+ break;
+ case "CR":
+ await _device!.设置恒电阻CR(LoadValue, Ct());
+ AppendLog($"恒电阻 CR 已设为 {LoadValue} Ω");
+ break;
+ default:
+ AppendLog($"未知模式 {SelectedMode},无法设置设定值");
+ break;
+ }
+ }));
+
+ QueryStatusCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ StatusByte = await _device!.读取状态字节(Ct());
+ AppendLog($"状态字节: {StatusByte}");
+ }));
+
+ QueryAllMeasureCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ MeasuredVoltage = await _device!.查询实际电压(Ct());
+ MeasuredCurrent = await _device!.查询实际电流(Ct());
+ MeasuredPower = await _device!.查询实际功率(Ct());
+ AppendLog($"测量 → 电压:{MeasuredVoltage}V 电流:{MeasuredCurrent}A 功率:{MeasuredPower}W");
+ }));
+
+ Initialize();
+ }
+
+ #region 初始化 / Navigation
+
+ public void Initialize(string? deviceName = null)
+ {
+ N69200? found = null;
+ string? foundName = null;
+
+ if (deviceName != null &&
+ _deviceManager.DeviceMap.TryGetValue(deviceName, out var d) &&
+ d is N69200 n)
+ {
+ found = n;
+ foundName = deviceName;
+ }
+ else
+ {
+ foreach (var kv in _deviceManager.DeviceMap)
+ {
+ if (kv.Value is N69200 n69)
+ {
+ found = n69;
+ foundName = kv.Key;
+ break;
+ }
+ }
+ }
+
+ _device = found;
+ DeviceName = foundName ?? "N69200 (未找到)";
+ IsConnected = _device?.IsConnected ?? false;
+
+ AppendLog(found != null
+ ? $"已关联设备 [{DeviceName}],连接状态:{(IsConnected ? "已连接" : "未连接")}"
+ : "未在 DeviceManager 中找到 N69200 设备,请先初始化设备配置。");
+ }
+
+ public override void OnNavigatedTo(NavigationContext context)
+ {
+ var name = context.Parameters.GetValue("DeviceName");
+ Initialize(name);
+ }
+
+ #endregion
+
+ #region 辅助
+
+ private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
+
+ private async Task Exec(Func action)
+ {
+ if (_device == null)
+ {
+ AppendLog("错误:未关联到设备实例,请检查设备配置。");
+ return;
+ }
+ if (IsBusy) return;
+ IsBusy = true;
+ try
+ {
+ await action();
+ IsConnected = _device.IsConnected;
+ }
+ catch (OperationCanceledException)
+ {
+ AppendLog("命令超时或已取消。");
+ }
+ catch (Exception ex)
+ {
+ AppendLog($"错误:{ex.Message}");
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ private void AppendLog(string message)
+ {
+ var line = $"[{DateTime.Now:HH:mm:ss}] {message}";
+ ResponseLog = ResponseLog.Length > 4000
+ ? line + "\n" + ResponseLog[..3000]
+ : line + "\n" + ResponseLog;
+ }
+
+ #endregion
+
+ public void Dispose()
+ {
+ _cts?.Cancel();
+ _cts?.Dispose();
+ }
+ }
+}
diff --git a/DeviceEditModule/ViewModels/SDS2000X_HDViewModel.cs b/DeviceEditModule/ViewModels/SDS2000X_HDViewModel.cs
new file mode 100644
index 0000000..e5ba2ca
--- /dev/null
+++ b/DeviceEditModule/ViewModels/SDS2000X_HDViewModel.cs
@@ -0,0 +1,294 @@
+using DeviceCommand.Device;
+using Prism.Commands;
+using Prism.Ioc;
+using System;
+using System.Threading;
+using System.Windows.Input;
+using UIShare.GlobalVariable;
+using UIShare.ViewModelBase;
+
+namespace DeviceEditModule.ViewModels
+{
+ ///
+ /// SDS2000X_HD 数字存储示波器控制面板 ViewModel。
+ ///
+ public class SDS2000X_HDViewModel : NavigateViewModelBase, IDisposable
+ {
+ #region 私有字段
+
+ private readonly DeviceManager _deviceManager;
+ private SDS2000X_HD? _device;
+ private CancellationTokenSource? _cts;
+
+ #endregion
+
+ #region 设备信息属性
+
+ private string _deviceName = "SDS2000X_HD";
+ public string DeviceName
+ {
+ get => _deviceName;
+ set => SetProperty(ref _deviceName, value);
+ }
+
+ private bool _isConnected;
+ public bool IsConnected
+ {
+ get => _isConnected;
+ set => SetProperty(ref _isConnected, value);
+ }
+
+ private bool _isBusy;
+ public bool IsBusy
+ {
+ get => _isBusy;
+ set => SetProperty(ref _isBusy, value);
+ }
+
+ #endregion
+
+ #region 输入参数属性
+
+ private int _channel = 1;
+ /// 当前操作通道(1~4)。
+ public int Channel
+ {
+ get => _channel;
+ set => SetProperty(ref _channel, value);
+ }
+
+ private double _voltsPerDiv = 1.0;
+ /// 垂直电压档位(V/div)。
+ public double VoltsPerDiv
+ {
+ get => _voltsPerDiv;
+ set => SetProperty(ref _voltsPerDiv, value);
+ }
+
+ private double _offset = 0.0;
+ /// 垂直偏移(V)。
+ public double Offset
+ {
+ get => _offset;
+ set => SetProperty(ref _offset, value);
+ }
+
+ private bool _is50Ohm;
+ /// 是否使用 50Ω 输入阻抗,false 为 1MΩ。
+ public bool Is50Ohm
+ {
+ get => _is50Ohm;
+ set => SetProperty(ref _is50Ohm, value);
+ }
+
+ private double _timeBase = 0.001;
+ /// 水平时基档位(s/div)。
+ public double TimeBase
+ {
+ get => _timeBase;
+ set => SetProperty(ref _timeBase, value);
+ }
+
+ private double _triggerLevel = 0.0;
+ /// 触发电平(V)。
+ public double TriggerLevel
+ {
+ get => _triggerLevel;
+ set => SetProperty(ref _triggerLevel, value);
+ }
+
+ private string _triggerSource = "C1";
+ /// 触发源(C1/C2/C3/C4/EX/LINE)。
+ public string TriggerSource
+ {
+ get => _triggerSource;
+ set => SetProperty(ref _triggerSource, value);
+ }
+
+ #endregion
+
+ #region 测量结果属性
+
+ private string _measuredVpp = "—";
+ public string MeasuredVpp
+ {
+ get => _measuredVpp;
+ set => SetProperty(ref _measuredVpp, value);
+ }
+
+ private string _measuredFrequency = "—";
+ public string MeasuredFrequency
+ {
+ get => _measuredFrequency;
+ set => SetProperty(ref _measuredFrequency, value);
+ }
+
+ private string _measuredRms = "—";
+ public string MeasuredRms
+ {
+ get => _measuredRms;
+ set => SetProperty(ref _measuredRms, value);
+ }
+
+ private string _responseLog = string.Empty;
+ /// 命令响应日志(最新消息在顶部)。
+ public string ResponseLog
+ {
+ get => _responseLog;
+ set => SetProperty(ref _responseLog, value);
+ }
+
+ #endregion
+
+ #region 命令
+
+ public ICommand QueryIdentityCommand { get; }
+ public ICommand ResetDeviceCommand { get; }
+ public ICommand RunCommand { get; }
+ public ICommand StopCommand { get; }
+ public ICommand SingleCommand { get; }
+ public ICommand ForceTriggerCommand { get; }
+ public ICommand SetChannelOnCommand { get; }
+ public ICommand SetChannelOffCommand { get; }
+ public ICommand SetVoltsDivCommand { get; }
+ public ICommand SetOffsetCommand { get; }
+ public ICommand SetImpedance50Command { get; }
+ public ICommand SetImpedance1MCommand { get; }
+ public ICommand SetTimeBaseCommand { get; }
+ public ICommand SetTriggerLevelCommand { get; }
+ public ICommand SetTriggerSourceCommand { get; }
+ public ICommand QueryMeasurementsCommand{ get; }
+ public ICommand QueryVppCommand { get; }
+ public ICommand QueryFrequencyCommand { get; }
+ public ICommand QueryRmsCommand { get; }
+
+ #endregion
+
+ public SDS2000X_HDViewModel(IContainerProvider containerProvider) : base(containerProvider)
+ {
+ _deviceManager = containerProvider.Resolve();
+
+ QueryIdentityCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("IDN: " + await _device!.查询设备标识(Ct()))));
+ ResetDeviceCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.重置设备(Ct()); AppendLog("设备已重置"); }));
+ RunCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.启动捕获_RUN(Ct()); AppendLog("已开始捕获"); }));
+ StopCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.停止捕获_STOP(Ct()); AppendLog("已停止捕获"); }));
+ SingleCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.单次触发_SINGLE(Ct()); AppendLog("已触发单次捕获"); }));
+ ForceTriggerCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.强制触发(Ct()); AppendLog("已强制触发"); }));
+ SetChannelOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置通道开关(Channel, true, Ct()); AppendLog($"通道 {Channel} 已开启"); }));
+ SetChannelOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置通道开关(Channel, false, Ct()); AppendLog($"通道 {Channel} 已关闭"); }));
+ SetVoltsDivCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置通道电压档位(Channel, VoltsPerDiv, Ct()); AppendLog($"C{Channel} 电压档位已设为 {VoltsPerDiv} V/div"); }));
+ SetOffsetCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置通道垂直偏移(Channel, Offset, Ct()); AppendLog($"C{Channel} 垂直偏移已设为 {Offset} V"); }));
+ SetImpedance50Command = new DelegateCommand(async () => await Exec(async () => { await _device!.设置通道输入阻抗(Channel, true, Ct()); AppendLog($"C{Channel} 输入阻抗已设为 50Ω"); }));
+ SetImpedance1MCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置通道输入阻抗(Channel, false, Ct()); AppendLog($"C{Channel} 输入阻抗已设为 1MΩ"); }));
+ SetTimeBaseCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置水平时基(TimeBase, Ct()); AppendLog($"水平时基已设为 {TimeBase} s/div"); }));
+ SetTriggerLevelCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置触发电平(TriggerLevel, Ct()); AppendLog($"触发电平已设为 {TriggerLevel} V"); }));
+ SetTriggerSourceCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置触发源(TriggerSource, Ct()); AppendLog($"触发源已设为 {TriggerSource}"); }));
+
+ QueryMeasurementsCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ MeasuredVpp = await _device!.查询实际电压峰峰值(Channel, Ct());
+ MeasuredFrequency = await _device!.查询实际频率(Channel, Ct());
+ MeasuredRms = await _device!.查询实际电压均方根(Channel, Ct());
+ AppendLog($"C{Channel} 测量 → Vpp:{MeasuredVpp} Freq:{MeasuredFrequency}Hz RMS:{MeasuredRms}V");
+ }));
+
+ QueryVppCommand = new DelegateCommand(async () => await Exec(async () => { MeasuredVpp = await _device!.查询实际电压峰峰值(Channel, Ct()); AppendLog($"C{Channel} Vpp: {MeasuredVpp}"); }));
+ QueryFrequencyCommand = new DelegateCommand(async () => await Exec(async () => { MeasuredFrequency = await _device!.查询实际频率(Channel, Ct()); AppendLog($"C{Channel} Freq: {MeasuredFrequency}"); }));
+ QueryRmsCommand = new DelegateCommand(async () => await Exec(async () => { MeasuredRms = await _device!.查询实际电压均方根(Channel, Ct()); AppendLog($"C{Channel} RMS: {MeasuredRms}"); }));
+
+ Initialize();
+ }
+
+ #region 初始化 / Navigation
+
+ public void Initialize(string? deviceName = null)
+ {
+ SDS2000X_HD? found = null;
+ string? foundName = null;
+
+ if (deviceName != null &&
+ _deviceManager.DeviceMap.TryGetValue(deviceName, out var d) &&
+ d is SDS2000X_HD s)
+ {
+ found = s;
+ foundName = deviceName;
+ }
+ else
+ {
+ foreach (var kv in _deviceManager.DeviceMap)
+ {
+ if (kv.Value is SDS2000X_HD sds)
+ {
+ found = sds;
+ foundName = kv.Key;
+ break;
+ }
+ }
+ }
+
+ _device = found;
+ DeviceName = foundName ?? "SDS2000X_HD (未找到)";
+ IsConnected = _device?.IsConnected ?? false;
+
+ AppendLog(found != null
+ ? $"已关联设备 [{DeviceName}],连接状态:{(IsConnected ? "已连接" : "未连接")}"
+ : "未在 DeviceManager 中找到 SDS2000X_HD 设备,请先初始化设备配置。");
+ }
+
+ public override void OnNavigatedTo(NavigationContext context)
+ {
+ var name = context.Parameters.GetValue("DeviceName");
+ Initialize(name);
+ }
+
+ #endregion
+
+ #region 辅助
+
+ private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
+
+ private async Task Exec(Func action)
+ {
+ if (_device == null)
+ {
+ AppendLog("错误:未关联到设备实例,请检查设备配置。");
+ return;
+ }
+ if (IsBusy) return;
+ IsBusy = true;
+ try
+ {
+ await action();
+ IsConnected = _device.IsConnected;
+ }
+ catch (OperationCanceledException)
+ {
+ AppendLog("命令超时或已取消。");
+ }
+ catch (Exception ex)
+ {
+ AppendLog($"错误:{ex.Message}");
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ private void AppendLog(string message)
+ {
+ var line = $"[{DateTime.Now:HH:mm:ss}] {message}";
+ ResponseLog = ResponseLog.Length > 4000
+ ? line + "\n" + ResponseLog[..3000]
+ : line + "\n" + ResponseLog;
+ }
+
+ #endregion
+
+ public void Dispose()
+ {
+ _cts?.Cancel();
+ _cts?.Dispose();
+ }
+ }
+}
diff --git a/DeviceEditModule/ViewModels/SPAW7000ViewModel.cs b/DeviceEditModule/ViewModels/SPAW7000ViewModel.cs
new file mode 100644
index 0000000..b22ebfa
--- /dev/null
+++ b/DeviceEditModule/ViewModels/SPAW7000ViewModel.cs
@@ -0,0 +1,303 @@
+using DeviceCommand.Device;
+using Prism.Commands;
+using Prism.Ioc;
+using System;
+using System.Threading;
+using System.Windows.Input;
+using UIShare.GlobalVariable;
+using UIShare.ViewModelBase;
+
+namespace DeviceEditModule.ViewModels
+{
+ ///
+ /// SPAW7000 功率分析记录仪控制面板 ViewModel。
+ ///
+ public class SPAW7000ViewModel : NavigateViewModelBase, IDisposable
+ {
+ #region 私有字段
+
+ private readonly DeviceManager _deviceManager;
+ private SPAW7000? _device;
+ private CancellationTokenSource? _cts;
+
+ #endregion
+
+ #region 设备信息属性
+
+ private string _deviceName = "SPAW7000";
+ public string DeviceName
+ {
+ get => _deviceName;
+ set => SetProperty(ref _deviceName, value);
+ }
+
+ private bool _isConnected;
+ public bool IsConnected
+ {
+ get => _isConnected;
+ set => SetProperty(ref _isConnected, value);
+ }
+
+ private bool _isBusy;
+ public bool IsBusy
+ {
+ get => _isBusy;
+ set => SetProperty(ref _isBusy, value);
+ }
+
+ #endregion
+
+ #region 输入参数属性
+
+ private int _channel = 1;
+ /// 当前操作通道。
+ public int Channel
+ {
+ get => _channel;
+ set => SetProperty(ref _channel, value);
+ }
+
+ private double _voltageRange = 300.0;
+ /// 电压量程(V)。
+ public double VoltageRange
+ {
+ get => _voltageRange;
+ set => SetProperty(ref _voltageRange, value);
+ }
+
+ private double _currentRange = 5.0;
+ /// 电流量程(A)。
+ public double CurrentRange
+ {
+ get => _currentRange;
+ set => SetProperty(ref _currentRange, value);
+ }
+
+ private string _couplingMode = "DC";
+ /// 耦合模式:AC / DC / ACDC。
+ public string CouplingMode
+ {
+ get => _couplingMode;
+ set => SetProperty(ref _couplingMode, value);
+ }
+
+ private int _resolution = 6;
+ /// 显示分辨率(5 或 6)。
+ public int Resolution
+ {
+ get => _resolution;
+ set => SetProperty(ref _resolution, value);
+ }
+
+ private int _brightness = 5;
+ /// 屏幕亮度(1~10)。
+ public int Brightness
+ {
+ get => _brightness;
+ set => SetProperty(ref _brightness, value);
+ }
+
+ #endregion
+
+ #region 测量结果属性
+
+ private string _measuredVoltage = "—";
+ public string MeasuredVoltage
+ {
+ get => _measuredVoltage;
+ set => SetProperty(ref _measuredVoltage, value);
+ }
+
+ private string _measuredCurrent = "—";
+ public string MeasuredCurrent
+ {
+ get => _measuredCurrent;
+ set => SetProperty(ref _measuredCurrent, value);
+ }
+
+ private string _measuredPower = "—";
+ public string MeasuredPower
+ {
+ get => _measuredPower;
+ set => SetProperty(ref _measuredPower, value);
+ }
+
+ private string _measuredFrequency = "—";
+ public string MeasuredFrequency
+ {
+ get => _measuredFrequency;
+ set => SetProperty(ref _measuredFrequency, value);
+ }
+
+ private string _measuredPowerFactor = "—";
+ public string MeasuredPowerFactor
+ {
+ get => _measuredPowerFactor;
+ set => SetProperty(ref _measuredPowerFactor, value);
+ }
+
+ private string _deviceModel = "—";
+ public string DeviceModel
+ {
+ get => _deviceModel;
+ set => SetProperty(ref _deviceModel, value);
+ }
+
+ private string _deviceSerial = "—";
+ public string DeviceSerial
+ {
+ get => _deviceSerial;
+ set => SetProperty(ref _deviceSerial, value);
+ }
+
+ private string _responseLog = string.Empty;
+ /// 命令响应日志(最新消息在顶部)。
+ public string ResponseLog
+ {
+ get => _responseLog;
+ set => SetProperty(ref _responseLog, value);
+ }
+
+ #endregion
+
+ #region 命令
+
+ public ICommand QueryIdentityCommand { get; }
+ public ICommand ResetDeviceCommand { get; }
+ public ICommand QueryAllMeasureCommand { get; }
+ public ICommand SetVoltageRangeCommand { get; }
+ public ICommand SetCurrentRangeCommand { get; }
+ public ICommand SetCouplingModeCommand { get; }
+ public ICommand SetResolutionCommand { get; }
+ public ICommand SetBrightnessCommand { get; }
+ public ICommand SetTouchLockOnCommand { get; }
+ public ICommand SetTouchLockOffCommand { get; }
+ public ICommand QueryModelCommand { get; }
+ public ICommand QuerySerialCommand { get; }
+ public ICommand QueryStatusByteCommand { get; }
+
+ #endregion
+
+ public SPAW7000ViewModel(IContainerProvider containerProvider) : base(containerProvider)
+ {
+ _deviceManager = containerProvider.Resolve();
+
+ QueryIdentityCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("IDN: " + await _device!.查询设备标识(Ct()))));
+ ResetDeviceCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.重置设备(Ct()); AppendLog("设备已重置"); }));
+ SetVoltageRangeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电压量程(Channel, VoltageRange, Ct()); AppendLog($"通道 {Channel} 电压量程已设为 {VoltageRange} V"); }));
+ SetCurrentRangeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电流量程(Channel, CurrentRange, Ct()); AppendLog($"通道 {Channel} 电流量程已设为 {CurrentRange} A"); }));
+ SetCouplingModeCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置通道耦合模式(Channel, CouplingMode, Ct()); AppendLog($"通道 {Channel} 耦合模式已设为 {CouplingMode}"); }));
+ SetResolutionCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置显示分辨率(Resolution, Ct()); AppendLog($"显示分辨率已设为 {Resolution} 位"); }));
+ SetBrightnessCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置显示亮度(Brightness, Ct()); AppendLog($"屏幕亮度已设为 {Brightness}"); }));
+ SetTouchLockOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置屏幕触摸锁定(true, Ct()); AppendLog("屏幕触摸已锁定"); }));
+ SetTouchLockOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置屏幕触摸锁定(false, Ct()); AppendLog("屏幕触摸已解锁"); }));
+ QueryModelCommand = new DelegateCommand(async () => await Exec(async () => { DeviceModel = await _device!.查询设备型号(Ct()); AppendLog($"型号: {DeviceModel}"); }));
+ QuerySerialCommand = new DelegateCommand(async () => await Exec(async () => { DeviceSerial = await _device!.查询设备序列号(Ct()); AppendLog($"序列号: {DeviceSerial}"); }));
+ QueryStatusByteCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("STB: " + await _device!.读取状态字节(Ct()))));
+
+ QueryAllMeasureCommand = new DelegateCommand(async () => await Exec(async () =>
+ {
+ MeasuredVoltage = await _device!.查询实际电压(Channel, Ct());
+ MeasuredCurrent = await _device!.查询实际电流(Channel, Ct());
+ MeasuredPower = await _device!.查询实际功率(Channel, Ct());
+ MeasuredFrequency = await _device!.查询频率(Channel, Ct());
+ MeasuredPowerFactor = await _device!.查询功率因数(Channel, Ct());
+ AppendLog($"CH{Channel} 测量 → U:{MeasuredVoltage}V I:{MeasuredCurrent}A P:{MeasuredPower}W F:{MeasuredFrequency}Hz PF:{MeasuredPowerFactor}");
+ }));
+
+ Initialize();
+ }
+
+ #region 初始化 / Navigation
+
+ public void Initialize(string? deviceName = null)
+ {
+ SPAW7000? found = null;
+ string? foundName = null;
+
+ if (deviceName != null &&
+ _deviceManager.DeviceMap.TryGetValue(deviceName, out var d) &&
+ d is SPAW7000 s)
+ {
+ found = s;
+ foundName = deviceName;
+ }
+ else
+ {
+ foreach (var kv in _deviceManager.DeviceMap)
+ {
+ if (kv.Value is SPAW7000 spaw)
+ {
+ found = spaw;
+ foundName = kv.Key;
+ break;
+ }
+ }
+ }
+
+ _device = found;
+ DeviceName = foundName ?? "SPAW7000 (未找到)";
+ IsConnected = _device?.IsConnected ?? false;
+
+ AppendLog(found != null
+ ? $"已关联设备 [{DeviceName}],连接状态:{(IsConnected ? "已连接" : "未连接")}"
+ : "未在 DeviceManager 中找到 SPAW7000 设备,请先初始化设备配置。");
+ }
+
+ public override void OnNavigatedTo(NavigationContext context)
+ {
+ var name = context.Parameters.GetValue("DeviceName");
+ Initialize(name);
+ }
+
+ #endregion
+
+ #region 辅助
+
+ private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
+
+ private async Task Exec(Func action)
+ {
+ if (_device == null)
+ {
+ AppendLog("错误:未关联到设备实例,请检查设备配置。");
+ return;
+ }
+ if (IsBusy) return;
+ IsBusy = true;
+ try
+ {
+ await action();
+ IsConnected = _device.IsConnected;
+ }
+ catch (OperationCanceledException)
+ {
+ AppendLog("命令超时或已取消。");
+ }
+ catch (Exception ex)
+ {
+ AppendLog($"错误:{ex.Message}");
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ private void AppendLog(string message)
+ {
+ var line = $"[{DateTime.Now:HH:mm:ss}] {message}";
+ ResponseLog = ResponseLog.Length > 4000
+ ? line + "\n" + ResponseLog[..3000]
+ : line + "\n" + ResponseLog;
+ }
+
+ #endregion
+
+ public void Dispose()
+ {
+ _cts?.Cancel();
+ _cts?.Dispose();
+ }
+ }
+}
diff --git a/DeviceEditModule/Views/DialogMangerView.xaml b/DeviceEditModule/Views/DialogMangerView.xaml
new file mode 100644
index 0000000..82a7beb
--- /dev/null
+++ b/DeviceEditModule/Views/DialogMangerView.xaml
@@ -0,0 +1,284 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DeviceEditModule/Views/DialogMangerView.xaml.cs b/DeviceEditModule/Views/DialogMangerView.xaml.cs
new file mode 100644
index 0000000..9fefd47
--- /dev/null
+++ b/DeviceEditModule/Views/DialogMangerView.xaml.cs
@@ -0,0 +1,81 @@
+using DeviceEditModule.ViewModels;
+using System.Runtime.InteropServices;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Interop;
+
+namespace DeviceEditModule.Views
+{
+ ///
+ /// DialogMangerView 代码后置。
+ /// 负责处理与 Window 相关的操作(最小化),ViewModel 通过事件通知,
+ /// 此处执行 P/Invoke,绕过 WPF 在 AllowsTransparency=True 时禁止
+ /// 直接设置 WindowState.Minimized 的限制。
+ ///
+ public partial class DialogMangerView : UserControl
+ {
+ #region P/Invoke
+
+ [DllImport("user32.dll")]
+ private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
+
+ /// SW_MINIMIZE:最小化到任务栏。
+ private const int SW_MINIMIZE = 6;
+ /// SW_RESTORE:激活并显示窗口。如果窗口最小化或最大化,系统会将其还原到原始大小和位置。
+ private const int SW_RESTORE = 9;
+ #endregion
+
+ public DialogMangerView()
+ {
+ InitializeComponent();
+
+ // 在 Loaded 后订阅 ViewModel 的最小化请求事件
+ Loaded += (_, _) =>
+ {
+ if (DataContext is DialogMangerViewModel vm)
+ {
+ vm.MinimizeRequested += OnMinimizeRequested;
+ vm.RestoreRequested += OnRestoreRequested;
+ }
+
+ };
+
+ // 在 Unloaded 时取消订阅,防止内存泄漏
+ Unloaded += (_, _) =>
+ {
+ if (DataContext is DialogMangerViewModel vm)
+ {
+ vm.MinimizeRequested -= OnMinimizeRequested;
+ vm.RestoreRequested -= OnRestoreRequested;
+ }
+
+ };
+ }
+ private void OnRestoreRequested(object? sender, EventArgs e)
+ {
+ var window = Window.GetWindow(this);
+ if (window == null) return;
+
+ var hwnd = new WindowInteropHelper(window).EnsureHandle();
+
+ // 使用 Win32 API 强行恢复窗口,绕过 WPF 的 AllowsTransparency 限制
+ ShowWindow(hwnd, SW_RESTORE);
+ }
+ private void OnMinimizeRequested(object? sender, System.EventArgs e)
+ {
+ var window = Window.GetWindow(this);
+ if (window == null) return;
+
+ var hwnd = new WindowInteropHelper(window).EnsureHandle();
+ ShowWindow(hwnd, SW_MINIMIZE);
+ }
+
+ /// 标题栏拖拽移动窗口。
+ private void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ if (e.LeftButton == MouseButtonState.Pressed)
+ Window.GetWindow(this)?.DragMove();
+ }
+ }
+}
diff --git a/DeviceEditModule/Views/IT7800EView.xaml b/DeviceEditModule/Views/IT7800EView.xaml
new file mode 100644
index 0000000..1efdd70
--- /dev/null
+++ b/DeviceEditModule/Views/IT7800EView.xaml
@@ -0,0 +1,274 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DeviceEditModule/Views/IT7800EView.xaml.cs b/DeviceEditModule/Views/IT7800EView.xaml.cs
new file mode 100644
index 0000000..2569458
--- /dev/null
+++ b/DeviceEditModule/Views/IT7800EView.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace DeviceEditModule.Views
+{
+ ///
+ /// IT7800EView.xaml 的交互逻辑
+ ///
+ public partial class IT7800EView : UserControl
+ {
+ public IT7800EView()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/DeviceEditModule/Views/N36200View.xaml b/DeviceEditModule/Views/N36200View.xaml
new file mode 100644
index 0000000..9185c2e
--- /dev/null
+++ b/DeviceEditModule/Views/N36200View.xaml
@@ -0,0 +1,264 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DeviceEditModule/Views/N36200View.xaml.cs b/DeviceEditModule/Views/N36200View.xaml.cs
new file mode 100644
index 0000000..8a5a596
--- /dev/null
+++ b/DeviceEditModule/Views/N36200View.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace DeviceEditModule.Views
+{
+ ///
+ /// N36200View.xaml 的交互逻辑
+ ///
+ public partial class N36200View : UserControl
+ {
+ public N36200View()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/DeviceEditModule/Views/N36600View.xaml b/DeviceEditModule/Views/N36600View.xaml
new file mode 100644
index 0000000..573607b
--- /dev/null
+++ b/DeviceEditModule/Views/N36600View.xaml
@@ -0,0 +1,249 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DeviceEditModule/Views/N36600View.xaml.cs b/DeviceEditModule/Views/N36600View.xaml.cs
new file mode 100644
index 0000000..c019813
--- /dev/null
+++ b/DeviceEditModule/Views/N36600View.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace DeviceEditModule.Views
+{
+ ///
+ /// N36600View.xaml 的交互逻辑
+ ///
+ public partial class N36600View : UserControl
+ {
+ public N36600View()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/DeviceEditModule/Views/N69200View.xaml b/DeviceEditModule/Views/N69200View.xaml
new file mode 100644
index 0000000..c4134e7
--- /dev/null
+++ b/DeviceEditModule/Views/N69200View.xaml
@@ -0,0 +1,262 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DeviceEditModule/Views/N69200View.xaml.cs b/DeviceEditModule/Views/N69200View.xaml.cs
new file mode 100644
index 0000000..d5e8d4c
--- /dev/null
+++ b/DeviceEditModule/Views/N69200View.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace DeviceEditModule.Views
+{
+ ///
+ /// N69200View.xaml 的交互逻辑
+ ///
+ public partial class N69200View : UserControl
+ {
+ public N69200View()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/DeviceEditModule/Views/SDS2000X_HDView.xaml b/DeviceEditModule/Views/SDS2000X_HDView.xaml
new file mode 100644
index 0000000..0201463
--- /dev/null
+++ b/DeviceEditModule/Views/SDS2000X_HDView.xaml
@@ -0,0 +1,246 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DeviceEditModule/Views/SDS2000X_HDView.xaml.cs b/DeviceEditModule/Views/SDS2000X_HDView.xaml.cs
new file mode 100644
index 0000000..b05ce49
--- /dev/null
+++ b/DeviceEditModule/Views/SDS2000X_HDView.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace DeviceEditModule.Views
+{
+ ///
+ /// SDS2000X_HDView.xaml 的交互逻辑
+ ///
+ public partial class SDS2000X_HDView : UserControl
+ {
+ public SDS2000X_HDView()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/DeviceEditModule/Views/SPAW7000View.xaml b/DeviceEditModule/Views/SPAW7000View.xaml
new file mode 100644
index 0000000..dfacee3
--- /dev/null
+++ b/DeviceEditModule/Views/SPAW7000View.xaml
@@ -0,0 +1,255 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DeviceEditModule/Views/SPAW7000View.xaml.cs b/DeviceEditModule/Views/SPAW7000View.xaml.cs
new file mode 100644
index 0000000..d4477d9
--- /dev/null
+++ b/DeviceEditModule/Views/SPAW7000View.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace DeviceEditModule.Views
+{
+ ///
+ /// SPAW7000View.xaml 的交互逻辑
+ ///
+ public partial class SPAW7000View : UserControl
+ {
+ public SPAW7000View()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/MainModule/ViewModels/AutomatedTestingViewModel.cs b/MainModule/ViewModels/AutomatedTestingViewModel.cs
index 1049d14..7b566e4 100644
--- a/MainModule/ViewModels/AutomatedTestingViewModel.cs
+++ b/MainModule/ViewModels/AutomatedTestingViewModel.cs
@@ -18,6 +18,7 @@ namespace MainModule.ViewModels
#region 私有字段
private string _testStatus;
private readonly IScopedProvider _scope;
+ private bool IsInitialized =false;
#endregion
#region 属性
@@ -119,7 +120,11 @@ namespace MainModule.ViewModels
#region 命令处理与事件
private async Task OnLoad()
{
- await _deviceManager.ConnectAllDevices();
+ if (!IsInitialized)
+ {
+ await _deviceManager.ConnectAllDevices();
+ IsInitialized = true;
+ }
}
private void OnRefresh()
diff --git a/TestingModule/ViewModels/ParametersManagerViewModel.cs b/TestingModule/ViewModels/ParametersManagerViewModel.cs
index 8350c3a..f5cf47a 100644
--- a/TestingModule/ViewModels/ParametersManagerViewModel.cs
+++ b/TestingModule/ViewModels/ParametersManagerViewModel.cs
@@ -5,6 +5,7 @@ using Logger;
using MaterialDesignThemes.Wpf;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Reflection;
using System.Windows.Input;
using System.Xml;
using UIShare.ViewModelBase;
@@ -68,6 +69,7 @@ namespace TestingModule.ViewModels
private readonly SystemConfig _systemConfig;
private readonly GlobalInfo _globalInfo;
private readonly DeviceManager _deviceManager;
+ private readonly IContainerProvider _containerProvider;
#region 命令
public ICommand ParameterAddCommand { get; set; }
public ICommand ParameterEditCommand { get; set; }
@@ -85,6 +87,7 @@ namespace TestingModule.ViewModels
_systemConfig = containerProvider.Resolve();
_deviceManager = containerProvider.Resolve();
_globalInfo = containerProvider.Resolve();
+ _containerProvider = containerProvider;
Program = _ScopedContext.Program;
ParameterAddCommand = new DelegateCommand(ParameterAdd);
ParameterEditCommand = new DelegateCommand(ParameterEdit);
@@ -105,15 +108,64 @@ namespace TestingModule.ViewModels
{
await _deviceManager.CloseDeviceAsync(SelectedDevice.DeviceName);
}
+ ///
+ /// 跟踪已打开的弹窗管理器窗口实例,避免重复打开多个 DialogMangerView 窗口。
+ ///
+ private static System.Windows.Window? _dialogWindow;
+
private void DeviceEdit()
{
if (!_globalInfo.IsAdmin) return;
- if (SelectedDevice==null)
- {
- return;
- }
+ if (SelectedDevice == null) return;
var type = SelectedDevice.DeviceType.Split('.').Last();
- _dialogService.Show(type);
+ var viewName = type + "View";
+
+ try
+ {
+ // 1. 先确保弹窗管理器窗口已打开(首次 Show,后续只追加 Tab)
+ if (_dialogWindow == null || !_dialogWindow.IsVisible)
+ {
+ _dialogService.Show("DialogMangerView");
+
+ // 找到刚刚被 DialogService 打开的窗口(按 DataContext 类型名匹配)
+ _dialogWindow = System.Windows.Application.Current.Windows
+ .OfType()
+ .FirstOrDefault(w => w.DataContext?.GetType().Name == "DialogMangerViewModel");
+ }
+
+ // 2. 从容器按注册名解析设备编辑 View
+ var view = _containerProvider.Resolve