LGES-OC5-PtoP-Welder/AuroraDevices/AuroraChiller/SMC/Monitoring/UCLaserManagementMonitoringViewModel.cs
2026-06-05 13:44:39 +09:00

145 lines
4.2 KiB
C#

using Aurora;
using Aurora.Api;
using Aurora.View;
using AuroraChiller;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
namespace AuroraChiller.SMC
{
public class LaserManagement : NotifyPropertyChangedBase
{
public int Index { get; set; }
public string Name { get; set; }
private double currentValue;
public double CurrentValue
{
get { return currentValue; }
set
{
if (currentValue != value)
{
currentValue = value;
NotifyPropertyChanged(nameof(CurrentValue));
}
}
}
private double maxValue;
public double MaxValue
{
get { return maxValue; }
set
{
if (maxValue != value)
{
maxValue = value;
NotifyPropertyChanged(nameof(MaxValue));
}
}
}
private double warning1;
public double Warning1
{
get { return warning1; }
set
{
if (warning1 != value)
{
warning1 = value;
NotifyPropertyChanged(nameof(Warning1));
}
}
}
private double warning2;
public double Warning2
{
get { return warning2; }
set
{
if (warning2 != value)
{
warning2 = value;
NotifyPropertyChanged(nameof(Warning2));
}
}
}
public string Unit { get; set; }
}
public class UCLaserManagementMonitoringViewModel : NotifyPropertyChangedBase
{
public ICommand CMD_VisibleChanged { get; }
public List<LaserManagement> LaserManagementList { get; }
private readonly SmcChiller Chiller;
private readonly ChillerSetting _ChillerSetting;
private readonly DispatcherTimer MonitorTimer;
private int _ListSelectedIndexDegree;
public int ListSelectedIndexDegree { get => _ListSelectedIndexDegree; set => SetProperty(ref _ListSelectedIndexDegree, value); }
public UCLaserManagementMonitoringViewModel(IAuroraEnvironment aurora, string deviceId, string settingId)
{
var devManager = aurora.DeviceManager;
Chiller = devManager[deviceId] as SmcChiller;
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
LaserManagementList = new List<LaserManagement>();
_ChillerSetting = aurora.SettingEntry[settingId] as ChillerSetting;
LaserManagementList.Add(new LaserManagement {
Index = Chiller.DeviceNo,
Name = "칠러_1 교체 남은 시간",
CurrentValue = 0.0,
MaxValue = _ChillerSetting.WATER_TIME_MAX,
Warning1 = _ChillerSetting.WATER_TIME_1,
Warning2 = _ChillerSetting.WATER_TIME_2,
Unit = "Day"
});
MonitorTimer = new DispatcherTimer();
MonitorTimer.Tick += OnMonitoring;
MonitorTimer.Interval = TimeSpan.FromMilliseconds(500);
}
private void OnMonitoring(object sender, EventArgs e)
{
if (!Chiller.IsActivated ||
!Chiller.IsConnected())
return;
//Chiller.GetCurrentTemp(out double curTemp);
Chiller.GetCurrentTemp(1, out double curTemp);
LaserManagementList[0].CurrentValue = curTemp;
LaserManagementList[0].MaxValue = _ChillerSetting.WATER_TIME_MAX;
LaserManagementList[0].Warning1 = _ChillerSetting.WATER_TIME_1;
LaserManagementList[0].Warning2 = _ChillerSetting.WATER_TIME_2;
}
private void VisibleChanged(object obj)
{
bool visible = (bool)obj;
if (visible)
{
MonitorTimer.Start();
}
else
{
MonitorTimer.Stop();
}
}
}
}