Initial Push
This commit is contained in:
151
uniper_hmi/UniperHMI/Pages/ViewModels/AutomaticModePageVM.cs
Normal file
151
uniper_hmi/UniperHMI/Pages/ViewModels/AutomaticModePageVM.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using HMIToolkit;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Heisig.HMI.AdsManager;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using TwinCAT.TypeSystem;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace UniperHMI
|
||||
{
|
||||
|
||||
public enum E_BMS_CONTROL_MODE : short
|
||||
{
|
||||
AUTO_REMOTE = 1,
|
||||
AUTO_LOCAL = 2,
|
||||
SAFETY_CHECK = 3,
|
||||
CAPACITY_TEST = 4,
|
||||
MANUAL = 5
|
||||
}
|
||||
|
||||
public class BMSControlModeEntry(E_BMS_CONTROL_MODE mode, string name)
|
||||
{
|
||||
public E_BMS_CONTROL_MODE eMode = mode;
|
||||
public string Name = name;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed partial class AutomaticModePageVM : ObservableValidator, IDisposable
|
||||
{
|
||||
private int _setpoint;
|
||||
|
||||
[Range(-40000, 40000)]
|
||||
public int Setpoint
|
||||
{
|
||||
get => this._setpoint;
|
||||
set => SetProperty(ref this._setpoint, value, true);
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private int processValue;
|
||||
|
||||
[ObservableProperty]
|
||||
public HMIControlButtonVM? startButton;
|
||||
|
||||
[ObservableProperty]
|
||||
public HMIControlButtonVM? stopButton;
|
||||
|
||||
[ObservableProperty]
|
||||
private E_BMS_CONTROL_MODE bmsControlMode;
|
||||
|
||||
[ObservableProperty]
|
||||
public ObservableCollection<BMSControlModeEntry> reqBMSControlModes =
|
||||
[
|
||||
new BMSControlModeEntry(E_BMS_CONTROL_MODE.AUTO_REMOTE, "Auto Remote"),
|
||||
new BMSControlModeEntry(E_BMS_CONTROL_MODE.AUTO_LOCAL, "Auto Local"),
|
||||
new BMSControlModeEntry(E_BMS_CONTROL_MODE.SAFETY_CHECK, "Safety Check"),
|
||||
new BMSControlModeEntry(E_BMS_CONTROL_MODE.CAPACITY_TEST, "Capacity Test"),
|
||||
new BMSControlModeEntry(E_BMS_CONTROL_MODE.MANUAL, "Manual")
|
||||
];
|
||||
|
||||
[ObservableProperty]
|
||||
private BMSControlModeEntry selectedControlMode;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool canChangeControlMode;
|
||||
|
||||
private readonly string? _variableName;
|
||||
|
||||
private readonly IAdsManager? _adsManager;
|
||||
|
||||
public AutomaticModePageVM()
|
||||
{
|
||||
StartButton = new HMIControlButtonVM();
|
||||
StopButton = new HMIControlButtonVM();
|
||||
SelectedControlMode = ReqBMSControlModes[1];
|
||||
canChangeControlMode = true;
|
||||
}
|
||||
|
||||
public AutomaticModePageVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
|
||||
//StartButton = new HMIControlButtonVM(_adsManager, _variableName + ".stStartAutoButton");
|
||||
//StopButton = new HMIControlButtonVM(_adsManager, _variableName + ".stStopAutoButton");
|
||||
|
||||
SelectedControlMode = ReqBMSControlModes[1];
|
||||
|
||||
_adsManager.Register("GVL_SCADA.eCurrentControlMode", CurrentControlModeChanged);
|
||||
_adsManager.Register("GVL_SCADA.xCanChangeControlMode", CCCMChanged);
|
||||
|
||||
_adsManager.Register(_variableName + ".diSetpointAutomatic", SetpointChanged);
|
||||
}
|
||||
|
||||
private void SetpointChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
Setpoint = (int)e.Value;
|
||||
}
|
||||
|
||||
private void CCCMChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
CanChangeControlMode = (bool)e.Value;
|
||||
}
|
||||
|
||||
private void CurrentControlModeChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
BmsControlMode = (E_BMS_CONTROL_MODE)e.Value;
|
||||
SelectedControlMode.eMode = BmsControlMode;
|
||||
SelectedControlMode.Name = "Test";
|
||||
}
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
StartButton?.Dispose();
|
||||
StartButton = null;
|
||||
StopButton?.Dispose();
|
||||
StopButton = null;
|
||||
|
||||
_adsManager?.Deregister("GVL_SCADA.eCurrentControlMode", CurrentControlModeChanged);
|
||||
_adsManager?.Deregister("GVL_SCADA.xCanChangeControlMode", CCCMChanged);
|
||||
|
||||
_adsManager?.Deregister(_variableName + ".diSetpointAutomatic", SetpointChanged);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void StartAutomatic()
|
||||
{
|
||||
_adsManager?.WriteValue(_variableName + ".diSetpointAutomatic", Setpoint);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void StopAutomatic()
|
||||
{
|
||||
_adsManager?.WriteValue(_variableName + ".diSetpointAutomatic", 0);
|
||||
Setpoint = 0;
|
||||
}
|
||||
|
||||
public static ValidationResult ValidatePower(int power, ValidationContext context)
|
||||
{
|
||||
if (power < -40000 || power > 40000)
|
||||
return new("Must be between -40.000 and +40.000");
|
||||
else
|
||||
return ValidationResult.Success!;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user