Files
CapMachine/CapMachine.Wpf/ViewModels/DialogMeterExdViewModel.cs
Tyrone CT 3fde19855d 更改了报警地址
复位地址
数据记录进行了校验
2025-06-17 18:14:38 +08:00

163 lines
4.1 KiB
C#

using CapMachine.Core;
using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.Models;
using CapMachine.Wpf.Services;
using Prism.Commands;
using Prism.Services.Dialogs;
using System.Collections.ObjectModel;
namespace CapMachine.Wpf.ViewModels
{
public class DialogMeterExdViewModel : DialogViewModel
{
/// <summary>
/// 实例化函数
/// </summary>
public DialogMeterExdViewModel(MachineRtDataService machineRtDataService)
{
Title = "拓展控制";
MachineRtDataService = machineRtDataService;
}
/// <summary>
/// 当前的仪表命令消息
/// </summary>
public MeterCmdMsg CurMeterCmdMsg { get; set; }
private string name;
/// <summary>
/// 名称
/// </summary>
public string Name
{
get { return name; }
set { name = value; RaisePropertyChanged(); }
}
private int _Value;
/// <summary>
/// 值和数据
/// </summary>
public int Value
{
get { return _Value; }
set { _Value = value; RaisePropertyChanged(); }
}
private DelegateCommand _SendDataCmd;
/// <summary>
/// 发送数据命令
/// </summary>
public DelegateCommand SendDataCmd
{
set
{
_SendDataCmd = value;
}
get
{
if (_SendDataCmd == null)
{
_SendDataCmd = new DelegateCommand(() => SendDataCmdMethod());
}
return _SendDataCmd;
}
}
/// <summary>
/// 发送数据命令方法
/// </summary>
private void SendDataCmdMethod()
{
switch (CurMeterCmdMsg.Name)
{
case "PTC功率":
//发送数据 PTC功率 SV2
MachineRtDataService.SiemensDrive.Write("VW434", (short)Value);
break;
default:
break;
}
}
private DelegateCommand saveCmd;
/// <summary>
/// 保存命令
/// </summary>
public DelegateCommand SaveCmd
{
set
{
saveCmd = value;
}
get
{
if (saveCmd == null)
{
saveCmd = new DelegateCommand(() => SaveCmdMethod());
}
return saveCmd;
}
}
/// <summary>
/// 保存命令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void SaveCmdMethod()
{
DialogParameters pars = new DialogParameters
{
{ "NewData", "" }
};
RaiseRequestClose(new DialogResult(ButtonResult.OK, pars));
}
private DelegateCommand cancelCmd;
/// <summary>
/// 保存命令
/// </summary>
public DelegateCommand CancelCmd
{
set
{
cancelCmd = value;
}
get
{
if (cancelCmd == null)
{
cancelCmd = new DelegateCommand(() => CancelCmdMethod());
}
return cancelCmd;
}
}
public MachineRtDataService MachineRtDataService { get; }
/// <summary>
/// 取消命令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void CancelCmdMethod()
{
RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
}
/// <summary>
/// 窗口打开时的传递的参数
/// </summary>
/// <param name="parameters"></param>
public override void OnDialogOpened(IDialogParameters parameters)
{
//Name = parameters.GetValue<string>("Name");
CurMeterCmdMsg = parameters.GetValue<MeterCmdMsg>("MeterCmdMsg");
}
}
}