277 lines
10 KiB
C#
277 lines
10 KiB
C#
using Aurora.Api;
|
|
using Aurora;
|
|
using Aurora.View;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using WeldingCommon.Views;
|
|
using static WeldingCommon.Views.UCCommonAutoRunViewModel;
|
|
using WeldingCommon;
|
|
using System.Reactive.Linq;
|
|
using VisionCommon;
|
|
using WeldingCommon.Sequences;
|
|
using ILSOS_ACW_H52A.Sequences;
|
|
using WeldingCommon.Devices;
|
|
using ILSOS_ACW_H52A.Device;
|
|
using AuroraLaserScanner;
|
|
using WeldingCommon.Utils;
|
|
using System.Windows.Threading;
|
|
using WeldingCommon.Settings;
|
|
using WeldingCommon.Data;
|
|
using System.Windows.Controls;
|
|
using Aurora.Api.Manager;
|
|
using System.Windows;
|
|
using WeldingCommon.Recipes;
|
|
|
|
namespace ILSOS_ACW_H52A.Views
|
|
{
|
|
public class UCMainAutoRunViewModel : NotifyPropertyChangedBase
|
|
{
|
|
private readonly Logger Log = new Logger("UCMainAutoRunViewModel");
|
|
|
|
public ICommand CMD_VisibleChanged { get; }
|
|
public ICommand CMD_RunSequenceAutoRun { get; }
|
|
public ICommand CMD_StopSequenceAutoRun { get; }
|
|
public ICommand CMD_Reset { get; } // Totoal Product, Today Product
|
|
|
|
private readonly IAuroraEnvironment _Aurora;
|
|
private readonly IRecipeManager _RecipeManager;
|
|
private readonly ISettingEntry _SettingEntry;
|
|
private readonly IAlarmService _AlarmService;
|
|
|
|
private readonly SystemParameter _SystemParameter;
|
|
private readonly Scanner _Scanner;
|
|
private readonly PLCControllerACWH52A _Plc;
|
|
|
|
private ISequence _SeqAutoRun;
|
|
private bool _IsSequenceRunning_AutoRun;
|
|
public bool IsSequenceRunning_AutoRun { get => _IsSequenceRunning_AutoRun; set => SetProperty(ref _IsSequenceRunning_AutoRun, value); }
|
|
|
|
private bool _IsAlarm;
|
|
public bool IsAlarm { get => _IsAlarm; set => SetProperty(ref _IsAlarm, value); }
|
|
|
|
private DateTime _NowDateTime;
|
|
public DateTime NowDateTime { get => _NowDateTime; set => SetProperty(ref _NowDateTime, value); }
|
|
|
|
public WeldingData CurrentWeldingData { get => Status.GetProcessingWeldingData(); }
|
|
|
|
public UCCommonAutoRunViewModel CommonAutoRunViewModel { get; }
|
|
private readonly UserControl _UCRecipe;
|
|
|
|
private readonly DispatcherTimer _MonitorTimer;
|
|
|
|
public UCMainAutoRunViewModel(IAuroraEnvironment aurora, UserControl recipe, string sequenceId, ExternalRecipeUpdate externalRecipeUpdate)
|
|
{
|
|
_Aurora = aurora;
|
|
_RecipeManager = _Aurora.RecipeManager;
|
|
_SettingEntry = _Aurora.SettingEntry;
|
|
_AlarmService = _Aurora.AlarmService;
|
|
|
|
CommonAutoRunViewModel = new UCCommonAutoRunViewModel(_Aurora, sequenceId, externalRecipeUpdate);
|
|
_UCRecipe = recipe;
|
|
|
|
_SystemParameter = aurora.SettingEntry[CommonSettingIds.SystemParameter] as SystemParameter;
|
|
_Scanner = _Aurora.DeviceManager[CommonDeviceIds.Scanner] as Scanner;
|
|
_Plc = _Aurora.DeviceManager[CommonDeviceIds.PLCDevice] as PLCControllerACWH52A;
|
|
|
|
_SeqAutoRun = _Aurora.SequenceEntry[SequenceIds.SeqAutoRunACWH52A];
|
|
_SeqAutoRun.RunStateChanged += AutoRunSeq_RunStateChanged;
|
|
|
|
InitVariable();
|
|
|
|
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
|
|
|
|
CMD_RunSequenceAutoRun = new DelegateCommand(PerformCmdRunSequenceAutoRun);
|
|
CMD_StopSequenceAutoRun = new DelegateCommand(PerformCmdStopSequenceAutoRun);
|
|
CMD_Reset = new DelegateCommand(PerformCmdReset);
|
|
|
|
_MonitorTimer = new DispatcherTimer();
|
|
_MonitorTimer.Tick += OnMonitoring;
|
|
_MonitorTimer.Interval = TimeSpan.FromMilliseconds(100);
|
|
|
|
_Aurora.EventObservable.AsObservable(CommonEventIds.EVENT_SEQ_AUTO_RUN_START)
|
|
.ObserveOnDispatcher()
|
|
.Subscribe(x => OnAutoRunStartRequest());
|
|
|
|
_Aurora.EventObservable.AsObservable(CommonEventIds.EVENT_SEQ_AUTO_RUN_STOP)
|
|
.ObserveOnDispatcher()
|
|
.Subscribe(x => OnAutoRunStopRequest());
|
|
|
|
}
|
|
|
|
private void InitVariable()
|
|
{
|
|
IsSequenceRunning_AutoRun = false;
|
|
IsAlarm = false;
|
|
|
|
NowDateTime = DateTime.Now;
|
|
|
|
CurrentWeldingData.TotalProduct = _SystemParameter.TotalProductCount;
|
|
CurrentWeldingData.TodayProduct = _SystemParameter.TodayProductCount;
|
|
CurrentWeldingData.AutoRunStartTime = default(DateTime);
|
|
CurrentWeldingData.WeldingEndTime = default(DateTime);
|
|
CurrentWeldingData.WeldingSpanTimeMilliseconds = "0";
|
|
CurrentWeldingData.LotId = "Default_Lot_Id";
|
|
CurrentWeldingData.CellId = "Default_Cell_Id";
|
|
}
|
|
|
|
private void VisibleChanged(object obj)
|
|
{
|
|
bool visible = (bool)obj;
|
|
if (visible) {
|
|
_MonitorTimer.Start();
|
|
} else {
|
|
_MonitorTimer.Stop();
|
|
}
|
|
}
|
|
|
|
private void OnMonitoring(object sender, EventArgs e)
|
|
{
|
|
NowDateTime = DateTime.Now;
|
|
|
|
// Sequence Status check
|
|
if (_SeqAutoRun.RunState != SequenceRunState.Idle) {
|
|
IsSequenceRunning_AutoRun = true;
|
|
} else {
|
|
IsSequenceRunning_AutoRun = false;
|
|
}
|
|
|
|
// Alarm Status check
|
|
List<int> currentAlarmCode = _AlarmService.GetCurrentAlarmCodes();
|
|
if (currentAlarmCode.Count != 0) {
|
|
IsAlarm = true;
|
|
} else {
|
|
IsAlarm = false;
|
|
}
|
|
}
|
|
|
|
|
|
private void PerformCmdRunSequenceAutoRun(object obj)
|
|
{
|
|
var result = MessageUtil.ShowYesNoMessageDialog("AutoRun Sequence", "Start AutoRun Sequence?");
|
|
if (result == false) {
|
|
return;
|
|
}
|
|
|
|
if (VisionRecipeManager.GetFovInfos().Count == 0) {
|
|
MessageUtil.ShowWarningToast(string.Format("Please check the Vision Recipe of the currently active Recipe."));
|
|
return;
|
|
}
|
|
|
|
if (_SeqAutoRun.RunState == SequenceRunState.Running) {
|
|
MessageUtil.ShowWarningToast(string.Format("이미 시퀀스가 Start 상태입니다.", "SeqAutoRunACWH52A"));
|
|
return;
|
|
}
|
|
|
|
RunSequenceAutoRun();
|
|
|
|
}
|
|
|
|
private void OnAutoRunStartRequest()
|
|
{
|
|
RunSequenceAutoRun();
|
|
}
|
|
|
|
private void RunSequenceAutoRun()
|
|
{
|
|
var equipSetting = _Aurora.SettingEntry[AuroraSettings.Equipment] as EquipmentInfo;
|
|
var scoutSeqParams = new ScoutSeqParams(VisionRecipeManager.GetFovInfos()[0], eDisplayType.Machine_B);
|
|
var param = new SeqAutoRunACWH52A_InitParam() {
|
|
ScoutSeqParams = scoutSeqParams,
|
|
UseStream = equipSetting.UseStream,
|
|
};
|
|
|
|
//_SequenceDialog.Show();
|
|
IsSequenceRunning_AutoRun = true;
|
|
_SeqAutoRun.Start(param, OnCompleteAutoRun);
|
|
|
|
_Plc.WriteBit(_Plc.PC_AUTO_COMPLETEAddr, true);
|
|
}
|
|
|
|
private void OnCompleteAutoRun(SequenceActionResult res)
|
|
{
|
|
if (res != null) {
|
|
if (res.Param is SeqAutoRunACWH52A_OutParam result && result.Success == true) {
|
|
IsSequenceRunning_AutoRun = false;
|
|
MessageUtil.ShowSuccessToast(string.Format("Success SeqAutoRunACWH52A"));
|
|
return;
|
|
}
|
|
}
|
|
|
|
IsSequenceRunning_AutoRun = false;
|
|
MessageUtil.ShowWarningToast(string.Format("Fail SeqAutoRunACWH52A"));
|
|
}
|
|
|
|
private void PerformCmdStopSequenceAutoRun(object obj)
|
|
{
|
|
StopSequenceAutoRun();
|
|
}
|
|
|
|
private void OnAutoRunStopRequest()
|
|
{
|
|
StopSequenceAutoRun();
|
|
}
|
|
|
|
private void StopSequenceAutoRun()
|
|
{
|
|
if (_SeqAutoRun.RunState == SequenceRunState.Idle) {
|
|
return;
|
|
}
|
|
|
|
IsSequenceRunning_AutoRun = false;
|
|
_SeqAutoRun.Stop();
|
|
|
|
_Plc.WriteBit(_Plc.PC_MANUAL_COMPLETEAddr, true);
|
|
|
|
//Recipe를 기존에 선택된 Recipe로 Rollback 해 줌
|
|
WeldingRecipeManager.RollbackRecipe();
|
|
//AutoRun 정지 시 CorrectionFile을 Vision으로 변경
|
|
_Scanner.SelectCorrectionTable(1);
|
|
}
|
|
|
|
private void PerformCmdReset(object commandParameter)
|
|
{
|
|
switch ((string)commandParameter) {
|
|
case "TotalProduct": {
|
|
CurrentWeldingData.TotalProduct = 0;
|
|
_SystemParameter.TotalProductCount = CurrentWeldingData.TotalProduct;
|
|
_SettingEntry.Save(CommonSettingIds.SystemParameter, _SystemParameter, "UCMainAutoRunViewModel");
|
|
}
|
|
break;
|
|
|
|
case "TodayProduct": {
|
|
CurrentWeldingData.TodayProduct = 0;
|
|
_SystemParameter.TodayProductCount = CurrentWeldingData.TodayProduct;
|
|
_SettingEntry.Save(CommonSettingIds.SystemParameter, _SystemParameter, "UCMainAutoRunViewModel");
|
|
}
|
|
break;
|
|
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void AutoRunSeq_RunStateChanged(object sender, (string sequenceId, SequenceRunState state) e)
|
|
{
|
|
//AutoRun 상황에서 Recipe Save Lock
|
|
_RecipeManager.SaveLock(
|
|
CommonRecipeIds.ScannerObjectTeaching,
|
|
e.state != SequenceRunState.Idle);
|
|
//AutoRun 상황에서 Reicpe 화면 수정할 수 없도록 함
|
|
if (e.state == SequenceRunState.Running) {
|
|
Application.Current.Dispatcher.InvokeAsync(() => {
|
|
_UCRecipe.IsEnabled = false;
|
|
});
|
|
} else {
|
|
Application.Current.Dispatcher.InvokeAsync(() => {
|
|
_UCRecipe.IsEnabled = true;
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|