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!;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Heisig.HMI.AdsManager;
|
||||
|
||||
namespace UniperHMI
|
||||
{
|
||||
public sealed partial class BatteryOverviewPageVM : ObservableObject, IDisposable
|
||||
{
|
||||
[ObservableProperty]
|
||||
private StringControlButtonVM? string1VM;
|
||||
|
||||
[ObservableProperty]
|
||||
private StringControlButtonVM? string2VM;
|
||||
|
||||
[ObservableProperty]
|
||||
private StringControlButtonVM? dummyStringVM;
|
||||
|
||||
private readonly IAdsManager? _adsManager;
|
||||
|
||||
public BatteryOverviewPageVM()
|
||||
{
|
||||
string1VM = new StringControlButtonVM();
|
||||
string2VM = new StringControlButtonVM();
|
||||
}
|
||||
|
||||
public BatteryOverviewPageVM(IAdsManager adsManager)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
string1VM = new StringControlButtonVM(adsManager, "GVL_SCADA.stHMIInterface[0]");
|
||||
string2VM = new StringControlButtonVM(adsManager, "GVL_SCADA.stHMIInterface[1]");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
String1VM?.Dispose();
|
||||
String1VM = null;
|
||||
|
||||
String2VM?.Dispose();
|
||||
String2VM = null;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void String1Clicked()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateMessage("GVL_SCADA.stHMIInterface[0]", typeof(StringOverviewPage), "String 1"));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void String2Clicked()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateMessage("GVL_SCADA.stHMIInterface[1]", typeof(StringOverviewPage), "String 2"));
|
||||
}
|
||||
}
|
||||
}
|
||||
109
uniper_hmi/UniperHMI/Pages/ViewModels/EventsPageVM.cs
Normal file
109
uniper_hmi/UniperHMI/Pages/ViewModels/EventsPageVM.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using TcEventLoggerAdsProxyLib;
|
||||
|
||||
namespace UniperHMI
|
||||
{
|
||||
public partial class EventData : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
public uint id;
|
||||
|
||||
[ObservableProperty]
|
||||
public string? message;
|
||||
|
||||
[ObservableProperty]
|
||||
public DateTime raised;
|
||||
|
||||
[ObservableProperty]
|
||||
public DateTime cleared;
|
||||
|
||||
[ObservableProperty]
|
||||
public DateTime confirmed;
|
||||
};
|
||||
|
||||
public sealed partial class EventsPageVM : ObservableObject
|
||||
{
|
||||
public ObservableCollection<EventData> CurrentEvents { get; private set; } = [];
|
||||
private readonly object _lock = new();
|
||||
|
||||
private readonly TcEventLogger _logger;
|
||||
|
||||
[ObservableProperty]
|
||||
private EventData? currentEvent;
|
||||
|
||||
// 599264352000000000 ticks is a date used by beckhoff for events that didnt happen up to this point
|
||||
private const long NoTime = 599264352000000000;
|
||||
|
||||
|
||||
public EventsPageVM(TcEventLogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
_logger.AlarmRaised += SimpleAlarmRaisedEvent;
|
||||
_logger.AlarmCleared += SimpleAlarmClearedEvent;
|
||||
_logger.AlarmConfirmed += SimpleConfirmedAlarmEvent;
|
||||
|
||||
_logger.Connect("10.103.32.50.1.1");
|
||||
|
||||
GetAllActiveEvents();
|
||||
}
|
||||
|
||||
private void RebuildCurrentEventsList()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
CurrentEvents.Clear();
|
||||
}
|
||||
|
||||
GetAllActiveEvents();
|
||||
}
|
||||
|
||||
private void SimpleConfirmedAlarmEvent(TcAlarm alarm, bool remove)
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(RebuildCurrentEventsList);
|
||||
}
|
||||
|
||||
private void SimpleAlarmClearedEvent(TcAlarm alarm, bool remove)
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(RebuildCurrentEventsList);
|
||||
}
|
||||
|
||||
private void SimpleAlarmRaisedEvent(TcAlarm alarm)
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(RebuildCurrentEventsList);
|
||||
}
|
||||
|
||||
private void GetAllActiveEvents()
|
||||
{
|
||||
EventData eventData;
|
||||
List<EventData> tempEventList = [];
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
foreach (var alarm in _logger.ActiveAlarms)
|
||||
{
|
||||
eventData = new()
|
||||
{
|
||||
Id = alarm.EventId,
|
||||
Message = alarm.GetText(1033),
|
||||
Raised = alarm.TimeRaised,
|
||||
Cleared = alarm.TimeCleared,
|
||||
Confirmed = alarm.TimeConfirmed
|
||||
};
|
||||
|
||||
tempEventList.Add(eventData);
|
||||
}
|
||||
|
||||
IEnumerable<EventData> _eventQuery =
|
||||
from data in tempEventList
|
||||
orderby data.Raised descending
|
||||
select data;
|
||||
|
||||
CurrentEvent = _eventQuery.FirstOrDefault();
|
||||
CurrentEvents = new ObservableCollection<EventData>(_eventQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Heisig.HMI.AdsManager;
|
||||
using UniperHMI.OwnControls;
|
||||
|
||||
namespace UniperHMI
|
||||
{
|
||||
public sealed partial class ModuleOverviewPageVM : ObservableObject, IDisposable
|
||||
{
|
||||
[ObservableProperty]
|
||||
private UnitControlButtonVM unit1;
|
||||
|
||||
[ObservableProperty]
|
||||
private UnitControlButtonVM unit2;
|
||||
|
||||
[ObservableProperty]
|
||||
private UnitControlButtonVM unit3;
|
||||
|
||||
[ObservableProperty]
|
||||
private UnitControlButtonVM unit4;
|
||||
|
||||
private readonly IAdsManager? _adsManager;
|
||||
private readonly string? _variableName;
|
||||
|
||||
public ModuleOverviewPageVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
|
||||
unit1 = new(_adsManager, _variableName + ".stHMIInterfaceUnit1");
|
||||
unit2 = new(_adsManager, _variableName + ".stHMIInterfaceUnit2");
|
||||
unit3 = new(_adsManager, _variableName + ".stHMIInterfaceUnit3");
|
||||
unit4 = new(_adsManager, _variableName + ".stHMIInterfaceUnit4");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Unit1?.Dispose();
|
||||
Unit2?.Dispose();
|
||||
Unit3?.Dispose();
|
||||
Unit4?.Dispose();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void Unit1Clicked()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateMessage(_variableName + ".stHMIInterfaceUnit1", typeof(UnitOverviewPage), "Unit 1"));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void Unit2Clicked()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateMessage(_variableName + ".stHMIInterfaceUnit2", typeof(UnitOverviewPage), "Unit 2"));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void Unit3Clicked()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateMessage(_variableName + ".stHMIInterfaceUnit3", typeof(UnitOverviewPage), "Unit 3"));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void Unit4Clicked()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateMessage(_variableName + ".stHMIInterfaceUnit4", typeof(UnitOverviewPage), "Unit 4"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Heisig.HMI.AdsManager;
|
||||
|
||||
namespace UniperHMI;
|
||||
|
||||
public sealed partial class StringOverviewPageVM : ObservableObject, IDisposable
|
||||
{
|
||||
[ObservableProperty]
|
||||
private ModuleControlButtonVM module1;
|
||||
|
||||
[ObservableProperty]
|
||||
private ModuleControlButtonVM module2;
|
||||
|
||||
[ObservableProperty]
|
||||
private ModuleControlButtonVM module3;
|
||||
|
||||
private readonly IAdsManager? _adsManager;
|
||||
private readonly string? _variableName;
|
||||
|
||||
public StringOverviewPageVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
|
||||
module1 = new(_adsManager, _variableName + ".stHMIInterfaceModule1");
|
||||
module2 = new(_adsManager, _variableName + ".stHMIInterfaceModule2");
|
||||
module3 = new(_adsManager, _variableName + ".stHMIInterfaceModule3");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Module1?.Dispose();
|
||||
Module2?.Dispose();
|
||||
Module3?.Dispose();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Module1Clicked()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateMessage(_variableName + ".stHMIInterfaceModule1", typeof(ModuleOverviewPage), "Module 1"));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Module2Clicked()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateMessage(_variableName + ".stHMIInterfaceModule2", typeof(ModuleOverviewPage), "Module 2"));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Module3Clicked()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new NavigateMessage(_variableName + ".stHMIInterfaceModule3", typeof(ModuleOverviewPage), "Module 3"));
|
||||
}
|
||||
}
|
||||
31
uniper_hmi/UniperHMI/Pages/ViewModels/UnitOverviewPageVM.cs
Normal file
31
uniper_hmi/UniperHMI/Pages/ViewModels/UnitOverviewPageVM.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Heisig.HMI.AdsManager;
|
||||
|
||||
namespace UniperHMI;
|
||||
|
||||
public sealed partial class UnitOverviewPageVM : ObservableObject, IDisposable
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string unitName;
|
||||
|
||||
[ObservableProperty]
|
||||
private UnitDetailsControlVM unitControlVM;
|
||||
|
||||
private readonly IAdsManager? _adsManager;
|
||||
private readonly string? _variableName;
|
||||
|
||||
public UnitOverviewPageVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
|
||||
unitControlVM = new(_adsManager, _variableName);
|
||||
|
||||
unitName = "Unit X";
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UnitControlVM?.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user