283 lines
11 KiB
C#
283 lines
11 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using Aurora.Api.Manager;
|
|
using Aurora.View;
|
|
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 AuroraLaser
|
|
{
|
|
public class UCLaserDeviceViewModel : NotifyPropertyChangedBase
|
|
{
|
|
Logger Log = new Logger("Laser");
|
|
|
|
#region Xaml Property
|
|
// Get Bit Status
|
|
private bool _bInitComm;
|
|
public bool bInitComm { get => _bInitComm; set => SetProperty(ref _bInitComm, value); }
|
|
private bool _bEmission;
|
|
public bool bEmission { get => _bEmission; set => SetProperty(ref _bEmission, value); }
|
|
private bool _bPilotLaser;
|
|
public bool bPilotLaser { get => _bPilotLaser; set => SetProperty(ref _bPilotLaser, value); }
|
|
private bool _bLaserReady;
|
|
public bool bLaserReady { get => _bLaserReady; set => SetProperty(ref _bLaserReady, value); }
|
|
private bool _bLaserWarning;
|
|
public bool bLaserWarning { get => _bLaserWarning; set => SetProperty(ref _bLaserWarning, value); }
|
|
private bool _bLaserError;
|
|
public bool bLaserError { get => _bLaserError; set => SetProperty(ref _bLaserError, value); }
|
|
|
|
private bool _bEStop;
|
|
public bool bEStop { get => _bEStop; set => SetProperty(ref _bEStop, value); }
|
|
|
|
// Set Bit Status
|
|
private bool _bStartLaser;
|
|
public bool bStartLaser { get => _bStartLaser; set => SetProperty(ref _bStartLaser, value); }
|
|
private bool _bLaserOn;
|
|
public bool bLaserOn { get => _bLaserOn; set => SetProperty(ref _bLaserOn, value); }
|
|
private bool _bPilotLaserOn;
|
|
public bool bPilotLaserOn { get => _bPilotLaserOn; set => SetProperty(ref _bPilotLaserOn, value); }
|
|
private bool _bResetLaserOn;
|
|
public bool bResetLaserOn { get => _bResetLaserOn; set => SetProperty(ref _bResetLaserOn, value); }
|
|
|
|
private bool _bProgramActived;
|
|
public bool bProgramActived { get => _bProgramActived; set => SetProperty(ref _bProgramActived, value); }
|
|
|
|
private bool _bProgramInterrupted;
|
|
public bool bProgramInterrupted { get => _bProgramInterrupted; set => SetProperty(ref _bProgramInterrupted, value); }
|
|
|
|
// Control Mode
|
|
private bool _bGetModeLocal;
|
|
public bool bGetModeLocal { get => _bGetModeLocal; set => SetProperty(ref _bGetModeLocal, value); }
|
|
private bool _bGetModeRemote;
|
|
public bool bGetModeRemote { get => _bGetModeRemote; set => SetProperty(ref _bGetModeRemote, value); }
|
|
private bool _bSetModeLocal;
|
|
public bool bSetModeLocal { get => _bSetModeLocal; set => SetProperty(ref _bSetModeLocal, value); }
|
|
private bool _bSetModeRemote;
|
|
public bool bSetModeRemote { get => _bSetModeRemote; set => SetProperty(ref _bSetModeRemote, value); }
|
|
|
|
// Power
|
|
private string _strPowerCenter;
|
|
public string strPowerCenter { get => _strPowerCenter; set => SetProperty(ref _strPowerCenter, value); }
|
|
private string _strPowerRing;
|
|
public string strPowerRing { get => _strPowerRing; set => SetProperty(ref _strPowerRing, value); }
|
|
|
|
private string _Alarm1Status;
|
|
public string Alarm1Status { get => _Alarm1Status; set => SetProperty(ref _Alarm1Status, value); }
|
|
|
|
private string _Alarm2Status;
|
|
public string Alarm2Status { get => _Alarm2Status; set => SetProperty(ref _Alarm2Status, value); }
|
|
#endregion
|
|
|
|
#region Envent Command
|
|
public ICommand CMD_VisibleChanged { get; }
|
|
public ICommand CMD_Connect { get; }
|
|
public ICommand CMD_DisConnect { get; }
|
|
|
|
public ICommand CMD_LaserON { get; }
|
|
public ICommand CMD_LaserOFF { get; }
|
|
public ICommand CMD_PilotLaserON { get; }
|
|
public ICommand CMD_PilotLaserOFF { get; }
|
|
public ICommand CMD_Reset { get; }
|
|
public ICommand CMD_ShowAlarm { get; }
|
|
private readonly DispatcherTimer _CurrentStatusUpdateTimer;
|
|
|
|
#endregion
|
|
private readonly IDeviceManager _deviceManger;
|
|
private readonly LaserDevice _Laser;
|
|
|
|
public UCLaserDeviceViewModel(IAuroraEnvironment aurora, string deviceId)
|
|
{
|
|
_deviceManger = aurora.DeviceManager;
|
|
_Laser = _deviceManger[deviceId] as LaserDevice;
|
|
|
|
#region DelegateCommand
|
|
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
|
|
CMD_Connect = new DelegateCommand(Connect);
|
|
CMD_DisConnect = new DelegateCommand(DisConnect);
|
|
CMD_LaserON = new DelegateCommand(LaserON);
|
|
CMD_LaserOFF = new DelegateCommand(LaserOFF);
|
|
CMD_PilotLaserON = new DelegateCommand(PilotLaserON);
|
|
CMD_PilotLaserOFF = new DelegateCommand(PilotLaserOFF);
|
|
CMD_Reset = new DelegateCommand(ResetLaser);
|
|
CMD_ShowAlarm = new DelegateCommand(ShowAlarmStatus);
|
|
#endregion
|
|
|
|
#region Init Properties
|
|
bInitComm = false;
|
|
bEmission = false;
|
|
bPilotLaser = false;
|
|
bLaserReady = false;
|
|
bLaserWarning = false;
|
|
bLaserError = false;
|
|
bStartLaser = false;
|
|
bLaserOn = false;
|
|
bPilotLaserOn = false;
|
|
bResetLaserOn = false;
|
|
bGetModeLocal = false;
|
|
bGetModeRemote = false;
|
|
bSetModeLocal = false;
|
|
bSetModeRemote = false;
|
|
strPowerCenter = "0.000V";
|
|
strPowerRing = "0.000V";
|
|
#endregion
|
|
|
|
if (!_Laser.IsSimul) {
|
|
_CurrentStatusUpdateTimer = new DispatcherTimer();
|
|
_CurrentStatusUpdateTimer.Tick += OuCurrentStatusUpdateTimer;
|
|
_CurrentStatusUpdateTimer.Interval = TimeSpan.FromMilliseconds(100);
|
|
}
|
|
}
|
|
|
|
private void VisibleChanged(object obj)
|
|
{
|
|
bool visible = (bool)obj;
|
|
if (visible) {
|
|
_CurrentStatusUpdateTimer?.Start();
|
|
} else {
|
|
_CurrentStatusUpdateTimer?.Stop();
|
|
}
|
|
}
|
|
private void OuCurrentStatusUpdateTimer(object sender, EventArgs e)
|
|
{
|
|
if (_Laser.IsActivated && !_Laser.IsSimul) {
|
|
try {
|
|
//bInitComm = _Laser.GetInitCommunication();
|
|
bEmission = _Laser.GetEmissionStatus();
|
|
bPilotLaser = _Laser.GetPilotLaserStatus();
|
|
bLaserReady = _Laser.GetLaserReady();
|
|
bLaserWarning = _Laser.GetWarningStatus();
|
|
bLaserError = _Laser.GetLaserError();
|
|
bEStop = _Laser.GetEStop();
|
|
bStartLaser = _Laser.GetStartLaserSetBitStatus();
|
|
bLaserOn = _Laser.GetLaserStartSetBitStatus();
|
|
bPilotLaserOn = _Laser.GetPilotLaserSetBitStatus();
|
|
bResetLaserOn = _Laser.GetLaserResetSetBitStatus();
|
|
//bProgramActived = _Laser.GetProgramActived();
|
|
//bProgramInterrupted = _Laser.GetProgramInterrupted();
|
|
bGetModeLocal = _Laser.GetControlMode() == "LOCAL" ? true : false;
|
|
bGetModeRemote = _Laser.GetControlMode() == "REMOTE" ? true : false;
|
|
//bSetModeLocal = !_Laser.GetControlModeSetStatus(); //local == false, remote == true;
|
|
//bSetModeRemote = _Laser.GetControlModeSetStatus(); //local == false, remote == true;
|
|
strPowerCenter = _Laser.GetPowerCenter();
|
|
strPowerRing = _Laser.GetPowerRing();
|
|
} catch (Exception ex) {
|
|
Log.E(string.Format($"[OuCurrentStatusUpdateTimer]{ex.Message}"));
|
|
}
|
|
} else {
|
|
_CurrentStatusUpdateTimer?.Stop();
|
|
Log.D(string.Format("[OuCurrentStatusUpdateTimer]Check Scanner device Connect"));
|
|
}
|
|
}
|
|
|
|
private void Connect(object obj)
|
|
{
|
|
if (_Laser != null) {
|
|
_Laser.ActivateDevice();
|
|
}
|
|
}
|
|
private void DisConnect(object obj)
|
|
{
|
|
if (_Laser != null) {
|
|
//laser._Laser.DisConnect();
|
|
_Laser.DeactivateDevice();
|
|
}
|
|
}
|
|
private void LaserON(object obj)
|
|
{
|
|
if (_Laser != null) {
|
|
//laser._Laser.LaserOn();
|
|
_Laser.LaserOn();
|
|
}
|
|
}
|
|
|
|
private void LaserOFF(object obj)
|
|
{
|
|
if (_Laser != null) {
|
|
//laser._Laser.LaserOff();
|
|
_Laser.LaserOff();
|
|
}
|
|
}
|
|
|
|
private void PilotLaserON(object obj)
|
|
{
|
|
if (_Laser != null) {
|
|
//laser._Laser.PilotLaserOn();
|
|
_Laser.PilotLaserOn();
|
|
}
|
|
}
|
|
|
|
private void PilotLaserOFF(object obj)
|
|
{
|
|
if (_Laser != null) {
|
|
_Laser.PilotLaserOff();
|
|
}
|
|
}
|
|
|
|
private void ResetLaser(object obj)
|
|
{
|
|
if (_Laser != null) {
|
|
_Laser.ResetLaser();
|
|
}
|
|
}
|
|
|
|
private void ShowAlarmStatus(object obj)
|
|
{
|
|
Alarm1Status = "";
|
|
Alarm2Status = "";
|
|
// Won : IPG Ethernet Type을 제외하고 Status, Alarm 부분에 대한 상세내역을 받을 수 없으므로 현재는 IPG_YLS 시에만 사용 가능하도록 구현
|
|
if (_Laser.Config.LaserType == eLaserType.IPG_YLS_Laser) {
|
|
|
|
List<string> Alarm1List = new List<string>();
|
|
List<string> Alarm2List = new List<string>();
|
|
|
|
|
|
if (bLaserError) {
|
|
Alarm1List = _Laser.Alarm1String();
|
|
Alarm2List = _Laser.Alarm2String();
|
|
|
|
for (int i = 0; i < Alarm1List.Count; i++) {
|
|
Alarm1Status += Alarm1List[i] + ", ";
|
|
}
|
|
for (int i = 0; i < Alarm2List.Count; i++) {
|
|
Alarm2Status += Alarm2List[i] + ", ";
|
|
}
|
|
}
|
|
}
|
|
// Won : Coherent Ethernet Type Add
|
|
if (_Laser.Config.LaserType == eLaserType.Coherent_Arm_Laser) {
|
|
List<string> ErrorList = new List<string>();
|
|
|
|
ErrorList = _Laser.AlarmString();
|
|
|
|
for (int i = 0; i < ErrorList.Count; i++)
|
|
{
|
|
Alarm1Status += ErrorList[i] + ", " + "\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ShowLaserStatus(object obj)
|
|
{
|
|
// Won : IPG Ethernet Type을 제외하고 Status, Alarm 부분에 대한 상세내역을 받을 수 없으므로 현재는 IPG_YLS 시에만 사용 가능하도록 구현
|
|
if (_Laser.Config.LaserType != eLaserType.IPG_YLS_Laser)
|
|
return;
|
|
|
|
Alarm1Status = "";
|
|
Alarm2Status = "";
|
|
List<string> StatusList = new List<string>();
|
|
|
|
StatusList = _Laser.StatusString();
|
|
|
|
for (int i = 0; i < StatusList.Count; i++) {
|
|
Alarm1Status += StatusList[i] + ", ";
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|