设备编辑管理界面
This commit is contained in:
9
ADP.sln
9
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
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<ProjectReference Include="..\CAN驱动\CAN驱动.csproj" />
|
||||
<ProjectReference Include="..\Command\Command.csproj" />
|
||||
<ProjectReference Include="..\DeviceCommand\DeviceCommand.csproj" />
|
||||
<ProjectReference Include="..\DeviceEditModule\DeviceEditModule.csproj" />
|
||||
<ProjectReference Include="..\LoginModule\LoginModule.csproj" />
|
||||
<ProjectReference Include="..\MainModule\MainModule.csproj" />
|
||||
<ProjectReference Include="..\MonitorModule\MonitorModule.csproj" />
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<!--自定义style-->
|
||||
<ResourceDictionary Source="/UIShare;component/Styles/CommonStyle.xaml"></ResourceDictionary>
|
||||
<ResourceDictionary Source="/UIShare;component/Styles/WindowStyle.xaml"></ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
|
||||
@@ -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<IRegionManager>();
|
||||
_notificationManager = containerProvider.Resolve<INotificationManager>();
|
||||
_moduleManager = containerProvider.Resolve<IModuleManager>();
|
||||
|
||||
LeftDrawerOpenCommand = new DelegateCommand(LeftDrawerOpen);
|
||||
ShowDialogManagerViewCommand = new DelegateCommand(ShowDialogManagerView);
|
||||
MinimizeCommand = new DelegateCommand<Window>(MinimizeWindow);
|
||||
MaximizeCommand = new DelegateCommand<Window>(MaximizeWindow);
|
||||
CloseCommand = new DelegateCommand<Window>(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<CancelMinimizeEvent>().Publish();
|
||||
}
|
||||
private async void OnRunning()
|
||||
{
|
||||
string runningScope = _globalInfo.CurrentScope;
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
Command="{Binding NavigateCommand}"
|
||||
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
|
||||
Style="{StaticResource MaterialDesignFlatButton}"
|
||||
Margin="8" />
|
||||
Margin="8" />
|
||||
<Button Content="记录界面"
|
||||
Command="{Binding NavigateCommand}"
|
||||
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
|
||||
@@ -59,7 +59,8 @@
|
||||
Command="{Binding NavigateCommand}"
|
||||
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
|
||||
Style="{StaticResource MaterialDesignFlatButton}"
|
||||
Margin="8" />
|
||||
Margin="8" />
|
||||
|
||||
<!--<Button Content="更新界面"
|
||||
Command="{Binding NavigateCommand}"
|
||||
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
|
||||
@@ -96,7 +97,7 @@
|
||||
Foreground="White" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
|
||||
|
||||
|
||||
<!-- 工具菜单 -->
|
||||
<MenuItem Header="工具"
|
||||
@@ -159,6 +160,16 @@
|
||||
</MenuItem>
|
||||
|
||||
<!-- 蜂鸣器消音 -->
|
||||
<MenuItem Header="弹窗管理器"
|
||||
FontSize="14"
|
||||
Height="50"
|
||||
Foreground="Black"
|
||||
Command="{Binding ShowDialogManagerViewCommand}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="DialogueOutline"
|
||||
Foreground="Black" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="蜂鸣器消音"
|
||||
FontSize="14"
|
||||
Height="50"
|
||||
@@ -233,7 +244,7 @@
|
||||
Foreground="White" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
|
||||
|
||||
<MenuItem FontSize="14"
|
||||
Height="50"
|
||||
Foreground="White">
|
||||
@@ -303,21 +314,25 @@
|
||||
Identifier="Root">
|
||||
<!-- 主内容区 -->
|
||||
<Grid>
|
||||
<ContentControl prism:RegionManager.RegionName="ShellViewManager" />
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="31*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ContentControl prism:RegionManager.RegionName="ShellViewManager" Grid.ColumnSpan="2" />
|
||||
<Border x:Name="Overlay"
|
||||
Background="#40000000"
|
||||
Visibility="Collapsed"
|
||||
Panel.ZIndex="1">
|
||||
Panel.ZIndex="1" Grid.ColumnSpan="2">
|
||||
<StackPanel Width="150"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0 0 0 100">
|
||||
|
||||
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Border x:Name="Waitinglay"
|
||||
Background="#40000000"
|
||||
Visibility="Collapsed"
|
||||
Panel.ZIndex="1">
|
||||
Panel.ZIndex="1" Grid.ColumnSpan="2">
|
||||
<StackPanel Width="150"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0 0 0 100">
|
||||
|
||||
48
DeviceCommand/Devices/IOBoard.cs
Normal file
48
DeviceCommand/Devices/IOBoard.cs
Normal file
@@ -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<bool[]> 批量读输出开关(byte 站号, ushort 开始地址,ushort 数量)
|
||||
{
|
||||
return await Modbus.ReadCoilsAsync(站号, 开始地址, 数量);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace DeviceCommand.Device
|
||||
[ADPCommand]
|
||||
public class IT7800E : Tcp
|
||||
{
|
||||
//只有一个,八台产品一起用一个
|
||||
// 根据通用 SCPI 指令规范,使用换行符 (ASCII 字符 LF,即 \n) 作为标准结束符
|
||||
private const string ScpiDelimiter = "\n";
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace DeviceCommand.Device
|
||||
[ADPCommand]
|
||||
public class N36200 : Tcp
|
||||
{
|
||||
//只有一个,八台产品一起用一个
|
||||
// 手册第 9 页 2.2.4 明确规定:命令结束符为换行符 (ASCII 字符 LF,即 \n)
|
||||
private const string ScpiDelimiter = "\n";
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace DeviceCommand.Device
|
||||
[ADPCommand]
|
||||
public class SDS2000X_HD : Tcp
|
||||
{
|
||||
//只有两个,八台产品公用两两分组各用一个
|
||||
// 示波器底层 Socket 字符串命令通常以换行符 \n 结束
|
||||
private const string ScpiDelimiter = "\n";
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace DeviceCommand.Device
|
||||
[ADPCommand]
|
||||
public class SPAW7000 : Tcp
|
||||
{
|
||||
//只有两个,八台产品公用两两分组各用一个
|
||||
// 根据通用 SCPI 与远宽指令规范,使用换行符 (ASCII 字符 LF,即 \n) 作为标准结束符
|
||||
private const string ScpiDelimiter = "\n";
|
||||
|
||||
|
||||
26
DeviceEditModule/DeviceEditModule.cs
Normal file
26
DeviceEditModule/DeviceEditModule.cs
Normal file
@@ -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, DialogMangerViewModel>("DialogMangerView");
|
||||
|
||||
// 设备编辑 View 注册为 Navigation(被动态解析后作为 Tab 内容嵌入 DialogMangerView)
|
||||
containerRegistry.RegisterForNavigation<IT7800EView>("IT7800EView");
|
||||
containerRegistry.RegisterForNavigation<N36200View>("N36200View");
|
||||
containerRegistry.RegisterForNavigation<N36600View>("N36600View");
|
||||
containerRegistry.RegisterForNavigation<N69200View>("N69200View");
|
||||
containerRegistry.RegisterForNavigation<SDS2000X_HDView>("SDS2000X_HDView");
|
||||
containerRegistry.RegisterForNavigation<SPAW7000View>("SPAW7000View");
|
||||
}
|
||||
}
|
||||
}
|
||||
15
DeviceEditModule/DeviceEditModule.csproj
Normal file
15
DeviceEditModule/DeviceEditModule.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include=".\..\UIShare\UIShare.csproj" />
|
||||
<ProjectReference Include=".\..\DeviceCommand\DeviceCommand.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
149
DeviceEditModule/ViewModels/DialogMangerViewModel.cs
Normal file
149
DeviceEditModule/ViewModels/DialogMangerViewModel.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 弹窗管理器 ViewModel。
|
||||
/// <para>
|
||||
/// 职责:<br/>
|
||||
/// 1. 订阅 <see cref="AddDialogTabEvent"/>,将外部弹窗注册为 Tab;<br/>
|
||||
/// 2. 维护 <see cref="TagItems"/> 集合,控制选中/关闭逻辑;<br/>
|
||||
/// 3. 最小化:通过 <see cref="MinimizeRequested"/> 事件通知 View 执行 P/Invoke 窗口操作;<br/>
|
||||
/// 4. 关闭:调用 <see cref="RequestClose"/>。
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public class DialogMangerViewModel : DialogViewModelBase, IDisposable
|
||||
{
|
||||
#region 属性
|
||||
|
||||
/// <summary>所有 Tab 项集合,绑定到标签条的 ItemsControl。</summary>
|
||||
public ObservableCollection<DialogTabItemVM> TagItems { get; } = new();
|
||||
|
||||
/// <summary>以 Tab 标题为 key 追踪已打开的 Tab,防止重复打开。</summary>
|
||||
private readonly Dictionary<string, DialogTabItemVM> _tabDictionary = new();
|
||||
|
||||
private DialogTabItemVM? _selectedTag;
|
||||
/// <summary>当前激活的 Tab,其 Content 显示在内容区。</summary>
|
||||
public DialogTabItemVM? SelectedTag
|
||||
{
|
||||
get => _selectedTag;
|
||||
set => SetProperty(ref _selectedTag, value);
|
||||
}
|
||||
|
||||
/// <summary>是否没有任何 Tab(用于绑定空状态提示的 Visibility)。</summary>
|
||||
public bool HasNoTabs => TagItems.Count == 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
|
||||
public ICommand MinimizeCommand { get; }
|
||||
public ICommand CloseCommand { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件
|
||||
|
||||
/// <summary>
|
||||
/// View 订阅此事件后,在事件回调里执行 P/Invoke 最小化。
|
||||
/// 这样 ViewModel 无需引用任何 UI 或 Win32 类型。
|
||||
/// </summary>
|
||||
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<AddDialogTabEvent>().Subscribe(OnAddTab, ThreadOption.UIThread);
|
||||
_eventAggregator.GetEvent<CancelMinimizeEvent>().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 管理
|
||||
|
||||
/// <summary>收到事件:若 Tab 已存在则激活,否则创建并追加到集合。</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>激活(选中)指定 Tab,其余全部取消选中。</summary>
|
||||
private void OnSelectTab(DialogTabItemVM tab) => ActivateTab(tab);
|
||||
|
||||
/// <summary>关闭指定 Tab,自动选中相邻 Tab(或清空内容区)。</summary>
|
||||
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<AddDialogTabEvent>().Unsubscribe(OnAddTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
310
DeviceEditModule/ViewModels/IT7800EViewModel.cs
Normal file
310
DeviceEditModule/ViewModels/IT7800EViewModel.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// IT7800E 交直流电源控制面板 ViewModel。
|
||||
/// <para>
|
||||
/// 注册为 Navigation View,既可由 Region 导航进入,
|
||||
/// 也可由外部直接实例化后作为 Tab 内容塞入 DialogMangerView:
|
||||
/// <code>
|
||||
/// var view = container.Resolve<IT7800EView>();
|
||||
/// (view.DataContext as IT7800EViewModel)?.Initialize("IT7800E");
|
||||
/// _eventAggregator.GetEvent<AddDialogTabEvent>().Publish(
|
||||
/// new DialogTabInfo { Title = "IT7800E", Content = view });
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
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;
|
||||
/// <summary>正在执行设备命令时为 true,用于 UI 忙碌状态指示。</summary>
|
||||
public bool IsBusy
|
||||
{
|
||||
get => _isBusy;
|
||||
set => SetProperty(ref _isBusy, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 输入参数属性
|
||||
|
||||
private double _acVoltage = 220.0;
|
||||
/// <summary>待设置的交流电压值(V)。</summary>
|
||||
public double AcVoltage
|
||||
{
|
||||
get => _acVoltage;
|
||||
set => SetProperty(ref _acVoltage, value);
|
||||
}
|
||||
|
||||
private double _dcVoltage = 0.0;
|
||||
/// <summary>待设置的直流偏置电压值(V)。</summary>
|
||||
public double DcVoltage
|
||||
{
|
||||
get => _dcVoltage;
|
||||
set => SetProperty(ref _dcVoltage, value);
|
||||
}
|
||||
|
||||
private double _frequency = 50.0;
|
||||
/// <summary>待设置的交流频率(Hz)。</summary>
|
||||
public double Frequency
|
||||
{
|
||||
get => _frequency;
|
||||
set => SetProperty(ref _frequency, value);
|
||||
}
|
||||
|
||||
private double _currentLimit = 10.0;
|
||||
/// <summary>待设置的限流值(A)。</summary>
|
||||
public double CurrentLimit
|
||||
{
|
||||
get => _currentLimit;
|
||||
set => SetProperty(ref _currentLimit, value);
|
||||
}
|
||||
|
||||
private string _selectedMode = "AC";
|
||||
/// <summary>待设置的电源工作模式:AC / DC / ACDC。</summary>
|
||||
public string SelectedMode
|
||||
{
|
||||
get => _selectedMode;
|
||||
set => SetProperty(ref _selectedMode, value);
|
||||
}
|
||||
|
||||
private double _ovpValue = 260.0;
|
||||
/// <summary>过压保护值(V)。</summary>
|
||||
public double OvpValue
|
||||
{
|
||||
get => _ovpValue;
|
||||
set => SetProperty(ref _ovpValue, value);
|
||||
}
|
||||
|
||||
private double _ocpValue = 15.0;
|
||||
/// <summary>过流保护值(A)。</summary>
|
||||
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;
|
||||
/// <summary>命令响应日志(最新消息在顶部)。</summary>
|
||||
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<DeviceManager>();
|
||||
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// 从 DeviceManager 中查找 IT7800E 设备实例。
|
||||
/// 优先按 <paramref name="deviceName"/> 查找,否则取第一个匹配类型的设备。
|
||||
/// </summary>
|
||||
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<string?>("DeviceName");
|
||||
Initialize(name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
|
||||
|
||||
private async Task Exec(Func<Task> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
309
DeviceEditModule/ViewModels/N36200ViewModel.cs
Normal file
309
DeviceEditModule/ViewModels/N36200ViewModel.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// N36200 宽范围可编程直流电源控制面板 ViewModel。
|
||||
/// <para>
|
||||
/// 注册为 Navigation View,可通过 EventAggregator 添加为 DialogMangerView 中的 Tab:
|
||||
/// <code>
|
||||
/// var view = container.Resolve<N36200View>();
|
||||
/// (view.DataContext as N36200ViewModel)?.Initialize("N36200");
|
||||
/// _eventAggregator.GetEvent<AddDialogTabEvent>().Publish(
|
||||
/// new DialogTabInfo { Title = "N36200", Content = view });
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
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;
|
||||
/// <summary>待设置的输出电压值(V)。</summary>
|
||||
public double Voltage
|
||||
{
|
||||
get => _voltage;
|
||||
set => SetProperty(ref _voltage, value);
|
||||
}
|
||||
|
||||
private double _currentLimit = 5.0;
|
||||
/// <summary>待设置的限流值(A)。</summary>
|
||||
public double CurrentLimit
|
||||
{
|
||||
get => _currentLimit;
|
||||
set => SetProperty(ref _currentLimit, value);
|
||||
}
|
||||
|
||||
private string _selectedMode = "NORMal";
|
||||
/// <summary>待设置的运行模式:NORMal / CHARge / SEQuence / CPOWer / CARWave / APG。</summary>
|
||||
public string SelectedMode
|
||||
{
|
||||
get => _selectedMode;
|
||||
set => SetProperty(ref _selectedMode, value);
|
||||
}
|
||||
|
||||
private double _ovpValue = 15.0;
|
||||
/// <summary>过压保护值(V)。</summary>
|
||||
public double OvpValue
|
||||
{
|
||||
get => _ovpValue;
|
||||
set => SetProperty(ref _ovpValue, value);
|
||||
}
|
||||
|
||||
private double _ocpValue = 6.0;
|
||||
/// <summary>过流保护值(A)。</summary>
|
||||
public double OcpValue
|
||||
{
|
||||
get => _ocpValue;
|
||||
set => SetProperty(ref _ocpValue, value);
|
||||
}
|
||||
|
||||
private double _uvpValue = 0.0;
|
||||
/// <summary>欠压保护值(V)。</summary>
|
||||
public double UvpValue
|
||||
{
|
||||
get => _uvpValue;
|
||||
set => SetProperty(ref _uvpValue, value);
|
||||
}
|
||||
|
||||
private double _oppValue = 100.0;
|
||||
/// <summary>过功率保护值(W)。</summary>
|
||||
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 = "—";
|
||||
/// <summary>设备状态字(OUTPut:STATe? 查询结果)。</summary>
|
||||
public string DeviceStatus
|
||||
{
|
||||
get => _deviceStatus;
|
||||
set => SetProperty(ref _deviceStatus, value);
|
||||
}
|
||||
|
||||
private string _responseLog = string.Empty;
|
||||
/// <summary>命令响应日志(最新消息在顶部)。</summary>
|
||||
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<DeviceManager>();
|
||||
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// 从 DeviceManager 中查找 N36200 设备实例。
|
||||
/// 优先按 <paramref name="deviceName"/> 查找,否则取第一个匹配类型的设备。
|
||||
/// </summary>
|
||||
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<string?>("DeviceName");
|
||||
Initialize(name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
|
||||
|
||||
private async Task Exec(Func<Task> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
280
DeviceEditModule/ViewModels/N36600ViewModel.cs
Normal file
280
DeviceEditModule/ViewModels/N36600ViewModel.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// N36600 便携式宽范围可编程直流电源控制面板 ViewModel。
|
||||
/// </summary>
|
||||
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;
|
||||
/// <summary>待设置的输出电压值(V)。</summary>
|
||||
public double Voltage
|
||||
{
|
||||
get => _voltage;
|
||||
set => SetProperty(ref _voltage, value);
|
||||
}
|
||||
|
||||
private double _currentLimit = 5.0;
|
||||
/// <summary>待设置的输出电流值(A)。</summary>
|
||||
public double CurrentLimit
|
||||
{
|
||||
get => _currentLimit;
|
||||
set => SetProperty(ref _currentLimit, value);
|
||||
}
|
||||
|
||||
private double _power = 60.0;
|
||||
/// <summary>待设置的输出功率值(W)。</summary>
|
||||
public double Power
|
||||
{
|
||||
get => _power;
|
||||
set => SetProperty(ref _power, value);
|
||||
}
|
||||
|
||||
private double _ovpValue = 15.0;
|
||||
/// <summary>过压保护值(V)。</summary>
|
||||
public double OvpValue
|
||||
{
|
||||
get => _ovpValue;
|
||||
set => SetProperty(ref _ovpValue, value);
|
||||
}
|
||||
|
||||
private double _ocpValue = 6.0;
|
||||
/// <summary>过流保护值(A)。</summary>
|
||||
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 = "—";
|
||||
/// <summary>当前 DC 输出状态(OUTPut? 查询结果)。</summary>
|
||||
public string OutputState
|
||||
{
|
||||
get => _outputState;
|
||||
set => SetProperty(ref _outputState, value);
|
||||
}
|
||||
|
||||
private string _responseLog = string.Empty;
|
||||
/// <summary>命令响应日志(最新消息在顶部)。</summary>
|
||||
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<DeviceManager>();
|
||||
|
||||
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<string?>("DeviceName");
|
||||
Initialize(name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
|
||||
|
||||
private async Task Exec(Func<Task> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
316
DeviceEditModule/ViewModels/N69200ViewModel.cs
Normal file
316
DeviceEditModule/ViewModels/N69200ViewModel.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// N69200 可编程直流电子负载控制面板 ViewModel。
|
||||
/// </summary>
|
||||
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";
|
||||
/// <summary>工作模式:CC / CV / CP / CR。</summary>
|
||||
public string SelectedMode
|
||||
{
|
||||
get => _selectedMode;
|
||||
set => SetProperty(ref _selectedMode, value);
|
||||
}
|
||||
|
||||
private double _loadValue = 1.0;
|
||||
/// <summary>设定值(根据 SelectedMode 代表 A / V / W / Ω)。</summary>
|
||||
public double LoadValue
|
||||
{
|
||||
get => _loadValue;
|
||||
set => SetProperty(ref _loadValue, value);
|
||||
}
|
||||
|
||||
private double _ovpValue = 60.0;
|
||||
/// <summary>过压保护值(V)。</summary>
|
||||
public double OvpValue
|
||||
{
|
||||
get => _ovpValue;
|
||||
set => SetProperty(ref _ovpValue, value);
|
||||
}
|
||||
|
||||
private double _ocpValue = 10.0;
|
||||
/// <summary>过流保护值(A)。</summary>
|
||||
public double OcpValue
|
||||
{
|
||||
get => _ocpValue;
|
||||
set => SetProperty(ref _ocpValue, value);
|
||||
}
|
||||
|
||||
private double _oppValue = 200.0;
|
||||
/// <summary>过功率保护值(W)。</summary>
|
||||
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 = "—";
|
||||
/// <summary>当前负载模式(MODE? 查询结果)。</summary>
|
||||
public string CurrentMode
|
||||
{
|
||||
get => _currentMode;
|
||||
set => SetProperty(ref _currentMode, value);
|
||||
}
|
||||
|
||||
private string _statusByte = "—";
|
||||
/// <summary>状态字节(*STB? 查询结果)。</summary>
|
||||
public string StatusByte
|
||||
{
|
||||
get => _statusByte;
|
||||
set => SetProperty(ref _statusByte, value);
|
||||
}
|
||||
|
||||
private string _responseLog = string.Empty;
|
||||
/// <summary>命令响应日志(最新消息在顶部)。</summary>
|
||||
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<DeviceManager>();
|
||||
|
||||
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<string?>("DeviceName");
|
||||
Initialize(name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
|
||||
|
||||
private async Task Exec(Func<Task> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
294
DeviceEditModule/ViewModels/SDS2000X_HDViewModel.cs
Normal file
294
DeviceEditModule/ViewModels/SDS2000X_HDViewModel.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// SDS2000X_HD 数字存储示波器控制面板 ViewModel。
|
||||
/// </summary>
|
||||
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;
|
||||
/// <summary>当前操作通道(1~4)。</summary>
|
||||
public int Channel
|
||||
{
|
||||
get => _channel;
|
||||
set => SetProperty(ref _channel, value);
|
||||
}
|
||||
|
||||
private double _voltsPerDiv = 1.0;
|
||||
/// <summary>垂直电压档位(V/div)。</summary>
|
||||
public double VoltsPerDiv
|
||||
{
|
||||
get => _voltsPerDiv;
|
||||
set => SetProperty(ref _voltsPerDiv, value);
|
||||
}
|
||||
|
||||
private double _offset = 0.0;
|
||||
/// <summary>垂直偏移(V)。</summary>
|
||||
public double Offset
|
||||
{
|
||||
get => _offset;
|
||||
set => SetProperty(ref _offset, value);
|
||||
}
|
||||
|
||||
private bool _is50Ohm;
|
||||
/// <summary>是否使用 50Ω 输入阻抗,false 为 1MΩ。</summary>
|
||||
public bool Is50Ohm
|
||||
{
|
||||
get => _is50Ohm;
|
||||
set => SetProperty(ref _is50Ohm, value);
|
||||
}
|
||||
|
||||
private double _timeBase = 0.001;
|
||||
/// <summary>水平时基档位(s/div)。</summary>
|
||||
public double TimeBase
|
||||
{
|
||||
get => _timeBase;
|
||||
set => SetProperty(ref _timeBase, value);
|
||||
}
|
||||
|
||||
private double _triggerLevel = 0.0;
|
||||
/// <summary>触发电平(V)。</summary>
|
||||
public double TriggerLevel
|
||||
{
|
||||
get => _triggerLevel;
|
||||
set => SetProperty(ref _triggerLevel, value);
|
||||
}
|
||||
|
||||
private string _triggerSource = "C1";
|
||||
/// <summary>触发源(C1/C2/C3/C4/EX/LINE)。</summary>
|
||||
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;
|
||||
/// <summary>命令响应日志(最新消息在顶部)。</summary>
|
||||
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<DeviceManager>();
|
||||
|
||||
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<string?>("DeviceName");
|
||||
Initialize(name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
|
||||
|
||||
private async Task Exec(Func<Task> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
303
DeviceEditModule/ViewModels/SPAW7000ViewModel.cs
Normal file
303
DeviceEditModule/ViewModels/SPAW7000ViewModel.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// SPAW7000 功率分析记录仪控制面板 ViewModel。
|
||||
/// </summary>
|
||||
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;
|
||||
/// <summary>当前操作通道。</summary>
|
||||
public int Channel
|
||||
{
|
||||
get => _channel;
|
||||
set => SetProperty(ref _channel, value);
|
||||
}
|
||||
|
||||
private double _voltageRange = 300.0;
|
||||
/// <summary>电压量程(V)。</summary>
|
||||
public double VoltageRange
|
||||
{
|
||||
get => _voltageRange;
|
||||
set => SetProperty(ref _voltageRange, value);
|
||||
}
|
||||
|
||||
private double _currentRange = 5.0;
|
||||
/// <summary>电流量程(A)。</summary>
|
||||
public double CurrentRange
|
||||
{
|
||||
get => _currentRange;
|
||||
set => SetProperty(ref _currentRange, value);
|
||||
}
|
||||
|
||||
private string _couplingMode = "DC";
|
||||
/// <summary>耦合模式:AC / DC / ACDC。</summary>
|
||||
public string CouplingMode
|
||||
{
|
||||
get => _couplingMode;
|
||||
set => SetProperty(ref _couplingMode, value);
|
||||
}
|
||||
|
||||
private int _resolution = 6;
|
||||
/// <summary>显示分辨率(5 或 6)。</summary>
|
||||
public int Resolution
|
||||
{
|
||||
get => _resolution;
|
||||
set => SetProperty(ref _resolution, value);
|
||||
}
|
||||
|
||||
private int _brightness = 5;
|
||||
/// <summary>屏幕亮度(1~10)。</summary>
|
||||
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;
|
||||
/// <summary>命令响应日志(最新消息在顶部)。</summary>
|
||||
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<DeviceManager>();
|
||||
|
||||
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<string?>("DeviceName");
|
||||
Initialize(name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
private CancellationToken Ct() => (_cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))).Token;
|
||||
|
||||
private async Task Exec(Func<Task> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
284
DeviceEditModule/Views/DialogMangerView.xaml
Normal file
284
DeviceEditModule/Views/DialogMangerView.xaml
Normal file
@@ -0,0 +1,284 @@
|
||||
<UserControl x:Class="DeviceEditModule.Views.DialogMangerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
Height="850" Width="900">
|
||||
|
||||
<!-- 此窗口独立开启 ShowInTaskbar,以支持最小化后在任务栏恢复 -->
|
||||
<prism:Dialog.WindowStyle>
|
||||
<Style TargetType="Window">
|
||||
<Setter Property="WindowStyle" Value="None"/>
|
||||
<Setter Property="ResizeMode" Value="NoResize"/>
|
||||
<Setter Property="ShowInTaskbar" Value="True"/>
|
||||
<Setter Property="AllowsTransparency" Value="True"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="SizeToContent" Value="WidthAndHeight"/>
|
||||
</Style>
|
||||
</prism:Dialog.WindowStyle>
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVis"/>
|
||||
|
||||
<!-- ── 窗口拖拽阴影外框 ── -->
|
||||
<DropShadowEffect x:Key="WindowShadow"
|
||||
Color="#66000000"
|
||||
BlurRadius="16"
|
||||
ShadowDepth="4"
|
||||
Direction="315"/>
|
||||
|
||||
<!-- ── Tab 项:未选中样式 ── -->
|
||||
<Style x:Key="TabItemStyle" TargetType="Border">
|
||||
<Setter Property="Background" Value="#F0F0F0"/>
|
||||
<Setter Property="BorderBrush" Value="#BDBDBD"/>
|
||||
<Setter Property="BorderThickness" Value="1,1,1,0"/>
|
||||
<Setter Property="CornerRadius" Value="6,6,0,0"/>
|
||||
<Setter Property="Margin" Value="2,5,0,0"/>
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsSelected}" Value="True">
|
||||
<Setter Property="Background" Value="White"/>
|
||||
<Setter Property="BorderBrush" Value="#1976D2"/>
|
||||
<Setter Property="BorderThickness" Value="1,2,1,0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<!-- ── 标题栏按钮 ── -->
|
||||
<Style x:Key="TitleBarButtonStyle" TargetType="Button">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="Width" Value="36"/>
|
||||
<Setter Property="Height" Value="28"/>
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border x:Name="bg"
|
||||
Background="{TemplateBinding Background}"
|
||||
CornerRadius="4">
|
||||
<ContentPresenter HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="bg" Property="Background" Value="#33FFFFFF"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter TargetName="bg" Property="Background" Value="#55FFFFFF"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- ── Tab 关闭按钮(小号,无边框) ── -->
|
||||
<Style x:Key="TabCloseButtonStyle" TargetType="Button">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
<Setter Property="Foreground" Value="#757575"/>
|
||||
<Setter Property="FontSize" Value="12"/>
|
||||
<Setter Property="Width" Value="18"/>
|
||||
<Setter Property="Height" Value="18"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border x:Name="bg"
|
||||
Background="{TemplateBinding Background}"
|
||||
CornerRadius="9">
|
||||
<ContentPresenter HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="bg" Property="Background" Value="#FFD32F2F"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<!-- 最外层:透明底 + 阴影 + 圆角 -->
|
||||
<Border CornerRadius="10"
|
||||
Background="White"
|
||||
Effect="{StaticResource WindowShadow}"
|
||||
Margin="8">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<!-- 标题栏 -->
|
||||
<RowDefinition Height="38"/>
|
||||
<!-- Tab 标签条 -->
|
||||
<RowDefinition Height="40"/>
|
||||
<!-- 内容区 -->
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border Grid.Row="0"
|
||||
CornerRadius="10,10,0,0"
|
||||
Background="#1565C0"
|
||||
MouseLeftButtonDown="MouseLeftButtonDown">
|
||||
<Grid Margin="12,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- 图标 + 标题 -->
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<materialDesign:PackIcon Kind="WindowRestore"
|
||||
Foreground="White"
|
||||
Width="18" Height="18"
|
||||
Margin="0,0,6,0"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="弹窗管理器"
|
||||
Foreground="White"
|
||||
FontSize="13"
|
||||
FontWeight="Medium"
|
||||
VerticalAlignment="Center"/>
|
||||
<!-- Tab 数量徽标 -->
|
||||
<Border Background="#33FFFFFF"
|
||||
CornerRadius="10"
|
||||
Padding="6,1"
|
||||
Margin="8,0,0,0"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock Foreground="White"
|
||||
FontSize="11">
|
||||
<TextBlock.Text>
|
||||
<Binding Path="TagItems.Count"
|
||||
StringFormat="{}{0} 个窗口"/>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 最小化按钮 -->
|
||||
<Button Grid.Column="1"
|
||||
Content="—"
|
||||
ToolTip="最小化"
|
||||
Command="{Binding MinimizeCommand}"
|
||||
Style="{StaticResource TitleBarButtonStyle}"
|
||||
Margin="0,0,2,0"/>
|
||||
|
||||
<!-- 关闭按钮 -->
|
||||
<Button Grid.Column="2"
|
||||
Content="✕"
|
||||
ToolTip="关闭"
|
||||
Command="{Binding CloseCommand}"
|
||||
Style="{StaticResource TitleBarButtonStyle}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border Grid.Row="1"
|
||||
Background="#FAFAFA"
|
||||
BorderBrush="#E0E0E0"
|
||||
BorderThickness="0,0,0,1">
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Auto"
|
||||
VerticalScrollBarVisibility="Hidden"
|
||||
Padding="4,0,4,0">
|
||||
<ItemsControl ItemsSource="{Binding TagItems}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<!-- 单个 Tab -->
|
||||
<Border Style="{StaticResource TabItemStyle}">
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="8,4,4,4"
|
||||
VerticalAlignment="Center">
|
||||
<!-- Tab 标题(点击激活) -->
|
||||
<Button Command="{Binding SelectCommand}"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
Cursor="Hand"
|
||||
Padding="0"
|
||||
MaxWidth="130">
|
||||
<Button.Template>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<ContentPresenter/>
|
||||
</ControlTemplate>
|
||||
</Button.Template>
|
||||
<TextBlock Text="{Binding Title}"
|
||||
FontSize="12"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
ToolTip="{Binding Title}"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="#616161"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsSelected}" Value="True">
|
||||
<Setter Property="Foreground" Value="#1565C0"/>
|
||||
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Button>
|
||||
<!-- 关闭按钮 -->
|
||||
<Button Command="{Binding CloseCommand}"
|
||||
Content="✕"
|
||||
Style="{StaticResource TabCloseButtonStyle}"
|
||||
Margin="4,0,0,0"
|
||||
ToolTip="关闭此窗口"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Row="2">
|
||||
|
||||
<!-- 空状态提示 -->
|
||||
<StackPanel HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="{Binding HasNoTabs, Converter={StaticResource BoolToVis}}">
|
||||
<materialDesign:PackIcon Kind="InboxOutline"
|
||||
Width="64" Height="64"
|
||||
Foreground="#BDBDBD"
|
||||
HorizontalAlignment="Center"/>
|
||||
<TextBlock Text="暂无打开的弹窗"
|
||||
Foreground="#9E9E9E"
|
||||
FontSize="14"
|
||||
Margin="0,8,0,0"
|
||||
HorizontalAlignment="Center"/>
|
||||
<TextBlock Text="其他窗口最小化后将在此处显示为标签页"
|
||||
Foreground="#BDBDBD"
|
||||
FontSize="11"
|
||||
Margin="0,4,0,0"
|
||||
HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 选中 Tab 的内容 -->
|
||||
<ContentControl Content="{Binding SelectedTag.Content}"
|
||||
Visibility="{Binding HasNoTabs,
|
||||
Converter={StaticResource BoolToVis},
|
||||
ConverterParameter=Invert}"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
VerticalContentAlignment="Stretch"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
81
DeviceEditModule/Views/DialogMangerView.xaml.cs
Normal file
81
DeviceEditModule/Views/DialogMangerView.xaml.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// DialogMangerView 代码后置。
|
||||
/// 负责处理与 Window 相关的操作(最小化),ViewModel 通过事件通知,
|
||||
/// 此处执行 P/Invoke,绕过 WPF 在 AllowsTransparency=True 时禁止
|
||||
/// 直接设置 WindowState.Minimized 的限制。
|
||||
/// </summary>
|
||||
public partial class DialogMangerView : UserControl
|
||||
{
|
||||
#region P/Invoke
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
||||
|
||||
/// <summary>SW_MINIMIZE:最小化到任务栏。</summary>
|
||||
private const int SW_MINIMIZE = 6;
|
||||
/// <summary>SW_RESTORE:激活并显示窗口。如果窗口最小化或最大化,系统会将其还原到原始大小和位置。</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>标题栏拖拽移动窗口。</summary>
|
||||
private void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
Window.GetWindow(this)?.DragMove();
|
||||
}
|
||||
}
|
||||
}
|
||||
274
DeviceEditModule/Views/IT7800EView.xaml
Normal file
274
DeviceEditModule/Views/IT7800EView.xaml
Normal file
@@ -0,0 +1,274 @@
|
||||
<UserControl x:Class="DeviceEditModule.Views.IT7800EView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
d:DesignHeight="760" d:DesignWidth="860">
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVis"/>
|
||||
|
||||
|
||||
</UserControl.Resources>
|
||||
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel Margin="12">
|
||||
|
||||
<!-- ═══ 设备信息头 ═══ -->
|
||||
<materialDesign:Card Margin="0,0,0,8" Padding="12,8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<materialDesign:PackIcon Kind="Flash" Width="22" Height="22"
|
||||
Foreground="#1565C0" Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="IT7800E 交直流可编程电源"
|
||||
FontSize="15" FontWeight="Bold"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="{Binding DeviceName, StringFormat=' [{0}]'}"
|
||||
FontSize="13" Foreground="#757575"
|
||||
VerticalAlignment="Center" Margin="4,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 连接状态指示 -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Width="10" Height="10" CornerRadius="5" Margin="0,0,6,0">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Background" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock VerticalAlignment="Center" FontSize="12">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="未连接"/>
|
||||
<Setter Property="Foreground" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Text" Value="已连接"/>
|
||||
<Setter Property="Foreground" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<!-- 忙碌指示 -->
|
||||
<ProgressBar IsIndeterminate="True" Width="80" Height="4"
|
||||
Margin="12,0,0,0"
|
||||
Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
|
||||
<!-- ═══ 主体 2 列 ═══ -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- ─── 左列 ─── -->
|
||||
<StackPanel Grid.Column="0" Margin="0,0,4,0">
|
||||
|
||||
<!-- 输出控制 -->
|
||||
<GroupBox Header="输出控制" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<!-- 开关输出 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="主输出" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="开启输出" Command="{Binding OutputOnCommand}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
Background="#388E3C" Foreground="White"
|
||||
Height="32" Padding="12,0" FontSize="12" Margin="4,0"/>
|
||||
<Button Content="关闭输出" Command="{Binding OutputOffCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 工作模式 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="工作模式" Style="{StaticResource ParamLabel}"/>
|
||||
<ComboBox Width="90" Height="32" Margin="4,0"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
SelectedItem="{Binding SelectedMode}"
|
||||
VerticalContentAlignment="Center" FontSize="12">
|
||||
<ComboBoxItem Content="AC"/>
|
||||
<ComboBoxItem Content="DC"/>
|
||||
<ComboBoxItem Content="ACDC"/>
|
||||
</ComboBox>
|
||||
<Button Content="设置模式" Command="{Binding SetModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 远程/本地 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="控制模式" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="远程控制" Command="{Binding SetRemoteModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="本地控制" Command="{Binding SetLocalModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 清除 / 重置 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="系统操作" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="清除告警" Command="{Binding ClearAlarmCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
<Button Content="清除错误" Command="{Binding ClearErrorCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
<Button Content="重置设备" Command="{Binding ResetDeviceCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 参数设置 -->
|
||||
<GroupBox Header="参数设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<!-- AC 电压 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="AC电压 (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding AcVoltage, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetAcVoltageCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- DC 偏置 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="DC偏置 (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding DcVoltage, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetDcVoltageCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 频率 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="频率 (Hz)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding Frequency, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetFrequencyCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 限流 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="限流 (A)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding CurrentLimit, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetCurrentCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 保护设置 -->
|
||||
<GroupBox Header="保护设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OVP (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OvpValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OVP" Command="{Binding SetOvpCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OCP (A)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OcpValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OCP" Command="{Binding SetOcpCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ─── 右列 ─── -->
|
||||
<StackPanel Grid.Column="1" Margin="4,0,0,0">
|
||||
|
||||
<!-- 实时测量 -->
|
||||
<GroupBox Header="实时测量" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际电压" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredVoltage, Mode=OneWay}"/>
|
||||
<TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际电流" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredCurrent, Mode=OneWay}"/>
|
||||
<TextBlock Text="A" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际功率" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredPower, Mode=OneWay}"/>
|
||||
<TextBlock Text="W" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="输出频率" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredFrequency, Mode=OneWay}"/>
|
||||
<TextBlock Text="Hz" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<Button Content="刷新全部测量" Command="{Binding QueryAllMeasureCommand}"
|
||||
Style="{StaticResource CmdBtn}"
|
||||
HorizontalAlignment="Left" Margin="0,4,0,0"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 设备信息 -->
|
||||
<GroupBox Header="设备信息" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Orientation="Horizontal" Margin="4,8">
|
||||
<Button Content="查询 IDN" Command="{Binding QueryIdentityCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 响应日志 -->
|
||||
<GroupBox Header="响应日志" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<ScrollViewer Height="260" VerticalScrollBarVisibility="Auto">
|
||||
<TextBox Text="{Binding ResponseLog, Mode=OneWay}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="11"
|
||||
FontFamily="Consolas"
|
||||
Background="#FAFAFA"
|
||||
BorderThickness="0"
|
||||
VerticalAlignment="Top"/>
|
||||
</ScrollViewer>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
28
DeviceEditModule/Views/IT7800EView.xaml.cs
Normal file
28
DeviceEditModule/Views/IT7800EView.xaml.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// IT7800EView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class IT7800EView : UserControl
|
||||
{
|
||||
public IT7800EView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
264
DeviceEditModule/Views/N36200View.xaml
Normal file
264
DeviceEditModule/Views/N36200View.xaml
Normal file
@@ -0,0 +1,264 @@
|
||||
<UserControl x:Class="DeviceEditModule.Views.N36200View"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
d:DesignHeight="760" d:DesignWidth="860">
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVis"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel Margin="12">
|
||||
|
||||
<!-- ═══ 设备信息头 ═══ -->
|
||||
<materialDesign:Card Margin="0,0,0,8" Padding="12,8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<materialDesign:PackIcon Kind="BatteryCharging" Width="22" Height="22"
|
||||
Foreground="#2E7D32" Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="N36200 宽范围可编程直流电源"
|
||||
FontSize="15" FontWeight="Bold"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="{Binding DeviceName, StringFormat=' [{0}]'}"
|
||||
FontSize="13" Foreground="#757575"
|
||||
VerticalAlignment="Center" Margin="4,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 连接状态指示 -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Width="10" Height="10" CornerRadius="5" Margin="0,0,6,0">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Background" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock VerticalAlignment="Center" FontSize="12">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="未连接"/>
|
||||
<Setter Property="Foreground" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Text" Value="已连接"/>
|
||||
<Setter Property="Foreground" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<ProgressBar IsIndeterminate="True" Width="80" Height="4"
|
||||
Margin="12,0,0,0"
|
||||
Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
|
||||
<!-- ═══ 主体 2 列 ═══ -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- ─── 左列 ─── -->
|
||||
<StackPanel Grid.Column="0" Margin="0,0,4,0">
|
||||
|
||||
<!-- 输出控制 -->
|
||||
<GroupBox Header="输出控制" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<!-- 开关输出 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="DC 输出" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="开启输出" Command="{Binding OutputOnCommand}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
Background="#388E3C" Foreground="White"
|
||||
Height="32" Padding="12,0" FontSize="12" Margin="4,0"/>
|
||||
<Button Content="关闭输出" Command="{Binding OutputOffCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 运行模式 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="运行模式" Style="{StaticResource ParamLabel}"/>
|
||||
<ComboBox Width="100" Height="32" Margin="4,0"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
SelectedItem="{Binding SelectedMode}"
|
||||
VerticalContentAlignment="Center" FontSize="12">
|
||||
<ComboBoxItem Content="NORMal"/>
|
||||
<ComboBoxItem Content="CHARge"/>
|
||||
<ComboBoxItem Content="SEQuence"/>
|
||||
<ComboBoxItem Content="CPOWer"/>
|
||||
<ComboBoxItem Content="CARWave"/>
|
||||
</ComboBox>
|
||||
<Button Content="设置" Command="{Binding SetModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 重置 / 清除 / IDN -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="系统操作" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="清除告警" Command="{Binding ClearAlarmCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
<Button Content="重置设备" Command="{Binding ResetDeviceCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 参数设置 -->
|
||||
<GroupBox Header="参数设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<!-- 电压 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="电压 (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding Voltage, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetVoltageCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 限流 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="限流 (A)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding CurrentLimit, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetCurrentCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 保护设置 -->
|
||||
<GroupBox Header="保护设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OVP (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OvpValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OVP" Command="{Binding SetOvpCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OCP (A)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OcpValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OCP" Command="{Binding SetOcpCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="UVP (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding UvpValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 UVP" Command="{Binding SetUvpCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OPP (W)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OppValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OPP" Command="{Binding SetOppCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ─── 右列 ─── -->
|
||||
<StackPanel Grid.Column="1" Margin="4,0,0,0">
|
||||
|
||||
<!-- 实时测量 -->
|
||||
<GroupBox Header="实时测量" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际电压" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredVoltage, Mode=OneWay}"/>
|
||||
<TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际电流" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredCurrent, Mode=OneWay}"/>
|
||||
<TextBlock Text="A" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际功率" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredPower, Mode=OneWay}"/>
|
||||
<TextBlock Text="W" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<Button Content="刷新全部测量" Command="{Binding QueryAllMeasureCommand}"
|
||||
Style="{StaticResource CmdBtn}"
|
||||
HorizontalAlignment="Left" Margin="0,4,0,0"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 设备信息与状态 -->
|
||||
<GroupBox Header="设备信息与状态" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<Button Content="查询 IDN" Command="{Binding QueryIdentityCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="查询状态字" Command="{Binding QueryStatusCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="状态字" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}" Width="200"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding DeviceStatus, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 响应日志 -->
|
||||
<GroupBox Header="响应日志" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<ScrollViewer Height="300" VerticalScrollBarVisibility="Auto">
|
||||
<TextBox Text="{Binding ResponseLog, Mode=OneWay}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="11"
|
||||
FontFamily="Consolas"
|
||||
Background="#FAFAFA"
|
||||
BorderThickness="0"
|
||||
VerticalAlignment="Top"/>
|
||||
</ScrollViewer>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
28
DeviceEditModule/Views/N36200View.xaml.cs
Normal file
28
DeviceEditModule/Views/N36200View.xaml.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// N36200View.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class N36200View : UserControl
|
||||
{
|
||||
public N36200View()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
249
DeviceEditModule/Views/N36600View.xaml
Normal file
249
DeviceEditModule/Views/N36600View.xaml
Normal file
@@ -0,0 +1,249 @@
|
||||
<UserControl x:Class="DeviceEditModule.Views.N36600View"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
d:DesignHeight="760" d:DesignWidth="860">
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVis"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel Margin="12">
|
||||
|
||||
<!-- ═══ 设备信息头 ═══ -->
|
||||
<materialDesign:Card Margin="0,0,0,8" Padding="12,8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<materialDesign:PackIcon Kind="BatteryCharging" Width="22" Height="22"
|
||||
Foreground="#2E7D32" Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="N36600 便携式宽范围可编程直流电源"
|
||||
FontSize="15" FontWeight="Bold"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="{Binding DeviceName, StringFormat=' [{0}]'}"
|
||||
FontSize="13" Foreground="#757575"
|
||||
VerticalAlignment="Center" Margin="4,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 连接状态指示 -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Width="10" Height="10" CornerRadius="5" Margin="0,0,6,0">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Background" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock VerticalAlignment="Center" FontSize="12">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="未连接"/>
|
||||
<Setter Property="Foreground" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Text" Value="已连接"/>
|
||||
<Setter Property="Foreground" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<ProgressBar IsIndeterminate="True" Width="80" Height="4"
|
||||
Margin="12,0,0,0"
|
||||
Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
|
||||
<!-- ═══ 主体 2 列 ═══ -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- ─── 左列 ─── -->
|
||||
<StackPanel Grid.Column="0" Margin="0,0,4,0">
|
||||
|
||||
<!-- 输出控制 -->
|
||||
<GroupBox Header="输出控制" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<!-- 开关输出 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="DC 输出" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="开启输出" Command="{Binding OutputOnCommand}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
Background="#388E3C" Foreground="White"
|
||||
Height="32" Padding="12,0" FontSize="12" Margin="4,0"/>
|
||||
<Button Content="关闭输出" Command="{Binding OutputOffCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 远程/本地 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="控制模式" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="远程控制" Command="{Binding SetRemoteModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="本地控制" Command="{Binding SetLocalModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 清除保护 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="清除保护" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="清除OVP" Command="{Binding ClearVoltageProtectionCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
<Button Content="清除OCP" Command="{Binding ClearCurrentProtectionCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 参数设置 -->
|
||||
<GroupBox Header="参数设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<!-- 电压 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="电压 (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding Voltage, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetVoltageCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 电流 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="电流 (A)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding CurrentLimit, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetCurrentCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 功率 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="功率 (W)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding Power, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetPowerCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 保护设置 -->
|
||||
<GroupBox Header="保护设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OVP (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OvpValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OVP" Command="{Binding SetOvpCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OCP (A)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OcpValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OCP" Command="{Binding SetOcpCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ─── 右列 ─── -->
|
||||
<StackPanel Grid.Column="1" Margin="4,0,0,0">
|
||||
|
||||
<!-- 实时测量 -->
|
||||
<GroupBox Header="实时测量" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际电压" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredVoltage, Mode=OneWay}"/>
|
||||
<TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际电流" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredCurrent, Mode=OneWay}"/>
|
||||
<TextBlock Text="A" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际功率" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredPower, Mode=OneWay}"/>
|
||||
<TextBlock Text="W" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<Button Content="刷新全部测量" Command="{Binding QueryAllMeasureCommand}"
|
||||
Style="{StaticResource CmdBtn}"
|
||||
HorizontalAlignment="Left" Margin="0,4,0,0"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 设备信息与状态 -->
|
||||
<GroupBox Header="设备信息与状态" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<Button Content="查询 IDN" Command="{Binding QueryIdentityCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="查询输出状态" Command="{Binding QueryOutputStateCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="输出状态" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}" Width="160"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OutputState, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 响应日志 -->
|
||||
<GroupBox Header="响应日志" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<ScrollViewer Height="300" VerticalScrollBarVisibility="Auto">
|
||||
<TextBox Text="{Binding ResponseLog, Mode=OneWay}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="11"
|
||||
FontFamily="Consolas"
|
||||
Background="#FAFAFA"
|
||||
BorderThickness="0"
|
||||
VerticalAlignment="Top"/>
|
||||
</ScrollViewer>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
28
DeviceEditModule/Views/N36600View.xaml.cs
Normal file
28
DeviceEditModule/Views/N36600View.xaml.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// N36600View.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class N36600View : UserControl
|
||||
{
|
||||
public N36600View()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
262
DeviceEditModule/Views/N69200View.xaml
Normal file
262
DeviceEditModule/Views/N69200View.xaml
Normal file
@@ -0,0 +1,262 @@
|
||||
<UserControl x:Class="DeviceEditModule.Views.N69200View"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
d:DesignHeight="760" d:DesignWidth="860">
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVis"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel Margin="12">
|
||||
|
||||
<!-- ═══ 设备信息头 ═══ -->
|
||||
<materialDesign:Card Margin="0,0,0,8" Padding="12,8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<materialDesign:PackIcon Kind="CurrentDc" Width="22" Height="22"
|
||||
Foreground="#1565C0" Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="N69200 可编程直流电子负载"
|
||||
FontSize="15" FontWeight="Bold"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="{Binding DeviceName, StringFormat=' [{0}]'}"
|
||||
FontSize="13" Foreground="#757575"
|
||||
VerticalAlignment="Center" Margin="4,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 连接状态指示 -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Width="10" Height="10" CornerRadius="5" Margin="0,0,6,0">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Background" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock VerticalAlignment="Center" FontSize="12">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="未连接"/>
|
||||
<Setter Property="Foreground" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Text" Value="已连接"/>
|
||||
<Setter Property="Foreground" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<ProgressBar IsIndeterminate="True" Width="80" Height="4"
|
||||
Margin="12,0,0,0"
|
||||
Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
|
||||
<!-- ═══ 主体 2 列 ═══ -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- ─── 左列 ─── -->
|
||||
<StackPanel Grid.Column="0" Margin="0,0,4,0">
|
||||
|
||||
<!-- 输入控制 -->
|
||||
<GroupBox Header="输入控制" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<!-- 开关输入 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="DC 输入" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="开启输入" Command="{Binding InputOnCommand}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
Background="#388E3C" Foreground="White"
|
||||
Height="32" Padding="12,0" FontSize="12" Margin="4,0"/>
|
||||
<Button Content="关闭输入" Command="{Binding InputOffCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 工作模式 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="工作模式" Style="{StaticResource ParamLabel}"/>
|
||||
<ComboBox Width="90" Height="32" Margin="4,0"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
SelectedItem="{Binding SelectedMode}"
|
||||
VerticalContentAlignment="Center" FontSize="12">
|
||||
<ComboBoxItem Content="CC"/>
|
||||
<ComboBoxItem Content="CV"/>
|
||||
<ComboBoxItem Content="CP"/>
|
||||
<ComboBoxItem Content="CR"/>
|
||||
</ComboBox>
|
||||
<Button Content="设置" Command="{Binding SetModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="查询" Command="{Binding QueryModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 远程/本地 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="控制模式" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="远程控制" Command="{Binding SetRemoteModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="本地控制" Command="{Binding SetLocalModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<!-- 系统操作 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="系统操作" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="清除告警" Command="{Binding ClearAlarmCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
<Button Content="重置设备" Command="{Binding ResetDeviceCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 参数设置 -->
|
||||
<GroupBox Header="参数设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<!-- 设定值 -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="设定值" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding LoadValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetLoadValueCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 保护设置 -->
|
||||
<GroupBox Header="保护设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OVP (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OvpValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OVP" Command="{Binding SetOvpCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OCP (A)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OcpValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OCP" Command="{Binding SetOcpCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="OPP (W)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding OppValue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置 OPP" Command="{Binding SetOppCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ─── 右列 ─── -->
|
||||
<StackPanel Grid.Column="1" Margin="4,0,0,0">
|
||||
|
||||
<!-- 实时测量 -->
|
||||
<GroupBox Header="实时测量" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际电压" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredVoltage, Mode=OneWay}"/>
|
||||
<TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际电流" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredCurrent, Mode=OneWay}"/>
|
||||
<TextBlock Text="A" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="实际功率" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding MeasuredPower, Mode=OneWay}"/>
|
||||
<TextBlock Text="W" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<Button Content="刷新全部测量" Command="{Binding QueryAllMeasureCommand}"
|
||||
Style="{StaticResource CmdBtn}"
|
||||
HorizontalAlignment="Left" Margin="0,4,0,0"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 设备信息与状态 -->
|
||||
<GroupBox Header="设备信息与状态" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<Button Content="查询 IDN" Command="{Binding QueryIdentityCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="查询状态字节" Command="{Binding QueryStatusCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="当前模式" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}" Width="120"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding CurrentMode, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="状态字节" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}" Width="120"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding StatusByte, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 响应日志 -->
|
||||
<GroupBox Header="响应日志" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<ScrollViewer Height="260" VerticalScrollBarVisibility="Auto">
|
||||
<TextBox Text="{Binding ResponseLog, Mode=OneWay}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="11"
|
||||
FontFamily="Consolas"
|
||||
Background="#FAFAFA"
|
||||
BorderThickness="0"
|
||||
VerticalAlignment="Top"/>
|
||||
</ScrollViewer>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
28
DeviceEditModule/Views/N69200View.xaml.cs
Normal file
28
DeviceEditModule/Views/N69200View.xaml.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// N69200View.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class N69200View : UserControl
|
||||
{
|
||||
public N69200View()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
246
DeviceEditModule/Views/SDS2000X_HDView.xaml
Normal file
246
DeviceEditModule/Views/SDS2000X_HDView.xaml
Normal file
@@ -0,0 +1,246 @@
|
||||
<UserControl x:Class="DeviceEditModule.Views.SDS2000X_HDView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
d:DesignHeight="760" d:DesignWidth="860">
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVis"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel Margin="12">
|
||||
|
||||
<!-- ═══ 设备信息头 ═══ -->
|
||||
<materialDesign:Card Margin="0,0,0,8" Padding="12,8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<materialDesign:PackIcon Kind="Waveform" Width="22" Height="22"
|
||||
Foreground="#1565C0" Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="SDS2000X_HD 数字存储示波器"
|
||||
FontSize="15" FontWeight="Bold"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="{Binding DeviceName, StringFormat=' [{0}]'}"
|
||||
FontSize="13" Foreground="#757575"
|
||||
VerticalAlignment="Center" Margin="4,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 连接状态指示 -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Width="10" Height="10" CornerRadius="5" Margin="0,0,6,0">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Background" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock VerticalAlignment="Center" FontSize="12">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="未连接"/>
|
||||
<Setter Property="Foreground" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Text" Value="已连接"/>
|
||||
<Setter Property="Foreground" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<ProgressBar IsIndeterminate="True" Width="80" Height="4"
|
||||
Margin="12,0,0,0"
|
||||
Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
|
||||
<!-- ═══ 主体 2 列 ═══ -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- ─── 左列 ─── -->
|
||||
<StackPanel Grid.Column="0" Margin="0,0,4,0">
|
||||
|
||||
<!-- 通道选择 -->
|
||||
<GroupBox Header="通道选择" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="通道号" Style="{StaticResource ParamLabel}"/>
|
||||
<ComboBox Width="80" Height="32" Margin="4,0"
|
||||
SelectedItem="{Binding Channel}"
|
||||
VerticalContentAlignment="Center" FontSize="12">
|
||||
<ComboBoxItem Content="1"/>
|
||||
<ComboBoxItem Content="2"/>
|
||||
<ComboBoxItem Content="3"/>
|
||||
<ComboBoxItem Content="4"/>
|
||||
</ComboBox>
|
||||
<Button Content="开启" Command="{Binding SetChannelOnCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="关闭" Command="{Binding SetChannelOffCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 运行控制 -->
|
||||
<GroupBox Header="运行控制" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<Button Content="Run" Command="{Binding RunCommand}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
Background="#388E3C" Foreground="White"
|
||||
Height="32" Padding="16,0" FontSize="12" Margin="4,0"/>
|
||||
<Button Content="Stop" Command="{Binding StopCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
<Button Content="Single" Command="{Binding SingleCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="Force Trig" Command="{Binding ForceTriggerCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<Button Content="查询 IDN" Command="{Binding QueryIdentityCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="重置设备" Command="{Binding ResetDeviceCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 垂直设置 -->
|
||||
<GroupBox Header="垂直设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="V/div (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
Text="{Binding VoltsPerDiv, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetVoltsDivCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="Offset (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
Text="{Binding Offset, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetOffsetCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="输入阻抗" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="50Ω" Command="{Binding SetImpedance50Command}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="1MΩ" Command="{Binding SetImpedance1MCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 水平/触发设置 -->
|
||||
<GroupBox Header="水平与触发" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="时基 (s/div)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
Text="{Binding TimeBase, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetTimeBaseCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="触发电平 (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
Text="{Binding TriggerLevel, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetTriggerLevelCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="触发源" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}" Width="80"
|
||||
Text="{Binding TriggerSource, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetTriggerSourceCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ─── 右列 ─── -->
|
||||
<StackPanel Grid.Column="1" Margin="4,0,0,0">
|
||||
|
||||
<!-- 自动测量 -->
|
||||
<GroupBox Header="自动测量" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="Vpp" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
Text="{Binding MeasuredVpp, Mode=OneWay}"/>
|
||||
<TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
<Button Content="刷新" Command="{Binding QueryVppCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="频率" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
Text="{Binding MeasuredFrequency, Mode=OneWay}"/>
|
||||
<TextBlock Text="Hz" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
<Button Content="刷新" Command="{Binding QueryFrequencyCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="RMS" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
Text="{Binding MeasuredRms, Mode=OneWay}"/>
|
||||
<TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
<Button Content="刷新" Command="{Binding QueryRmsCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<Button Content="刷新全部测量" Command="{Binding QueryMeasurementsCommand}"
|
||||
Style="{StaticResource CmdBtn}"
|
||||
HorizontalAlignment="Left" Margin="0,4,0,0"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 响应日志 -->
|
||||
<GroupBox Header="响应日志" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<ScrollViewer Height="460" VerticalScrollBarVisibility="Auto">
|
||||
<TextBox Text="{Binding ResponseLog, Mode=OneWay}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="11"
|
||||
FontFamily="Consolas"
|
||||
Background="#FAFAFA"
|
||||
BorderThickness="0"
|
||||
VerticalAlignment="Top"/>
|
||||
</ScrollViewer>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
28
DeviceEditModule/Views/SDS2000X_HDView.xaml.cs
Normal file
28
DeviceEditModule/Views/SDS2000X_HDView.xaml.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// SDS2000X_HDView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SDS2000X_HDView : UserControl
|
||||
{
|
||||
public SDS2000X_HDView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
255
DeviceEditModule/Views/SPAW7000View.xaml
Normal file
255
DeviceEditModule/Views/SPAW7000View.xaml
Normal file
@@ -0,0 +1,255 @@
|
||||
<UserControl x:Class="DeviceEditModule.Views.SPAW7000View"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
|
||||
mc:Ignorable="d"
|
||||
prism:ViewModelLocator.AutoWireViewModel="True"
|
||||
d:DesignHeight="760" d:DesignWidth="860">
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVis"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel Margin="12">
|
||||
|
||||
<!-- ═══ 设备信息头 ═══ -->
|
||||
<materialDesign:Card Margin="0,0,0,8" Padding="12,8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<materialDesign:PackIcon Kind="ChartLine" Width="22" Height="22"
|
||||
Foreground="#1565C0" Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="SPAW7000 功率分析记录仪"
|
||||
FontSize="15" FontWeight="Bold"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="{Binding DeviceName, StringFormat=' [{0}]'}"
|
||||
FontSize="13" Foreground="#757575"
|
||||
VerticalAlignment="Center" Margin="4,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 连接状态指示 -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Width="10" Height="10" CornerRadius="5" Margin="0,0,6,0">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Background" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
<TextBlock VerticalAlignment="Center" FontSize="12">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="未连接"/>
|
||||
<Setter Property="Foreground" Value="#F44336"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Text" Value="已连接"/>
|
||||
<Setter Property="Foreground" Value="#4CAF50"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<ProgressBar IsIndeterminate="True" Width="80" Height="4"
|
||||
Margin="12,0,0,0"
|
||||
Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
|
||||
<!-- ═══ 主体 2 列 ═══ -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- ─── 左列 ─── -->
|
||||
<StackPanel Grid.Column="0" Margin="0,0,4,0">
|
||||
|
||||
<!-- 通道与量程 -->
|
||||
<GroupBox Header="通道与量程" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="通道号" Style="{StaticResource ParamLabel}"/>
|
||||
<ComboBox Width="80" Height="32" Margin="4,0"
|
||||
SelectedItem="{Binding Channel}"
|
||||
VerticalContentAlignment="Center" FontSize="12">
|
||||
<ComboBoxItem Content="1"/>
|
||||
<ComboBoxItem Content="2"/>
|
||||
<ComboBoxItem Content="3"/>
|
||||
<ComboBoxItem Content="4"/>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="电压量程 (V)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
Text="{Binding VoltageRange, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetVoltageRangeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="电流量程 (A)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
Text="{Binding CurrentRange, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetCurrentRangeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="耦合模式" Style="{StaticResource ParamLabel}"/>
|
||||
<ComboBox Width="90" Height="32" Margin="4,0"
|
||||
SelectedItem="{Binding CouplingMode}"
|
||||
VerticalContentAlignment="Center" FontSize="12">
|
||||
<ComboBoxItem Content="AC"/>
|
||||
<ComboBoxItem Content="DC"/>
|
||||
<ComboBoxItem Content="ACDC"/>
|
||||
</ComboBox>
|
||||
<Button Content="设置" Command="{Binding SetCouplingModeCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 系统设置 -->
|
||||
<GroupBox Header="系统设置" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="分辨率" Style="{StaticResource ParamLabel}"/>
|
||||
<ComboBox Width="80" Height="32" Margin="4,0"
|
||||
SelectedItem="{Binding Resolution}"
|
||||
VerticalContentAlignment="Center" FontSize="12">
|
||||
<ComboBoxItem Content="5"/>
|
||||
<ComboBoxItem Content="6"/>
|
||||
</ComboBox>
|
||||
<Button Content="设置" Command="{Binding SetResolutionCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="亮度 (1~10)" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}" Width="60"
|
||||
Text="{Binding Brightness, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding SetBrightnessCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="触摸锁" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="锁定" Command="{Binding SetTouchLockOnCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="解锁" Command="{Binding SetTouchLockOffCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 设备信息 -->
|
||||
<GroupBox Header="设备信息" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<Button Content="查询 IDN" Command="{Binding QueryIdentityCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="重置设备" Command="{Binding ResetDeviceCommand}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<Button Content="查询型号" Command="{Binding QueryModelCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="查询序列号" Command="{Binding QuerySerialCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="查询 STB" Command="{Binding QueryStatusByteCommand}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="型号" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}" Width="120"
|
||||
Text="{Binding DeviceModel, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="序列号" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}" Width="160"
|
||||
Text="{Binding DeviceSerial, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ─── 右列 ─── -->
|
||||
<StackPanel Grid.Column="1" Margin="4,0,0,0">
|
||||
|
||||
<!-- 实时测量 -->
|
||||
<GroupBox Header="实时测量" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="电压" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
Text="{Binding MeasuredVoltage, Mode=OneWay}"/>
|
||||
<TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="电流" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
Text="{Binding MeasuredCurrent, Mode=OneWay}"/>
|
||||
<TextBlock Text="A" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="功率" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
Text="{Binding MeasuredPower, Mode=OneWay}"/>
|
||||
<TextBlock Text="W" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="频率" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
Text="{Binding MeasuredFrequency, Mode=OneWay}"/>
|
||||
<TextBlock Text="Hz" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="功率因数" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
Text="{Binding MeasuredPowerFactor, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
<Button Content="刷新全部测量" Command="{Binding QueryAllMeasureCommand}"
|
||||
Style="{StaticResource CmdBtn}"
|
||||
HorizontalAlignment="Left" Margin="0,4,0,0"/>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 响应日志 -->
|
||||
<GroupBox Header="响应日志" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<ScrollViewer Height="360" VerticalScrollBarVisibility="Auto">
|
||||
<TextBox Text="{Binding ResponseLog, Mode=OneWay}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="11"
|
||||
FontFamily="Consolas"
|
||||
Background="#FAFAFA"
|
||||
BorderThickness="0"
|
||||
VerticalAlignment="Top"/>
|
||||
</ScrollViewer>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
28
DeviceEditModule/Views/SPAW7000View.xaml.cs
Normal file
28
DeviceEditModule/Views/SPAW7000View.xaml.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// SPAW7000View.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SPAW7000View : UserControl
|
||||
{
|
||||
public SPAW7000View()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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<SystemConfig>();
|
||||
_deviceManager = containerProvider.Resolve<DeviceManager>();
|
||||
_globalInfo = containerProvider.Resolve<GlobalInfo>();
|
||||
_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);
|
||||
}
|
||||
/// <summary>
|
||||
/// 跟踪已打开的弹窗管理器窗口实例,避免重复打开多个 DialogMangerView 窗口。
|
||||
/// </summary>
|
||||
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<System.Windows.Window>()
|
||||
.FirstOrDefault(w => w.DataContext?.GetType().Name == "DialogMangerViewModel");
|
||||
}
|
||||
|
||||
// 2. 从容器按注册名解析设备编辑 View
|
||||
var view = _containerProvider.Resolve<object>(viewName) as System.Windows.FrameworkElement;
|
||||
if (view == null) return;
|
||||
|
||||
// 3. 通过反射调用 ViewModel 上的 Initialize(deviceName) 方法,
|
||||
// 避免 TestingModule 直接引用 DeviceEditModule 的类型
|
||||
var vm = view.DataContext;
|
||||
if (vm != null)
|
||||
{
|
||||
var initMethod = vm.GetType().GetMethod("Initialize", new[] { typeof(string) });
|
||||
initMethod?.Invoke(vm, new object[] { SelectedDevice.DeviceName });
|
||||
}
|
||||
|
||||
// 4. 发布事件 → DialogMangerViewModel 接收后将此 View 添加为 Tab
|
||||
// 标题格式:{当前作用域} - {设备名称},作为全局唯一 Tab 标识
|
||||
_eventAggregator.GetEvent<AddDialogTabEvent>().Publish(new DialogTabInfo
|
||||
{
|
||||
Title = $"{_globalInfo.CurrentScope} - {SelectedDevice.DeviceName}",
|
||||
Content = view
|
||||
});
|
||||
|
||||
// 5. 将窗口置顶(确保用户看到新增的 Tab)
|
||||
if (_dialogWindow != null && _dialogWindow.IsVisible)
|
||||
{
|
||||
if (_dialogWindow.WindowState == System.Windows.WindowState.Minimized)
|
||||
_dialogWindow.WindowState = System.Windows.WindowState.Normal;
|
||||
_dialogWindow.Activate();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LoggerHelper.ErrorWithNotify($"打开设备编辑窗口 [{type}] 失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void ParameterDelete()
|
||||
|
||||
21
UIShare/PubEvent/AddDialogTabEvent.cs
Normal file
21
UIShare/PubEvent/AddDialogTabEvent.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using UIShare.UIViewModel;
|
||||
|
||||
namespace UIShare.PubEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// 其他模块向弹窗管理器添加 Tab 的事件。
|
||||
/// 发布方:任何需要将弹窗托管到 DialogManagerView 的模块。
|
||||
/// 订阅方:<c>DialogMangerViewModel</c>(仅一处订阅)。
|
||||
/// <code>
|
||||
/// // 示例:在某个 ViewModel 中发布
|
||||
/// _eventAggregator.GetEvent<AddDialogTabEvent>().Publish(new DialogTabInfo
|
||||
/// {
|
||||
/// Title = "设备配置",
|
||||
/// Content = new DeviceConfigView()
|
||||
/// });
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public class AddDialogTabEvent : PubSubEvent<DialogTabInfo>
|
||||
{
|
||||
}
|
||||
}
|
||||
12
UIShare/PubEvent/CancelMinimizeEvent.cs
Normal file
12
UIShare/PubEvent/CancelMinimizeEvent.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 CancelMinimizeEvent:PubSubEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,6 @@
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Secondary/MaterialDesignColor.Lime.xaml" />
|
||||
<!--自定义style-->
|
||||
<ResourceDictionary Source="/UIShare;component/Styles/WindowStyle.xaml"></ResourceDictionary>
|
||||
<ResourceDictionary Source="/UIShare;component/Styles/DialogControlStyle.xaml"></ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
|
||||
63
UIShare/Styles/DialogControlStyle.xaml
Normal file
63
UIShare/Styles/DialogControlStyle.xaml
Normal file
@@ -0,0 +1,63 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style x:Key="CmdBtn" TargetType="Button" BasedOn="{StaticResource MaterialDesignRaisedButton}">
|
||||
<Setter Property="Height" Value="32"/>
|
||||
<Setter Property="Padding" Value="12,0"/>
|
||||
<Setter Property="FontSize" Value="12"/>
|
||||
<Setter Property="Margin" Value="4,0"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="WarnBtn" TargetType="Button" BasedOn="{StaticResource MaterialDesignRaisedButton}">
|
||||
<Setter Property="Height" Value="32"/>
|
||||
<Setter Property="Padding" Value="12,0"/>
|
||||
<Setter Property="FontSize" Value="12"/>
|
||||
<Setter Property="Margin" Value="4,0"/>
|
||||
<Setter Property="Background" Value="#EF6C00"/>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="NumInput" TargetType="TextBox" BasedOn="{StaticResource MaterialDesignOutlinedTextBox}">
|
||||
<Setter Property="Width" Value="100"/>
|
||||
<Setter Property="Height" Value="32"/>
|
||||
<Setter Property="Padding" Value="5,0"/>
|
||||
<Setter Property="materialDesign:TextFieldAssist.TextBoxViewMargin" Value="6,2,6,2"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="FontSize" Value="12"/>
|
||||
<Setter Property="Margin" Value="4,0"/>
|
||||
<Setter Property="materialDesign:HintAssist.IsFloating" Value="False"/>
|
||||
<Setter Property="materialDesign:HintAssist.Hint" Value=""/>
|
||||
|
||||
<Setter Property="AutomationProperties.Name" Value=""/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="MeasureBox" TargetType="TextBox" BasedOn="{StaticResource MaterialDesignOutlinedTextBox}">
|
||||
<Setter Property="Width" Value="110"/>
|
||||
<Setter Property="Height" Value="32"/>
|
||||
<Setter Property="Padding" Value="5,0"/>
|
||||
<Setter Property="materialDesign:TextFieldAssist.TextBoxViewMargin" Value="6,2,6,2"/>
|
||||
<Setter Property="IsReadOnly" Value="True"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="FontSize" Value="12"/>
|
||||
<Setter Property="Margin" Value="4,0"/>
|
||||
<Setter Property="Background" Value="#F5F5F5"/>
|
||||
<Setter Property="materialDesign:HintAssist.IsFloating" Value="False"/>
|
||||
<Setter Property="materialDesign:HintAssist.Hint" Value=""/>
|
||||
|
||||
<Setter Property="AutomationProperties.Name" Value=""/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ParamLabel" TargetType="TextBlock">
|
||||
<Setter Property="Width" Value="80"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="FontSize" Value="12"/>
|
||||
<Setter Property="Margin" Value="0,0,4,0"/>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -1,5 +1,5 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
|
||||
|
||||
<Style x:Key="DialogUserManageStyle"
|
||||
TargetType="Window">
|
||||
@@ -19,4 +19,5 @@
|
||||
Value="WidthAndHeight" />
|
||||
</Style>
|
||||
|
||||
|
||||
</ResourceDictionary>
|
||||
|
||||
19
UIShare/UIViewModel/DialogTabInfo.cs
Normal file
19
UIShare/UIViewModel/DialogTabInfo.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace UIShare.UIViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 弹窗 Tab 信息载体(事件负载,轻量 POCO)。
|
||||
/// 其他模块发布 <c>AddDialogTabEvent</c> 时填充此对象,
|
||||
/// DialogMangerViewModel 接收后创建对应的 Tab 项。
|
||||
/// </summary>
|
||||
public class DialogTabInfo
|
||||
{
|
||||
/// <summary>Tab 标题(显示在标签页上)。</summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Tab 内容:传入一个已实例化的 <see cref="System.Windows.FrameworkElement"/>(通常是 UserControl),
|
||||
/// 由 ContentControl 直接承载展示。
|
||||
/// </summary>
|
||||
public object? Content { get; set; }
|
||||
}
|
||||
}
|
||||
60
UIShare/UIViewModel/DialogTabItemVM.cs
Normal file
60
UIShare/UIViewModel/DialogTabItemVM.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Prism.Commands;
|
||||
using Prism.Mvvm;
|
||||
using System;
|
||||
|
||||
namespace DeviceEditModule.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 弹窗管理器中单个 Tab 项的 ViewModel。
|
||||
/// 由 <see cref="DialogMangerViewModel"/> 在收到 AddDialogTabEvent 时创建,
|
||||
/// 通过构造函数注入选中/关闭的回调,保持与父 ViewModel 的低耦合。
|
||||
/// </summary>
|
||||
public class DialogTabItemVM : BindableBase
|
||||
{
|
||||
#region 属性
|
||||
|
||||
private string _title = string.Empty;
|
||||
/// <summary>Tab 标签页上显示的标题。</summary>
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
private object? _content;
|
||||
/// <summary>Tab 内容区域(通常为 UserControl 实例)。</summary>
|
||||
public object? Content
|
||||
{
|
||||
get => _content;
|
||||
set => SetProperty(ref _content, value);
|
||||
}
|
||||
|
||||
private bool _isSelected;
|
||||
/// <summary>是否为当前激活 Tab(用于切换选中态样式)。</summary>
|
||||
public bool IsSelected
|
||||
{
|
||||
get => _isSelected;
|
||||
set => SetProperty(ref _isSelected, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
|
||||
/// <summary>点击 Tab 标题激活该 Tab。</summary>
|
||||
public DelegateCommand SelectCommand { get; }
|
||||
|
||||
/// <summary>点击 Tab 上的 × 关闭并移除该 Tab。</summary>
|
||||
public DelegateCommand CloseCommand { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <param name="onSelect">父 VM 提供的激活回调。</param>
|
||||
/// <param name="onClose">父 VM 提供的关闭回调。</param>
|
||||
public DialogTabItemVM(Action<DialogTabItemVM> onSelect, Action<DialogTabItemVM> onClose)
|
||||
{
|
||||
SelectCommand = new DelegateCommand(() => onSelect(this));
|
||||
CloseCommand = new DelegateCommand(() => onClose(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user