182 lines
5.3 KiB
C#
182 lines
5.3 KiB
C#
using BOB.Singleton;
|
|
using Prism.Commands;
|
|
using Prism.Mvvm;
|
|
using Prism.Events;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using DeviceCommand.Device;
|
|
using Logger;
|
|
using BOB.ViewModels.UserControls;
|
|
|
|
namespace BOB.ViewModels.Dialogs
|
|
{
|
|
public class EAEL9080ViewModel : BindableBase, IDialogAware
|
|
{
|
|
#region 属性
|
|
private string _Title = "低压直流负载";
|
|
private string _设备标识字符串;
|
|
private string _负载模式;
|
|
private string _电流LA;
|
|
private string _电流LB;
|
|
private NumericalDisplayViewModel _电压MV=new();
|
|
private NumericalDisplayViewModel _电流MV = new();
|
|
private NumericalDisplayViewModel _功率MV=new();
|
|
|
|
public string Title
|
|
{
|
|
get { return _Title; }
|
|
set { SetProperty(ref _Title, value); }
|
|
}
|
|
|
|
public string 设备标识字符串
|
|
{
|
|
get { return _设备标识字符串; }
|
|
set { SetProperty(ref _设备标识字符串, value); }
|
|
}
|
|
|
|
public string 负载模式
|
|
{
|
|
get { return _负载模式; }
|
|
set { SetProperty(ref _负载模式, value); }
|
|
}
|
|
|
|
public string 电流LA
|
|
{
|
|
get { return _电流LA; }
|
|
set { SetProperty(ref _电流LA, value); }
|
|
}
|
|
|
|
public string 电流LB
|
|
{
|
|
get { return _电流LB; }
|
|
set { SetProperty(ref _电流LB, value); }
|
|
}
|
|
public NumericalDisplayViewModel 电压MV
|
|
{
|
|
get { return _电压MV; }
|
|
set { SetProperty(ref _电压MV, value); }
|
|
}
|
|
public NumericalDisplayViewModel 电流MV
|
|
{
|
|
get { return _电流MV; }
|
|
set { SetProperty(ref _电流MV, value); }
|
|
}
|
|
public NumericalDisplayViewModel 功率MV
|
|
{
|
|
get { return _功率MV; }
|
|
set { SetProperty(ref _功率MV, value); }
|
|
}
|
|
#endregion
|
|
|
|
#region 命令
|
|
public ICommand 连接命令 { get; private set; }
|
|
public ICommand 断开命令 { get; private set; }
|
|
public ICommand 设置为远程模式命令 { get; private set; }
|
|
public ICommand 设置负载工作模式命令 { get; private set; }
|
|
public ICommand 电源输出开命令 { get; private set; }
|
|
public ICommand 电源输出关命令 { get; private set; }
|
|
public ICommand 关闭命令 { get; private set; }
|
|
public ICommand 查询设备信息命令 { get; private set; }
|
|
|
|
#endregion
|
|
|
|
private IEventAggregator _eventAggregator { get; set; }
|
|
private Devices _devices { get; set; }
|
|
private GlobalVariables _globalVariables { get; set; }
|
|
private EAEL9080 device { get; set; }
|
|
|
|
public EAEL9080ViewModel(IContainerProvider containerProvider)
|
|
{
|
|
_devices = containerProvider.Resolve<Devices>();
|
|
_globalVariables = containerProvider.Resolve<GlobalVariables>();
|
|
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
|
|
连接命令 = new AsyncDelegateCommand(OnConnect);
|
|
断开命令 = new DelegateCommand(OnDisconnect);
|
|
设置为远程模式命令 = new AsyncDelegateCommand(OnSetRemoteMode);
|
|
设置负载工作模式命令 = new AsyncDelegateCommand(OnSetLoadMode);
|
|
电源输出开命令 = new AsyncDelegateCommand(OnPowerOn);
|
|
电源输出关命令 = new AsyncDelegateCommand(OnPowerOff);
|
|
关闭命令 = new DelegateCommand(OnOff);
|
|
查询设备信息命令 = new AsyncDelegateCommand(OnQueryDeviceInfo);
|
|
}
|
|
|
|
private async Task OnQueryDeviceInfo()
|
|
{
|
|
设备标识字符串 = await device.查询设备信息();
|
|
}
|
|
|
|
private void OnOff()
|
|
{
|
|
RequestClose.Invoke();
|
|
}
|
|
|
|
private async Task OnConnect()
|
|
{
|
|
await device.ConnectAsync();
|
|
}
|
|
|
|
private async void OnDisconnect()
|
|
{
|
|
device.Close();
|
|
}
|
|
|
|
|
|
private async Task OnSetRemoteMode()
|
|
{
|
|
await device.设置远程控制(true);
|
|
}
|
|
|
|
private async Task OnSetLoadMode()
|
|
{
|
|
|
|
}
|
|
|
|
private async Task OnPowerOn()
|
|
{
|
|
await device.打开输出();
|
|
}
|
|
|
|
private async Task OnPowerOff()
|
|
{
|
|
await device.关闭输出();
|
|
}
|
|
|
|
#region dialog规范
|
|
public DialogCloseListener RequestClose { get; set; }
|
|
|
|
public bool CanCloseDialog()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void OnDialogClosed()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
try
|
|
{
|
|
var a = _devices.DeviceDic["EAEL9080"] as EAEL9080;
|
|
if (a != null)
|
|
{
|
|
device = a;
|
|
}
|
|
else
|
|
{
|
|
LoggerHelper.ErrorWithNotify("设备没有初始化无法打开测试界面");
|
|
RequestClose.Invoke();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
LoggerHelper.ErrorWithNotify("找不到设备无法打开测试界面");
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
}
|