using Aurora; using Aurora.Api; using Aurora.View; using AuroraDeviceCommon.Views; using System; using System.Collections.ObjectModel; using System.Windows.Input; using System.Windows.Threading; namespace AuroraLaser.Coherent { public class UCCoherentHyperRapidLaserDeviceViewModel : BaseDeviceViewModel { public ICommand CMD_Connect { get; } public ICommand CMD_SetShutter { get; } public ICommand CMD_SetInternalShutter { get; } public ICommand CMD_StartSystem { get; } public ICommand CMD_StopSystem { get; } public ICommand CMD_ClearSystem { get; } public ICommand CMD_SetTransmission { get; } public ICommand CMD_SetPower { get; } public ICommand CMD_UmacLaserPowerOn { get; } public ICommand CMD_UmacLaserPowerOff { get; } public bool _IsConnection; public bool IsConnection { get => _IsConnection; set => SetProperty(ref _IsConnection, value); } public string _LaserConnect; public string LaserConnect { get => _LaserConnect; set => SetProperty(ref _LaserConnect, value); } public bool _IsSystemActivated; public bool IsSystemActivated { get => _IsSystemActivated; set => SetProperty(ref _IsSystemActivated, value); } public string _curSystemStatus; public string curSystemStatus { get => _curSystemStatus; set => SetProperty(ref _curSystemStatus, value); } public bool _IsKeySwitchOn; public bool IsKeySwitchOn { get => _IsKeySwitchOn; set => SetProperty(ref _IsKeySwitchOn, value); } public bool _IsShutterOpened; public bool IsShutterOpened { get => _IsShutterOpened; set => SetProperty(ref _IsShutterOpened, value); } public bool _IsInternalShutterOpened; public bool IsInternalShutterOpened { get => _IsInternalShutterOpened; set => SetProperty(ref _IsInternalShutterOpened, value); } public bool _IsSystemReady; public bool IsSystemReady { get => _IsSystemReady; set => SetProperty(ref _IsSystemReady, value); } public double _CurOutputPower; public double CurOutputPower { get => _CurOutputPower; set => SetProperty(ref _CurOutputPower, value); } public double _CurTransmission; public double CurTransmission { get => _CurTransmission; set => SetProperty(ref _CurTransmission, value); } public double _OutputPower; public double OutputPower { get => _OutputPower; set => SetProperty(ref _OutputPower, value); } public double _Transmission; public double Transmission { get => _Transmission; set => SetProperty(ref _Transmission, value); } public string _CurAmp; public string CurAmp { get => _CurAmp; set => SetProperty(ref _CurAmp, value); } private readonly DispatcherTimer MonitorTimer; private readonly IExternalShutter _ExternalShutter; private readonly IExternalLaserShot _ExternalShot; private string LaserDeviceId; private ObservableCollection _LaserLogMessage; public ObservableCollection LaserLogMessage { get => _LaserLogMessage; } private bool _ScreenEnable = true; public bool ScreenEnable { get => _ScreenEnable; set => SetProperty(ref _ScreenEnable, value); } public UCCoherentHyperRapidLaserDeviceViewModel(IAuroraEnvironment aurora, Device laser, IExternalShutter externalShutter, IExternalLaserShot externalShot) : base(aurora, laser) { CMD_Connect = new DelegateCommand(Connect); CMD_SetShutter = new DelegateCommand(SetShutter); CMD_SetInternalShutter = new DelegateCommand(SetInternalShutter); CMD_StartSystem = new DelegateCommand(StartSystem); CMD_StopSystem = new DelegateCommand(StopSystem); CMD_ClearSystem = new DelegateCommand(StopSystem); CMD_SetTransmission = new DelegateCommand(SetTransmission); CMD_SetPower = new DelegateCommand(SetPower); CMD_UmacLaserPowerOn = new DelegateCommand(SetUmacLaserPowerOn); CMD_UmacLaserPowerOff = new DelegateCommand(SetUmacLaserPowerOff); _ExternalShutter = externalShutter; _ExternalShot = externalShot; LaserDeviceId = laser.DeviceId; _IsKeySwitchOn = false; _IsShutterOpened = false; _IsSystemReady = false; _OutputPower = 0.0; _CurOutputPower = 0.0; _CurTransmission = 0.0; _CurAmp = ""; _LaserConnect = ""; _IsSystemActivated = false; _curSystemStatus = ""; _LaserLogMessage = new ObservableCollection(); MonitorTimer = new DispatcherTimer(); MonitorTimer.Tick += OnMonitoring; MonitorTimer.Interval = TimeSpan.FromMilliseconds(1000); } private void AddLaserLog(string _message) { if (LaserLogMessage.Count > 100) { LaserLogMessage.RemoveAt(100); } LaserLogMessage.Insert(0, _message); } protected override void VisibleChanged(object obj) { bool visible = (bool)obj; if (visible) { MonitorTimer.Start(); } else { MonitorTimer.Stop(); } } private bool IsShutterOpenend() { return _ExternalShutter.IsExternalShutterOpened((_Device as HyperRapidLaser).GetLaserNo()); } private void OnMonitoring(object sender, EventArgs e) { if (!_Device.IsActivated) { return; } var laser = _Device as HyperRapidLaser; IsConnection = _Device.IsActivated; if (IsConnection) { LaserConnect = "Connected"; } else { LaserConnect = "Disconnected"; } switch (laser.GetLaserState()) { case (int)HyperRapidLaser._tagLaserState.LASER_STATE_BOOT: IsSystemActivated = false; curSystemStatus = "Boot"; break; case (int)HyperRapidLaser._tagLaserState.LASER_STATE_READY: IsSystemActivated = false; curSystemStatus = "Ready"; break; case (int)HyperRapidLaser._tagLaserState.LASER_STATE_ON: IsSystemActivated = true; curSystemStatus = "On"; if (laser.GetPM() != 2) { laser.SetPM(2); } break; case (int)HyperRapidLaser._tagLaserState.LASER_STATE_FAULT: curSystemStatus = "Fault"; break; } if (IsKeySwitchOn != laser.IsKeySwitchOn()) { IsKeySwitchOn = laser.IsKeySwitchOn(); if (IsKeySwitchOn) AddLaserLog("IsKeySwitchOn : On"); else AddLaserLog("IsKeySwitchOn : Off"); } if (IsShutterOpened != IsShutterOpenend()) { IsShutterOpened = IsShutterOpenend(); if (IsShutterOpened) AddLaserLog("IsShutterOpened : On"); else AddLaserLog("IsShutterOpened : Off"); } if (IsInternalShutterOpened != laser.IsInternalShutterOpened()) { IsInternalShutterOpened = laser.IsInternalShutterOpened(); if (IsInternalShutterOpened) AddLaserLog("IsInternalShutterOpened : On"); else AddLaserLog("IsInternalShutterOpened : Off"); } if (_CurOutputPower != laser.GetOutputAomPercentage()) { CurOutputPower = laser.GetOutputAomPercentage(); } if (_CurTransmission != laser.GetTransmission()) { CurTransmission = laser.GetTransmission(); } CurAmp = string.Format("{0}", laser.GetPM() == 2 ? "Internal & Gated" : "Internal"); var state = laser.GetLaserState(); //IsSystemReady = state == (int)_tagLaserState.LASER_STATE_READY; } private void Connect(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("Connect Click"); var laser = _Device as HyperRapidLaser; // 연결/해제 메서드 없음 } private void SetShutter(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("SetShutter Click"); var laser = _Device as HyperRapidLaser; ////laser.SetInternalShutterOpen(IsShutterOpened); _ExternalShutter.SetExternalShutterOpen(laser.GetLaserNo(), IsShutterOpened); } private void SetInternalShutter(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("SetInternalShutter Click"); var laser = _Device as HyperRapidLaser; laser.SetInternalShutterOpen(IsInternalShutterOpened); } private void StartSystem(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("StartSystem Click"); var laser = _Device as HyperRapidLaser; laser.SetLaserOn(true); } private void StopSystem(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("StopSystem Click"); var laser = _Device as HyperRapidLaser; laser.SetLaserOn(false); } private void ClearSystem(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("ClearSystem Click"); var laser = _Device as HyperRapidLaser; laser.ClearSystemFault(); } private void SetTransmission(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("SetTransmission Click"); var laser = _Device as HyperRapidLaser; laser.SetTransmission(_Transmission); } private void SetPower(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("SetPower Click"); var laser = _Device as HyperRapidLaser; laser.SetOutputAomPercentage(_OutputPower); } private void SetUmacLaserPowerOn(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("SetPower Click"); var laser = _Device as HyperRapidLaser; _ExternalShutter.SetExternalShutterOpen(laser.GetLaserNo(), true); _ExternalShot.SetLaserShot(laser.GetLaserNo(), true); } private void SetUmacLaserPowerOff(object obj) { if (!_Device.IsActivated) { return; } AddLaserLog("SetPower Click"); var laser = _Device as HyperRapidLaser; _ExternalShutter.SetExternalShutterOpen(laser.GetLaserNo(), false); _ExternalShot.SetLaserShot(laser.GetLaserNo(), false); } } }