can修改
This commit is contained in:
@@ -0,0 +1,671 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# ============================================================
|
||||
# 通用模板函数
|
||||
# ============================================================
|
||||
|
||||
function Write-ViewModel {
|
||||
param(
|
||||
[string]$ProjectPath, # e.g. "c:\Users\kk\Desktop\BOB"
|
||||
[string]$ClassName, # e.g. "E36233A"
|
||||
[string]$DeviceType, # e.g. "可编程直流电源"
|
||||
[string]$DeviceNamespace, # e.g. "DeviceCommand.Device"
|
||||
[string]$Properties, # C# property block
|
||||
[string]$Commands, # ICommand declarations
|
||||
[string]$CommandInits, # Command initialization in constructor
|
||||
[string]$ExtraUsings = ""
|
||||
)
|
||||
|
||||
$dir = Join-Path $ProjectPath "DeviceEditModule\ViewModels"
|
||||
if (!(Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
|
||||
|
||||
$content = @"
|
||||
using $DeviceNamespace;
|
||||
using Prism.Commands;
|
||||
using Prism.Ioc;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using UIShare.GlobalVariable;
|
||||
using UIShare.ViewModelBase;
|
||||
$ExtraUsings
|
||||
|
||||
namespace DeviceEditModule.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// $ClassName $DeviceType 控制面板 ViewModel
|
||||
/// </summary>
|
||||
public class ${ClassName}ViewModel : NavigateViewModelBase, IDisposable
|
||||
{
|
||||
#region 私有字段
|
||||
|
||||
private readonly DeviceManager _deviceManager;
|
||||
private ${ClassName}? _device;
|
||||
private CancellationTokenSource? _cts;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 设备信息属性
|
||||
|
||||
private string _deviceName = "$ClassName";
|
||||
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
|
||||
|
||||
$Properties
|
||||
|
||||
private string _responseLog = string.Empty;
|
||||
/// <summary>命令响应日志(最新消息在顶部)。</summary>
|
||||
public string ResponseLog
|
||||
{
|
||||
get => _responseLog;
|
||||
set => SetProperty(ref _responseLog, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
|
||||
$Commands
|
||||
|
||||
#endregion
|
||||
|
||||
public ${ClassName}ViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
_deviceManager = containerProvider.Resolve<DeviceManager>();
|
||||
|
||||
$CommandInits
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
#region 初始化 / Navigation
|
||||
|
||||
public void Initialize(string? deviceName = null)
|
||||
{
|
||||
${ClassName}? found = null;
|
||||
string? foundName = null;
|
||||
|
||||
if (deviceName != null &&
|
||||
_deviceManager.DeviceMap.TryGetValue(deviceName, out var d) &&
|
||||
d is ${ClassName} e)
|
||||
{
|
||||
found = e;
|
||||
foundName = deviceName;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var kv in _deviceManager.DeviceMap)
|
||||
{
|
||||
if (kv.Value is ${ClassName} it)
|
||||
{
|
||||
found = it;
|
||||
foundName = kv.Key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_device = found;
|
||||
DeviceName = foundName ?? "$ClassName (未找到)";
|
||||
IsConnected = _device?.IsConnected ?? false;
|
||||
|
||||
AppendLog(found != null
|
||||
? $"已关联设备 [{DeviceName}],连接状态:{(IsConnected ? "已连接" : "未连接")}"
|
||||
: "未在 DeviceManager 中找到 $ClassName 设备,请先初始化设备配置。");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
"@
|
||||
$file = Join-Path $dir "${ClassName}ViewModel.cs"
|
||||
[System.IO.File]::WriteAllText($file, $content, [System.Text.Encoding]::UTF8)
|
||||
Write-Host " Created: $file"
|
||||
}
|
||||
|
||||
function Write-ViewXaml {
|
||||
param(
|
||||
[string]$ProjectPath,
|
||||
[string]$ClassName,
|
||||
[string]$DeviceTitle, # e.g. "E36233A 可编程直流电源"
|
||||
[string]$Icon, # e.g. "Flash"
|
||||
[string]$LeftGroups, # GroupBox XAML blocks for left column
|
||||
[string]$RightGroups # GroupBox XAML blocks for right column
|
||||
)
|
||||
|
||||
$dir = Join-Path $ProjectPath "DeviceEditModule\Views"
|
||||
if (!(Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
|
||||
|
||||
$content = @"
|
||||
<UserControl x:Class="DeviceEditModule.Views.${ClassName}View"
|
||||
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="False"
|
||||
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="$Icon" Width="22" Height="22"
|
||||
Foreground="#1565C0" Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"/>
|
||||
<TextBlock Text="$DeviceTitle"
|
||||
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">
|
||||
$LeftGroups
|
||||
</StackPanel>
|
||||
|
||||
<!-- 右列 -->
|
||||
<StackPanel Grid.Column="1" Margin="4,0,0,0">
|
||||
$RightGroups
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
"@
|
||||
$file = Join-Path $dir "${ClassName}View.xaml"
|
||||
[System.IO.File]::WriteAllText($file, $content, [System.Text.Encoding]::UTF8)
|
||||
Write-Host " Created: $file"
|
||||
}
|
||||
|
||||
function Write-ViewXamlCs {
|
||||
param(
|
||||
[string]$ProjectPath,
|
||||
[string]$ClassName
|
||||
)
|
||||
|
||||
$dir = Join-Path $ProjectPath "DeviceEditModule\Views"
|
||||
$content = @"
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace DeviceEditModule.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// ${ClassName}View.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ${ClassName}View : UserControl
|
||||
{
|
||||
public ${ClassName}View()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
"@
|
||||
$file = Join-Path $dir "${ClassName}View.xaml.cs"
|
||||
[System.IO.File]::WriteAllText($file, $content, [System.Text.Encoding]::UTF8)
|
||||
Write-Host " Created: $file"
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# XAML 通用片段
|
||||
# ============================================================
|
||||
|
||||
$XamlLogGroup = @"
|
||||
<!-- 设备信息 -->
|
||||
<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>
|
||||
"@
|
||||
|
||||
function Xaml-OutputControl($onCmd, $offCmd, $onLabel="开启输出", $offLabel="关闭输出") {
|
||||
return @"
|
||||
<!-- 输出控制 -->
|
||||
<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="$onLabel" Command="{Binding $onCmd}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
Background="#388E3C" Foreground="White"
|
||||
Height="32" Padding="12,0" FontSize="12" Margin="4,0"/>
|
||||
<Button Content="$offLabel" Command="{Binding $offCmd}"
|
||||
Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
"@
|
||||
}
|
||||
|
||||
function Xaml-ParamInput($header, $label, $binding, $cmd) {
|
||||
return @"
|
||||
<!-- $header -->
|
||||
<GroupBox Header="$header" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="$label" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource NumInput}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding $binding, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="设置" Command="{Binding $cmd}"
|
||||
Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
"@
|
||||
}
|
||||
|
||||
function Xaml-Measure($label, $binding, $unit) {
|
||||
return @"
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="$label" Style="{StaticResource ParamLabel}"/>
|
||||
<TextBox Style="{StaticResource MeasureBox}"
|
||||
materialDesign:HintAssist.Hint=""
|
||||
Text="{Binding $binding, Mode=OneWay}"/>
|
||||
<TextBlock Text="$unit" VerticalAlignment="Center" Margin="2,0,8,0"/>
|
||||
</StackPanel>
|
||||
"@
|
||||
}
|
||||
|
||||
function Xaml-MeasureGroup($header, $measures, $refreshCmd=$null) {
|
||||
$refreshBtn = ""
|
||||
if ($refreshCmd) {
|
||||
$refreshBtn = @"
|
||||
<Button Content="刷新全部测量" Command="{Binding $refreshCmd}"
|
||||
Style="{StaticResource CmdBtn}"
|
||||
HorizontalAlignment="Left" Margin="0,4,0,0"/>
|
||||
"@
|
||||
}
|
||||
return @"
|
||||
<!-- $header -->
|
||||
<GroupBox Header="$header" Margin="0,0,0,8"
|
||||
materialDesign:ColorZoneAssist.Mode="PrimaryLight">
|
||||
<StackPanel Margin="4,4,4,4">
|
||||
$measures
|
||||
$refreshBtn
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
"@
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# BOB 设备
|
||||
# ============================================================
|
||||
$BOB = "c:\Users\kk\Desktop\BOB"
|
||||
Write-Host "=== Generating BOB device edit views ==="
|
||||
|
||||
# --- 1. E36233A ---
|
||||
Write-Host "`n--- E36233A ---"
|
||||
Write-ViewModel -ProjectPath $BOB -ClassName "E36233A" -DeviceType "可编程直流电源" -DeviceNamespace "DeviceCommand.Device" `
|
||||
-Properties @"
|
||||
#region 输入参数属性
|
||||
|
||||
private double _voltage = 0.0;
|
||||
public double Voltage { get => _voltage; set => SetProperty(ref _voltage, value); }
|
||||
|
||||
private double _current = 0.0;
|
||||
public double Current { get => _current; set => SetProperty(ref _current, value); }
|
||||
|
||||
private double _ocpValue = 0.0;
|
||||
public double OcpValue { get => _ocpValue; set => SetProperty(ref _ocpValue, value); }
|
||||
|
||||
private double _ovpValue = 0.0;
|
||||
public double OvpValue { get => _ovpValue; set => SetProperty(ref _ovpValue, value); }
|
||||
|
||||
private int _channel = 1;
|
||||
public int Channel { get => _channel; set => SetProperty(ref _channel, value); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 测量结果属性
|
||||
|
||||
private double _measuredVoltage;
|
||||
public double MeasuredVoltage { get => _measuredVoltage; set => SetProperty(ref _measuredVoltage, value); }
|
||||
|
||||
private double _measuredCurrent;
|
||||
public double MeasuredCurrent { get => _measuredCurrent; set => SetProperty(ref _measuredCurrent, value); }
|
||||
|
||||
"@ `
|
||||
-Commands @"
|
||||
public ICommand QueryIdentityCommand { get; }
|
||||
public ICommand OutputOnCommand { get; }
|
||||
public ICommand OutputOffCommand { get; }
|
||||
public ICommand SetRemoteCommand { get; }
|
||||
public ICommand SetVoltageCommand { get; }
|
||||
public ICommand SetCurrentCommand { get; }
|
||||
public ICommand SetOcpCommand { get; }
|
||||
public ICommand SetOvpCommand { get; }
|
||||
public ICommand SetChannelCommand { get; }
|
||||
public ICommand QueryMeasureCommand { get; }
|
||||
public ICommand ClearProtectionCommand { get; }
|
||||
"@ `
|
||||
-CommandInits @"
|
||||
QueryIdentityCommand = new DelegateCommand(async () => await Exec(async () => AppendLog("IDN: " + await _device!.查询设备信息(Ct()))));
|
||||
OutputOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电源输出(true, Ct()); AppendLog("输出已开启"); }));
|
||||
OutputOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电源输出(false, Ct()); AppendLog("输出已关闭"); }));
|
||||
SetRemoteCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置为远程模式(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!.设置电流(Current, Ct()); AppendLog($"电流已设为 {Current} A"); }));
|
||||
SetOcpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电流保护OCP电流(OcpValue, Ct()); AppendLog($"OCP已设为 {OcpValue} A"); }));
|
||||
SetOvpCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电压保护OVP电压(OvpValue, Ct()); AppendLog($"OVP已设为 {OvpValue} V"); }));
|
||||
SetChannelCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置通道(Channel, Ct()); AppendLog($"通道已设为 {Channel}"); }));
|
||||
ClearProtectionCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.清除电流保护(Ct()); await _device!.清除电压保护(Ct()); AppendLog("保护已清除"); }));
|
||||
QueryMeasureCommand = new DelegateCommand(async () => await Exec(async () =>
|
||||
{
|
||||
MeasuredVoltage = await _device!.查询电压(Ct());
|
||||
MeasuredCurrent = await _device!.查询电流(Ct());
|
||||
AppendLog($"测量 -> 电压:{MeasuredVoltage}V 电流:{MeasuredCurrent}A");
|
||||
}));
|
||||
"@
|
||||
|
||||
Write-ViewXaml -ProjectPath $BOB -ClassName "E36233A" -DeviceTitle "E36233A 可编程直流电源" -Icon "Flash" `
|
||||
-LeftGroups @"
|
||||
$(Xaml-OutputControl "OutputOnCommand" "OutputOffCommand")
|
||||
<!-- 通道与系统 -->
|
||||
<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 Channel, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Content="切换" Command="{Binding SetChannelCommand}" Style="{StaticResource CmdBtn}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4">
|
||||
<TextBlock Text="系统操作" Style="{StaticResource ParamLabel}"/>
|
||||
<Button Content="远程控制" Command="{Binding SetRemoteCommand}" Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="清除保护" Command="{Binding ClearProtectionCommand}" Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
$(Xaml-ParamInput "电压设置" "电压 (V)" "Voltage" "SetVoltageCommand")
|
||||
$(Xaml-ParamInput "电流设置" "电流 (A)" "Current" "SetCurrentCommand")
|
||||
$(Xaml-ParamInput "OCP设置" "OCP (A)" "OcpValue" "SetOcpCommand")
|
||||
$(Xaml-ParamInput "OVP设置" "OVP (V)" "OvpValue" "SetOvpCommand")
|
||||
"@ `
|
||||
-RightGroups @"
|
||||
$(Xaml-MeasureGroup "实时测量" "$(Xaml-Measure '实际电压' 'MeasuredVoltage' 'V')
|
||||
$(Xaml-Measure '实际电流' 'MeasuredCurrent' 'A')" "QueryMeasureCommand")
|
||||
$XamlLogGroup
|
||||
"@
|
||||
|
||||
Write-ViewXamlCs -ProjectPath $BOB -ClassName "E36233A"
|
||||
|
||||
# --- 2. EAEL9080 ---
|
||||
Write-Host "`n--- EAEL9080 ---"
|
||||
Write-ViewModel -ProjectPath $BOB -ClassName "EAEL9080" -DeviceType "双向可编程直流电源" -DeviceNamespace "DeviceCommand.Device" `
|
||||
-Properties @"
|
||||
#region 输入参数属性
|
||||
|
||||
private double _voltage = 0.0;
|
||||
public double Voltage { get => _voltage; set => SetProperty(ref _voltage, value); }
|
||||
|
||||
private double _current = 0.0;
|
||||
public double Current { get => _current; set => SetProperty(ref _current, value); }
|
||||
|
||||
private double _power = 0.0;
|
||||
public double Power { get => _power; set => SetProperty(ref _power, value); }
|
||||
|
||||
private double _ovpValue = 0.0;
|
||||
public double OvpValue { get => _ovpValue; set => SetProperty(ref _ovpValue, value); }
|
||||
|
||||
private double _ocpValue = 0.0;
|
||||
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); }
|
||||
|
||||
#endregion
|
||||
"@ `
|
||||
-Commands @"
|
||||
public ICommand QueryIdentityCommand { get; }
|
||||
public ICommand ResetDeviceCommand { get; }
|
||||
public ICommand OutputOnCommand { get; }
|
||||
public ICommand OutputOffCommand { get; }
|
||||
public ICommand InputOnCommand { get; }
|
||||
public ICommand InputOffCommand { get; }
|
||||
public ICommand SetVoltageCommand { get; }
|
||||
public ICommand SetCurrentCommand { get; }
|
||||
public ICommand SetPowerCommand { get; }
|
||||
public ICommand SetOvpCommand { get; }
|
||||
public ICommand SetOcpCommand { get; }
|
||||
public ICommand QueryMeasureCommand { get; }
|
||||
public ICommand RemoteOnCommand { get; }
|
||||
public ICommand RemoteOffCommand { get; }
|
||||
"@ `
|
||||
-CommandInits @"
|
||||
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("DC输出已开启"); }));
|
||||
OutputOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输出(false, Ct()); AppendLog("DC输出已关闭"); }));
|
||||
InputOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输入(true, Ct()); AppendLog("DC输入已开启"); }));
|
||||
InputOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置DC输入(false, Ct()); AppendLog("DC输入已关闭"); }));
|
||||
SetVoltageCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电压(Voltage, Ct()); AppendLog($"电压已设为 {Voltage} V"); }));
|
||||
SetCurrentCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.设置电流(Current, Ct()); AppendLog($"电流已设为 {Current} 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"); }));
|
||||
RemoteOnCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.激活远程控制(true, Ct()); AppendLog("远程控制已激活"); }));
|
||||
RemoteOffCommand = new DelegateCommand(async () => await Exec(async () => { await _device!.激活远程控制(false, Ct()); AppendLog("远程控制已释放"); }));
|
||||
QueryMeasureCommand = new DelegateCommand(async () => await Exec(async () =>
|
||||
{
|
||||
MeasuredVoltage = await _device!.查询实际电压(Ct());
|
||||
MeasuredCurrent = await _device!.查询实际电流(Ct());
|
||||
MeasuredPower = await _device!.查询实际功率(Ct());
|
||||
AppendLog($"测量 -> 电压:{MeasuredVoltage} 电流:{MeasuredCurrent} 功率:{MeasuredPower}");
|
||||
}));
|
||||
"@
|
||||
|
||||
Write-ViewXaml -ProjectPath $BOB -ClassName "EAEL9080" -DeviceTitle "EA EL9080 双向可编程直流电源" -Icon "Flash" `
|
||||
-LeftGroups @"
|
||||
<!-- 输出/输入控制 -->
|
||||
<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}"/>
|
||||
<Button Content="开启" Command="{Binding InputOnCommand}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
Background="#1565C0" 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}"/>
|
||||
<Button Content="激活" Command="{Binding RemoteOnCommand}" Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="释放" Command="{Binding RemoteOffCommand}" Style="{StaticResource CmdBtn}"/>
|
||||
<Button Content="重置设备" Command="{Binding ResetDeviceCommand}" Style="{StaticResource WarnBtn}"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
$(Xaml-ParamInput "电压设置" "电压 (V)" "Voltage" "SetVoltageCommand")
|
||||
$(Xaml-ParamInput "电流设置" "电流 (A)" "Current" "SetCurrentCommand")
|
||||
$(Xaml-ParamInput "功率设置" "功率 (W)" "Power" "SetPowerCommand")
|
||||
$(Xaml-ParamInput "OVP设置" "OVP (V)" "OvpValue" "SetOvpCommand")
|
||||
$(Xaml-ParamInput "OCP设置" "OCP (A)" "OcpValue" "SetOcpCommand")
|
||||
"@ `
|
||||
-RightGroups @"
|
||||
$(Xaml-MeasureGroup "实时测量" "$(Xaml-Measure '实际电压' 'MeasuredVoltage' 'V')
|
||||
$(Xaml-Measure '实际电流' 'MeasuredCurrent' 'A')
|
||||
$(Xaml-Measure '实际功率' 'MeasuredPower' 'W')" "QueryMeasureCommand")
|
||||
$XamlLogGroup
|
||||
"@
|
||||
|
||||
Write-ViewXamlCs -ProjectPath $BOB -ClassName "EAEL9080"
|
||||
|
||||
Write-Host "BOB part 1 done (E36233A, EAEL9080)"
|
||||
Reference in New Issue
Block a user