122 lines
3.8 KiB
C#
122 lines
3.8 KiB
C#
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;
|
|
|
|
using UniperHMI.Model;
|
|
namespace UniperHMI
|
|
{
|
|
public sealed partial class TrayFeederPageVM : 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 TrayFeederPageVM()
|
|
{
|
|
StartButton = new HMIControlButtonVM();
|
|
StopButton = new HMIControlButtonVM();
|
|
SelectedControlMode = ReqBMSControlModes[1];
|
|
canChangeControlMode = true;
|
|
}
|
|
|
|
public TrayFeederPageVM(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.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;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
StartButton?.Dispose();
|
|
StartButton = null;
|
|
StopButton?.Dispose();
|
|
StopButton = null;
|
|
|
|
_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!;
|
|
}
|
|
}
|
|
}
|