177 lines
6.9 KiB
C#
177 lines
6.9 KiB
C#
using Aurora.View;
|
|
using AuroraLaser.Coherent;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Windows.Input;
|
|
using System.Windows.Threading;
|
|
|
|
namespace AuroraLaser.Views
|
|
{
|
|
public class UCLaserCompactInfoViewModel : NotifyPropertyChangedBase
|
|
{
|
|
public ICommand CMD_VisibleChanged { get; }
|
|
public ICommand CMD_AlarmReset { get; }
|
|
|
|
private string _laserInfo;
|
|
public string LaserInfo { get => _laserInfo; set => SetProperty(ref _laserInfo, value); }
|
|
|
|
private string _serialNumber;
|
|
public string SerialNumber { get => _serialNumber; set => SetProperty(ref _serialNumber, value); }
|
|
|
|
private bool _isActivated;
|
|
public bool IsActivated { get => _isActivated; set => SetProperty(ref _isActivated, value); }
|
|
|
|
private string _laserModePeltierCtrl;
|
|
public string LaserModePeltierCtrl { get => _laserModePeltierCtrl; set => SetProperty(ref _laserModePeltierCtrl, value); }
|
|
|
|
private bool _isPeltierCtrlHeatingCooling;
|
|
public bool IsPeltierCtrlHeatingCooling { get => _isPeltierCtrlHeatingCooling; set => SetProperty(ref _isPeltierCtrlHeatingCooling, value); }
|
|
|
|
private bool _isCurrentSetExternal;
|
|
public bool IsCurrentSetExternal { get => _isCurrentSetExternal; set => SetProperty(ref _isCurrentSetExternal, value); }
|
|
|
|
private bool _isLaserCtrlExternal;
|
|
public bool IsLaserCtrlExternal { get => _isLaserCtrlExternal; set => SetProperty(ref _isLaserCtrlExternal, value); }
|
|
|
|
private bool _isPulseOn;
|
|
public bool IsPulseOn { get => _isPulseOn; set => SetProperty(ref _isPulseOn, value); }
|
|
|
|
private bool _isVT100On;
|
|
public bool IsVT100On { get => _isVT100On; set => SetProperty(ref _isVT100On, value); }
|
|
|
|
private double _laserActualPower;
|
|
public double LaserActualPower { get => _laserActualPower; set => SetProperty(ref _laserActualPower, value); }
|
|
|
|
private int _laserActualTemp;
|
|
public int LaserActualTemp { get => _laserActualTemp; set => SetProperty(ref _laserActualTemp, value); }
|
|
|
|
private string _errorMsg;
|
|
public string ErrorMsg { get => _errorMsg; set => SetProperty(ref _errorMsg, value); }
|
|
|
|
private string _ErrorMsgFgColor;
|
|
public string ErrorMsgFgColor { get => _ErrorMsgFgColor; set => SetProperty(ref _ErrorMsgFgColor, value); }
|
|
|
|
private bool _isPowerOn;
|
|
public bool IsPowerOn { get => _isPowerOn; set => SetProperty(ref _isPowerOn, value); }
|
|
|
|
private bool _isLaserOn;
|
|
public bool IsLaserOn { get => _isLaserOn; set => SetProperty(ref _isLaserOn, value); }
|
|
|
|
private bool _isLaserErrStatus;
|
|
public bool IsLaserErrStatus { get => _isLaserErrStatus; set => SetProperty(ref _isLaserErrStatus, value); }
|
|
|
|
private bool _isLaserFatalErr;
|
|
public bool IsLaserFatalErr { get => _isLaserFatalErr; set => SetProperty(ref _isLaserFatalErr, value); }
|
|
|
|
private bool _isLaserEmission;
|
|
public bool IsLaserEmission { get => _isLaserEmission; set => SetProperty(ref _isLaserEmission, value); }
|
|
|
|
Stopwatch swErrMsg = new Stopwatch();
|
|
//===================================================
|
|
|
|
private DispatcherTimer MonitorTimer;
|
|
private LaserCompact _laser;
|
|
|
|
public UCLaserCompactInfoViewModel(LaserCompact laser)
|
|
{
|
|
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
|
|
CMD_AlarmReset = new DelegateCommand(OnAlarmReset);
|
|
|
|
_laser = laser;
|
|
|
|
Init();
|
|
|
|
MonitorTimer = new DispatcherTimer();
|
|
MonitorTimer.Interval = TimeSpan.FromMilliseconds(100); // 10 [Hz]
|
|
MonitorTimer.Tick += OnMonitoring;
|
|
|
|
swErrMsg.Restart();
|
|
}
|
|
|
|
private void VisibleChanged(object obj) // 화면 전환 시 동작하는 곳
|
|
{
|
|
bool visible = (bool)obj;
|
|
if (visible) {
|
|
MonitorTimer.Start();
|
|
} else {
|
|
MonitorTimer.Stop();
|
|
}
|
|
}
|
|
|
|
private void OnAlarmReset(object obj)
|
|
{
|
|
var list = _laser.GetAlarmList();
|
|
if (list != null && list.Count > 0) { _laser.ClearAlarms(); }
|
|
_laser.ErrorReset();
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
LaserInfo = "Laser Info: " + _laser.DeviceId;
|
|
LaserModePeltierCtrl = "Peltier Ctrl : Only Cooling";
|
|
_ErrorMsgFgColor = "Black";
|
|
|
|
IsPowerOn = false;
|
|
IsLaserOn = false;
|
|
IsLaserErrStatus = false;
|
|
IsLaserFatalErr = false;
|
|
IsLaserEmission = false;
|
|
|
|
IsPeltierCtrlHeatingCooling = false;
|
|
IsCurrentSetExternal = false;
|
|
IsLaserCtrlExternal = false;
|
|
IsPulseOn = false;
|
|
IsVT100On = false;
|
|
}
|
|
|
|
private void OnMonitoring(object sender, EventArgs e)
|
|
{
|
|
IsActivated = _laser.IsActivated;
|
|
if (IsActivated) {
|
|
var _laserStatus = _laser.GetLaserStatusInfo();
|
|
// raw data: [0, 1000] [%] => [0, 100] 범위로 변경
|
|
LaserActualPower = _laserStatus.PowerValue * 0.1;
|
|
LaserActualTemp = _laserStatus.Temp;
|
|
SerialNumber = _laserStatus.SerialNumber;
|
|
// Test
|
|
//_laserStatus.Power_On = true;
|
|
IsPowerOn = _laserStatus.bPowerOn;
|
|
//_laserStatus.Laser_On = true;
|
|
IsLaserOn = _laserStatus.bLaserOn;
|
|
IsLaserErrStatus = _laserStatus.bErrorStatus;
|
|
IsLaserFatalErr = _laserStatus.bFatalError;
|
|
IsLaserEmission = _laserStatus.bEmission;
|
|
|
|
var _laserMode = _laser.GetLaserModeInfo();
|
|
IsPeltierCtrlHeatingCooling = _laserMode.bPeltierCooler_HeatingCooling;
|
|
IsCurrentSetExternal = _laserMode.bCurrent_Set_External;
|
|
IsLaserCtrlExternal = _laserMode.bLaser_Control_External;
|
|
IsPulseOn = _laserMode.bPulserOn;
|
|
IsVT100On = _laserMode.bVT100On;
|
|
|
|
var _laserErrMsg = _laser.GetLaserErrMsgInfo();
|
|
// Test
|
|
//_laserErrMsg.ErrMsg = "This is test";
|
|
if (ErrorMsg != _laserErrMsg.ErrMsg) {
|
|
ErrorMsg = _laserErrMsg.ErrMsg;
|
|
}
|
|
|
|
if (swErrMsg.ElapsedMilliseconds > 500) {
|
|
if (_laserErrMsg.ErrMsg == string.Empty) {
|
|
if (ErrorMsgFgColor != "Black") {
|
|
ErrorMsgFgColor = "Black";
|
|
}
|
|
} else { // LUKAS: 0.5초 간격으로, 빨간색 -> 노란색 순서로 깜박임
|
|
if (ErrorMsgFgColor != "Red") {
|
|
ErrorMsgFgColor = "Red";
|
|
} else {
|
|
ErrorMsgFgColor = "Yellow";
|
|
}
|
|
}
|
|
swErrMsg.Restart(); // 블링크 목적
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|