using System;
using System.Collections.Generic;
using Aitex.Core.Common;
using Aitex.Core.RT.Event;
using Aitex.Core.Util;
using Aitex.Sorter.Common;
using MECF.Framework.Common.Equipment;
using MECF.Framework.Common.SubstrateTrackings;
using Virgo_DCommon;
using Virgo_DRT.Device;
using Virgo_DRT.Device.YASKAWA;
using System.Diagnostics;
namespace Virgo_DRT.Devices
{
///
/// Base action
///
abstract class EfemActionBase : ActionBase
{
protected readonly EfemBase _efem;
public EfemOperation Type { get; protected set; }
protected EfemActionBase() : this(null) { }
protected EfemActionBase(EfemBase efem) : base(ModuleName.EFEM)
{
_efem = efem;
}
}
class DelayAction : ActionBase
{
private readonly DeviceTimer _timer = new DeviceTimer();
private readonly ushort _delayTime;
public bool IsDone => _timer.IsTimeout();
public DelayAction(ushort delaytime) : base(ModuleName.System)
{
this._delayTime = delaytime;
}
public override void Execute()
{
_timer.Start(this._delayTime * 1000);
}
public override void OnPostWork(string data)
{
EV.PostInfoLog(ModuleName.EFEM.ToString(), $"Delay time [{_delayTime}]");
}
}
}
namespace Virgo_DRT.Devices.YASKAWA
{
class EfemAction : EfemActionBase
{
public EfemAction(EfemBase device, ModuleName mod) : base(device)
{ }
public override void Execute()
{
_efem.MsgHandler.Send(new EfemMessage
{
Operation = this.Type,
Head = EfemMessage.MsgHead.MOV,
Parameters = new List { Constant.ModuleString[this.Module] }
});
base.Execute();
_efem.Status = DeviceState.Busy;
EV.PostInfoLog(this.Module.ToString(), $"Cmd {this.ID} {this.Type} Start");
}
public override void OnPostWork(string data = null)
{
_efem.Status = DeviceState.Idle;
EV.PostInfoLog(this.Module.ToString(), $"Cmd {this.ID} {this.Type} End");
}
}
///
///
///
class HomeAllAction : EfemAction
{
public HomeAllAction(EfemBase efem, ModuleName mod) : base(efem, mod)
{
Type = EfemOperation.Home;
this.Module = mod;
}
}
class HomeModuleAction : EfemAction
{
public HomeModuleAction(EfemBase efem, ModuleName mod) : base(efem, mod)
{
Type = EfemOperation.Home;
this.Module = mod;
}
}
class OrgshAction : EfemAction
{
public OrgshAction(EfemBase efem, ModuleName mod) : base(efem, mod)
{
Type = EfemOperation.Orgsh;
this.Module = mod;
}
}
class ClearErrorAction : EfemAction
{
public ClearErrorAction(EfemBase efem) : base(efem, ModuleName.EFEM)
{
Type = EfemOperation.ClearError;
}
public override void Execute()
{
_efem.MsgHandler.Send(new EfemMessage
{
Operation = this.Type,
Head = EfemMessage.MsgHead.SET,
Parameters = new List { "CLEAR" }
});
EV.PostInfoLog(this.Module.ToString(), "清除 EFEM 所有错误");
}
}
class MapAction : EfemAction
{
public MapAction(EfemBase efem, ModuleName mod) : base(efem, mod)
{
Type = EfemOperation.Map;
this.Module = mod;
}
public override void OnPostWork(string data)
{
_efem[Module].Status = DeviceState.Idle;
}
}
class PickAction : EfemAction
{
private MoveParam MoveParam { get; }
public PickAction(EfemBase efem, MoveParam mp) : base(efem, ModuleName.EFEM)
{
Type = EfemOperation.Pick;
MoveParam = mp;
}
public override void Execute()
{
//MOV:LOAD/P113/ARM2;
_efem.MsgHandler.Send(new EfemMessage
{
Operation = this.Type,
Head = EfemMessage.MsgHead.MOV,
Parameters = new List
{
MoveParam.SrcPos.ToHWString(),
Constant.ArmString[MoveParam.Arm],
MoveParam.WaferSize.ToString()
}
});
this.Status = ActionStatus.SendCmd;
_efem.Status = DeviceState.Busy;
}
public override void OnPostWork(string data)
{
WaferManager.Instance.WaferMoved(MoveParam.SrcModule, MoveParam.SrcSlot, MoveParam.DestModule, MoveParam.DestSlot);
_efem.Status = DeviceState.Idle;
//_bladeTarget = ModuleName.EfemRobot;
}
}
// MOV:GOTO/P113/ARM2/DOWN;
// MOV:UNLOAD/P225/ARM2;
class PlaceAction : EfemAction
{
private MoveParam MoveParam { get; }
public PlaceAction(EfemBase device, MoveParam mp) : base(device, ModuleName.EFEM)
{
Type = EfemOperation.Place;
MoveParam = mp;
}
public override void Execute()
{
_efem.MsgHandler.Send(new EfemMessage
{
Operation = this.Type,
Head = EfemMessage.MsgHead.MOV,
Parameters = new List
{
MoveParam.DestPos.ToHWString(),
Constant.ArmString[MoveParam.Arm],
MoveParam.WaferSize.ToString()
}
});
this.Status = ActionStatus.SendCmd;
_efem.Status = DeviceState.Busy;
}
public override void OnPostWork(string data)
{
WaferManager.Instance.WaferMoved(MoveParam.SrcModule, MoveParam.SrcSlot, MoveParam.DestModule, MoveParam.DestSlot);
_efem.Status = DeviceState.Idle;
}
}
class ExtendAction : EfemAction
{
private ExtendParam ExtParam { get; }
public ExtendPos TargetPosition => ExtParam.Pos;
public ExtendAction(EfemBase efem, ExtendParam ep)
: base(efem, ModuleName.EFEM)
{
Type = EfemOperation.Extend;
ExtParam = ep;
ExtParam.Arm = Hand.Blade1;
}
public override void Execute()
{
//MOV:EXTEND/LLA03/ARM2;
_efem.MsgHandler.Send(new EfemMessage
{
Operation = this.Type,
Head = EfemMessage.MsgHead.MOV,
Parameters = new List
{
ExtParam.Module.ToHWString(),
//Constant.ExtendPosString[ExtParam.Pos],
ExtParam.Pos.ToString(),
Constant.ArmString[ExtParam.Arm]
}
});
this.Status = ActionStatus.SendCmd;
_efem.Status = DeviceState.Busy;
}
public override void OnPostWork(string data)
{
_efem.Status = DeviceState.Idle;
switch (TargetPosition)
{
case ExtendPos.PB:
WaferManager.Instance.WaferMoved(ModuleName.EfemRobot, (int)ExtParam.Arm, ExtParam.Module, 0);
break;
case ExtendPos.G4:
WaferManager.Instance.WaferMoved(ExtParam.Module, 0, ModuleName.EfemRobot, (int)ExtParam.Arm);
break;
default:
Debug.WriteLine($"MNPT:{TargetPosition} 不需要更新 WaferManager 信息");
break;
}
}
}
class LiftAction : EfemAction
{
// MOV:LIFT/ALIGN1;
public LiftAction(EfemBase device, ModuleName mod) : base(device, mod)
{
Type = EfemOperation.Lift;
Module = mod;
}
public override void OnPostWork(string data)
{ }
}
class AlignAction : EfemAction
{
private WaferSize _ws { get; }
public AlignAction(EfemBase device, ModuleName mod, WaferSize size) : base(device, mod)
{
Type = EfemOperation.Align;
this.Module = mod;
this._ws = size;
}
public override void Execute()
{
_efem.MsgHandler.Send(new EfemMessage
{
Operation = this.Type,
Head = EfemMessage.MsgHead.MOV,
Parameters = new List { Module.ToHWString(), this._ws.ToString() }
});
this.Status = ActionStatus.SendCmd;
}
public override void OnPostWork(string data) { }
}
class LedAction : EfemAction
{
private LightType Light { get; }
private LightStatus LtStatus { get; }
public LedAction(EfemBase device, LightType lt, LightStatus st) : base(device, ModuleName.EFEM)
{
Type = EfemOperation.Light;
Light = lt;
LtStatus = st;
}
public override void Execute()
{
_efem.MsgHandler.Send(new EfemMessage
{
Operation = this.Type,
Head = EfemMessage.MsgHead.SET,
Parameters = new List { Constant.STOWER, Light.ToString(), LtStatus.ToString() }
});
_efem.Status = DeviceState.Busy;
EV.PostInfoLog(this.Module.ToString(), $"Cmd {this.ID} {this.Type} Start");
}
public override void OnPostWork(string data)
{
}
}
class AbortAction: EfemAction
{
public AbortAction(EfemBase efem) : base(efem, ModuleName.EFEM)
{
Type = EfemOperation.Abort;
}
public override void Execute()
{
_efem.MsgHandler.Send(new EfemMessage
{
Operation = this.Type,
Head = EfemMessage.MsgHead.MOV
});
}
}
}