using Aitex.Core.RT.Fsm;
using Aitex.Core.Utilities;
using MECF.Framework.Common.Equipment;
using MECF.Framework.RT.ModuleLibrary.VceModules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Venus_RT.Devices.VCE;
namespace Venus_RT.Modules.VCE
{
#region 状态和消息
public enum VceSTATE
{
Init,//初始化
Idle,//空闲
Error,//错误
Homing,//home操作 对应HM
DoorOpenning,//开门操作 对应DC
DoorClosing,//关门操作 对应DO
Loading,//取cassette操作 包括开门关门 对应LOAD,
UnLoading,
Mapping,//扫片 对应MP 包括三种格式 hex binary 智能(只有智能模式可以判断复杂情况)
Goting,//指定槽到达窗口 对应 GC
Resetting,//重置
Unknown
}
public enum VceMSG
{
Home,
Error,
DoorOpen,
DoorClose,
Map,
Load,
UnLoad,
Reset,
Goto,
Abort
}
#endregion
public class VceEntity : Entity, IEntity
{
private ModuleName _modulename;
private readonly VceModuleBase _vce;
public VceEntity(ModuleName moduleName)
{
_modulename = moduleName;
_vce = new HongHuVce(25, moduleName);
InitFsmMap();
}
///
/// 定义状态机的迁移表
///
private void InitFsmMap()
{
fsm = new StateMachine(_modulename.ToString(), (int)VceSTATE.Unknown, 50);
fsm.EnableRepeatedMsg(true);
AnyStateTransition(VceMSG.Error, fnError, VceSTATE.Error);
AnyStateTransition(VceMSG.Abort, fnAbort, VceSTATE.Idle);
//HOME init->homing idle->homing
Transition(VceSTATE.Init, VceMSG.Home, fnStartHome, VceSTATE.Homing);
Transition(VceSTATE.Idle, VceMSG.Home, fnStartHome, VceSTATE.Homing);
Transition(VceSTATE.Error, VceMSG.Home, fnStartHome, VceSTATE.Homing);
Transition(VceSTATE.Homing, FSM_MSG.TIMER, fnHomeTimeout, VceSTATE.Idle);
//Open Door 开门
Transition(VceSTATE.Idle, VceMSG.DoorOpen, fnStartOpenDoor, VceSTATE.DoorOpenning);
Transition(VceSTATE.DoorOpenning, FSM_MSG.TIMER, fnOpenDoorTimeout, VceSTATE.Idle);
//Close Door 关门
Transition(VceSTATE.Idle, VceMSG.DoorClose, fnStartCloseDoor, VceSTATE.DoorClosing);
Transition(VceSTATE.DoorClosing, FSM_MSG.TIMER, fnCloseDoorTimeout, VceSTATE.Idle);
//Map 扫片
Transition(VceSTATE.Idle, VceMSG.Map, fnStartMapping, VceSTATE.Mapping);
Transition(VceSTATE.Mapping, FSM_MSG.TIMER, fnMappingTimeout, VceSTATE.Idle);
//Load 取cassette
Transition(VceSTATE.Idle, VceMSG.Load, fnStartLoading, VceSTATE.Loading);
Transition(VceSTATE.Loading, FSM_MSG.TIMER, fnLoadingTimeout, VceSTATE.Idle);
//UnLoad 放cassette
Transition(VceSTATE.Idle, VceMSG.UnLoad, fnStartUnLoading, VceSTATE.UnLoading);
Transition(VceSTATE.UnLoading, FSM_MSG.TIMER, fnUnLoadingTimeout, VceSTATE.Idle);
//Goto 指定槽对准窗口
Transition(VceSTATE.Idle, VceMSG.Goto, fnStartGoto, VceSTATE.Goting);
Transition(VceSTATE.Goting, FSM_MSG.TIMER, fnGotingTimeout, VceSTATE.Idle);
//
EnumLoop.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
EnumLoop.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
Running = true;
}
//急停
private bool fnAbort(object[] param)
{
throw new NotImplementedException();
}
//升降到槽位
private bool fnStartGoto(object[] param)
{
return _vce.Goto(Convert.ToInt32(param[0]));
}
private bool fnGotingTimeout(object[] param)
{
throw new NotImplementedException();
}
private bool fnError(object[] param)
{
throw new NotImplementedException();
}
private bool fnStartHome(object[] param)
{
return _vce.HomeALL();
}
private bool fnHomeTimeout(object[] param)
{
throw new NotImplementedException();
}
private bool fnStartOpenDoor(object[] param)
{
return _vce.OpenDoor();
}
private bool fnOpenDoorTimeout(object[] param)
{
throw new NotImplementedException();
}
private bool fnStartCloseDoor(object[] param)
{
return _vce.CloseDoor();
}
private bool fnCloseDoorTimeout(object[] param)
{
throw new NotImplementedException();
}
private bool fnStartMapping(object[] param)
{
return _vce.Map();
}
private bool fnMappingTimeout(object[] param)
{
throw new NotImplementedException();
}
private bool fnStartLoading(object[] param)
{
return _vce.Load();
}
private bool fnLoadingTimeout(object[] param)
{
throw new NotImplementedException();
}
private bool fnStartUnLoading(object[] param)
{
return _vce.UnLoad();
}
private bool fnUnLoadingTimeout(object[] param)
{
throw new NotImplementedException();
}
public bool Check(int msg, out string reason, params object[] args)
{
throw new NotImplementedException();
}
}
}