2026-06-05 13:44:39 +09:00

364 lines
13 KiB
C#

using Aurora;
using Aurora.Api;
using Aurora.Api.Manager;
using Aurora.View;
using System;
using System.Data;
using System.Linq;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using static AuroraLaser.Amplitude.LaserSatsumaDisplay;
namespace AuroraLaser.Amplitude
{
/*
* Laser UI추가 작업
* 1. Laser Control 및 Monitor를 하기 위하여 UI Class
* */
public class UCLaserControllerViewModel : NotifyPropertyChangedBase
{
public ICommand CMD_VisibleChanged { get; }
public ICommand CMD_SaveRecipes { get; }
public ICommand CMD_SaveConfigs { get; }
public ICommand CMD_LaserOnOff { get; }
public ICommand CMD_SetAmplifier { get; }
public ICommand CMD_ShowSettingView { get; }
private bool isActivated = false;
public bool IsActivated {
get => isActivated;
set {
if (isActivated != value) {
isActivated = value;
HandleActivationChange(value);
NotifyPropertyChanged("IsActivated");
}
}
}
IAuroraEnvironment Aurora;
//public DelegateCommand EnterCommand { get; private set; }
public ICommand CMD_EnterCommand { get; }
private WinLaserSettingView m_WinLaserSettingView = null;
private readonly LaserSatsumaDisplay m_LaserDevice = null;
private readonly IDeviceManager m_DeviceManager;
private readonly IRecipeManager m_RecipeManager;
private readonly string m_RecipeId;
internal readonly ISequence TestSeq = null;
//readonly IDisposable _DisposableEvent;
private string m_strLaserStatus = "Laser Off";
public string LaserStatus { get => m_strLaserStatus; set => SetProperty(ref m_strLaserStatus, value); }
private DispatcherTimer MonitorTimer;
private bool m_bInterlock = false;
public bool IsInterlock { get => m_bInterlock; set => SetProperty(ref m_bInterlock, value); }
private bool m_bSelf_Test = false;
public bool IsSelfTest { get => m_bSelf_Test; set => SetProperty(ref m_bSelf_Test, value); }
private bool m_bModelock = false;
public bool IsModelock { get => m_bModelock; set => SetProperty(ref m_bModelock, value); }
private bool m_bFront_End_Ready = false;
public bool IsFrontEndReady { get => m_bFront_End_Ready; set => SetProperty(ref m_bFront_End_Ready, value); }
private bool m_bOscillator_Ready = false;
public bool IsOscillatorReady { get => m_bOscillator_Ready; set => SetProperty(ref m_bOscillator_Ready, value); }
private bool m_bAmplifier_Ready = false;
public bool IsAmplifierReady { get => m_bAmplifier_Ready; set => SetProperty(ref m_bAmplifier_Ready, value); }
private bool m_bKey = false;
public bool IsKey { get => m_bKey; set => SetProperty(ref m_bKey, value); }
private bool m_bStatus = false;
public bool IsStatus { get => m_bStatus; set => SetProperty(ref m_bStatus, value); }
private bool m_bShutter_Status;
public bool IsShutter { get => m_bShutter_Status; set => SetProperty(ref m_bShutter_Status, value); }
private ushort m_usPulsePicker;
public ushort PulsePicker { get => m_usPulsePicker; set => SetProperty(ref m_usPulsePicker, value); }
private ushort m_usExternalModulator = 0;
public ushort ExternalModulator { get => m_usExternalModulator; set => SetProperty(ref m_usExternalModulator, value); }
private double m_dOutputPower = 0.0;
public double OutputPower { get => m_dOutputPower; set => SetProperty(ref m_dOutputPower, value); }
private double m_dAmplifier_Write = 0.0;
public double Amplifier_Write { get => m_dAmplifier_Write; set => SetProperty(ref m_dAmplifier_Write, value); }
// Oscillator
private ushort m_usOscillator_Value = 0;
public ushort Oscillator_Value { get => m_usOscillator_Value; set => SetProperty(ref m_usOscillator_Value, value); }
private double m_dOscillator_Temp = 0.0;
public double Oscillator_Temp { get => m_dOscillator_Temp; set => SetProperty(ref m_dOscillator_Temp, value); }
private ushort m_dOscillator_PowerLD = 0;
public ushort Oscillator_PowerLD { get => m_dOscillator_PowerLD; set => SetProperty(ref m_dOscillator_PowerLD, value); }
// Preamp1
private ushort m_usPreamp1_Value = 0;
public ushort Preamp1_Value { get => m_usPreamp1_Value; set => SetProperty(ref m_usPreamp1_Value, value); }
private double m_dPreamp1_Temp = 0.0;
public double Preamp1_Temp { get => m_dPreamp1_Temp; set => SetProperty(ref m_dPreamp1_Temp, value); }
private ushort m_dPreamp1_PowerLD = 0;
public ushort Preamp1_PowerLD { get => m_dPreamp1_PowerLD; set => SetProperty(ref m_dPreamp1_PowerLD, value); }
// Amplifier
private double m_usAmplifier_Value = 0;
public double Amplifier_Value { get => m_usAmplifier_Value; set => SetProperty(ref m_usAmplifier_Value, value); }
//private double m_dAmplifier_Temp = 0.0;
public double Amplifier_Temp { get => m_dPreamp1_Temp; set => SetProperty(ref m_dPreamp1_Temp, value); }
private double m_dAmplifier_PowerLD = 0;
public double Amplifier_PowerLD { get => m_dAmplifier_PowerLD; set => SetProperty(ref m_dAmplifier_PowerLD, value); }
private IRecipeItem m_LaserRecipe;
public IRecipeItem LaserRecipe { get => m_LaserRecipe; set => SetProperty(ref m_LaserRecipe, value); }
public IDeviceConfig DevConfig
=> m_LaserDevice == null ? null : m_DeviceManager.GetDeviceConfig(m_LaserDevice.DeviceId);
public UCLaserControllerViewModel(IAuroraEnvironment aurora, string deviceId, string recipeId)
{
Aurora = aurora;
m_DeviceManager = aurora.DeviceManager;
m_RecipeManager = aurora.RecipeManager;
m_LaserDevice = m_DeviceManager[deviceId] as LaserSatsumaDisplay;
m_RecipeId = recipeId;
m_LaserRecipe = aurora.RecipeManager[recipeId];
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
CMD_SaveRecipes = new DelegateCommand(SaveRecipes);
CMD_SaveConfigs = new DelegateCommand(SaveConfigs);
CMD_SetAmplifier = new DelegateCommand(SetAmplifier);
CMD_LaserOnOff = new DelegateCommand(LaserOnOff);
CMD_ShowSettingView = new DelegateCommand(ShowSettingView);
CMD_EnterCommand = new DelegateCommand(EnterKey);
//OutputPower = "45.6";
MonitorTimer = new DispatcherTimer();
MonitorTimer.Tick += OnMonitoring;
MonitorTimer.Interval = TimeSpan.FromMilliseconds(300);
StartMonitoring();
_ = Observable.Merge(
aurora.EventObservable.AsObservable(AuroraSysEvent.SYS_DEVICE_ACTIVATED),
aurora.EventObservable.AsObservable(AuroraSysEvent.SYS_DEVICE_DEACTIVATED)
).Where(
x => x.Param as string == m_LaserDevice?.DeviceId
).ObserveOnDispatcher().Subscribe(
x => OnActiveChanged()
);
}
private void HandleActivationChange(bool value)
{
_ = value ? m_LaserDevice.Activate() : m_LaserDevice.Deactivate();
isActivated = m_LaserDevice.IsActivated;
}
protected void OnPropertyChanged(string propertyName)
{
}
private void SaveConfigs(object obj)
{
m_DeviceManager.SaveDeviceConfig(m_LaserDevice.DeviceId);
}
private void SetAmplifier(object obj)
{
//double dValue = 0.0;
//Aurora.EventPublisher.Publish(new EventMessage("", AuroraSysEvent.SYS_MAIN_ALARM, true));
//Aurora.EventPublisher.Publish(new EventMessage("", AuroraSysEvent.SYS_MAIN_LAMP, eTowerLamp.RED));
//LaserDevice = m_DeviceManager[CommonDeviceIds.Laser];
}
private void EnterKey(object obj)
{
//string sd = obj.ToString();
MessageBox.Show(Amplifier_Write.ToString());
}
private void LaserOnOff(object obj)
{
if (LaserStatus == "Laser On") {
//m_LaserDevice.LaserOnOff(false);
LaserStatus = "Laser Off";
} else {
//m_LaserDevice.LaserOnOff(true);
LaserStatus = "Laser On";
}
}
private void ShowSettingView(object obj)
{
if (m_LaserDevice.IsActivated == true) {
m_WinLaserSettingView = new WinLaserSettingView(Aurora, m_LaserDevice.DeviceId);
m_WinLaserSettingView.Show();
}
}
private void SaveRecipes(object obj)
{
//m_RecipeManager.SaveRecipe(m_RecipeId, m_LaserRecipe);
//LaserRecipe recipe = m_LaserRecipe as LaserRecipe;
//m_LaserDevice.ChangeModelRecipe(recipe.ChangeToDeviceArray());
}
public void StopMonitoring()
{
MonitorTimer.Stop();
}
public void StartMonitoring()
{
MonitorTimer.Start();
}
private void OnMonitoring(object sender, EventArgs e)
{
if (!m_LaserDevice.IsActivated) {
return;
}
IsInterlock = m_LaserDevice.DiscreteInputs[(int)e_DISCRETE_INPUT.e_INTERLOCK];
//IsSelfTest = m_LaserDevice.DiscreteInputs[(int)LaserDevice.e_DISCRETE_INPUT.e_INTERLOCK];
IsModelock = m_LaserDevice.DiscreteInputs[(int)e_DISCRETE_INPUT.e_MODE_LOCK];
IsFrontEndReady = m_LaserDevice.DiscreteInputs[(int)e_DISCRETE_INPUT.e_FRONT_END_READY];
IsOscillatorReady = m_LaserDevice.DiscreteInputs[(int)e_DISCRETE_INPUT.e_OSCILLATOR_READY];
//IsAmplifierReady = m_LaserDevice.DiscreteInputs[(int)LaserDevice.e_DISCRETE_INPUT.];
// Controller Status
IsKey = m_LaserDevice.DiscreteInputs[(int)e_DISCRETE_INPUT.e_KEY];
//IsStatus = m_LaserDevice.DiscreteInputs[(int)LaserDevice.e_DISCRETE_INPUT.e_OSCILLATOR_READY];
IsStatus = m_LaserDevice.IsActivated;
IsShutter = m_LaserDevice.DiscreteInputs[(int)e_DISCRETE_INPUT.e_SHUTTER];
// Holding Register
//PulsePicker = m_LaserDevice.HoldingRegisteres[(int)LaserDevice.e_HOLDING_REGISTER.e_PULSE_PICKER_FREQUENCY_SET];
//ExternalModulator = m_LaserDevice.HoldingRegisteres[(int)LaserDevice.e_HOLDING_REGISTER.e_EXTERNAL_MODULATOR_WIDTH];
OutputPower = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_OUTPUPT_POWER] / 1000.0;
// Oscillator
Oscillator_Value = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_OSCILLATOR_LD_CURRENT];
Oscillator_Temp = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_OSCILLATOR_LD_TEMP];
Oscillator_PowerLD = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_OSCILLATOR_LD_POWER];
PulsePicker = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_PULSE_PICKER_FREQUENCY];
// Preamp1
Preamp1_Value = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_PREAMP1_LD_CURRENT];
Preamp1_Temp = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_PREAMP1_LD_TEMP];
Preamp1_PowerLD = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_PREAMP1_LD_POWER];
Amplifier_Value = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_AMPLIFIER_LD_CURRENT] / 1000.0;
Amplifier_Temp = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_AMPLIFIER_LD_TEMP];
Amplifier_PowerLD = m_LaserDevice.InputRegisteres[(int)e_INPUT_REGISTER.e_AMPLIFIER_LD_POWER] / 1000.0;
//foreach (var motor in MotorList)
//{
// var acsmotor = motor.Motor as ACSMotor;
// if (!motor.IsInit)
// {
// //motor.IsInit = acsmotor.IsInitiallized();
// }
//}
}
public bool SomeConditionalProperty {
get { return false;/*...*/ }
set {
//...
OnPropertyChanged(nameof(SomeConditionalProperty));
//Because Background is dependent on this property.
OnPropertyChanged(nameof(Background));
}
}
public Brush Background =>
SomeConditionalProperty ? Brushes.Pink : Brushes.LightGreen;
private void OnSeqEvent(EventMessage obj)
{
//Weight = (double)obj.Param;
int nID = (int)obj.Param;
}
private void VisibleChanged(object obj)
{
if ((bool)obj) {
MonitorTimer.Start();
} else {
MonitorTimer.Stop();
}
}
private void OnActiveChanged()
{
IsActivated = m_LaserDevice.IsActivated;
if (m_LaserDevice.IsActivated) {
//HeadPara = LaserScanner.GetHeadPara();
}
}
//~UCLaserControllerViewModel()
//{
// _DisposableEvent?.Dispose();
//}
}
}