VceEntity.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.RT.OperationCenter;
  3. using Aitex.Core.Utilities;
  4. using MECF.Framework.Common.Equipment;
  5. using MECF.Framework.RT.ModuleLibrary.VceModules;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using Venus_Core;
  13. using Venus_RT.Devices.VCE;
  14. namespace Venus_RT.Modules.VCE
  15. {
  16. #region 状态和消息
  17. public enum VceSTATE
  18. {
  19. Init,//初始化
  20. Idle,//空闲
  21. Error,//错误
  22. Homing,//home操作 对应HM
  23. DoorOpenning,//开门操作 对应DC
  24. DoorClosing,//关门操作 对应DO
  25. Loading,//取cassette操作 包括开门关门 对应LOAD,
  26. UnLoading,
  27. Mapping,//扫片
  28. ReadingMap, //对应MP 包括三种格式 hex binary 智能(只有智能模式可以判断复杂情况)
  29. Goting,//指定槽到达窗口 对应 GC
  30. Resetting,//重置
  31. LoadPreparing,//准备
  32. LoadingWithoutSMIF,//没有SMIF的load
  33. Unknown
  34. }
  35. public enum VceMSG
  36. {
  37. Home,
  38. Error,
  39. DoorOpen,
  40. DoorClose,
  41. Map,
  42. ReadMap,
  43. Load,
  44. UnLoad,
  45. LoadPrepare,
  46. LoadWithoutSMIF,
  47. Reset,
  48. Goto,
  49. Abort
  50. }
  51. #endregion
  52. public class VceEntity : Entity, IEntity, IModuleEntity
  53. {
  54. private ModuleName _modulename;
  55. private readonly VceModuleBase _vce;
  56. public bool IsIdle => fsm.State == (int)VceSTATE.Idle;
  57. public bool IsInit => fsm.State == (int)VceSTATE.Init || fsm.State == (int)VceSTATE.Unknown;
  58. public bool IsBusy => !IsInit && !IsError && !IsIdle;
  59. public bool IsError => fsm.State == (int)VceSTATE.Error;
  60. public VceEntity(ModuleName moduleName)
  61. {
  62. _modulename = moduleName;
  63. _vce = new HongHuVce(25, _modulename);
  64. InitFsmMap();
  65. }
  66. protected override bool Init()
  67. {
  68. OP.Subscribe($"{_modulename}.HOME", (cmd,args) => { PostMsg(VceMSG.Home);return true; });
  69. OP.Subscribe($"{_modulename}.DoorOpen", (cmd,args) => { PostMsg(VceMSG.DoorOpen);return true; });
  70. OP.Subscribe($"{_modulename}.DoorClose", (cmd,args) => { PostMsg(VceMSG.DoorClose);return true; });
  71. OP.Subscribe($"{_modulename}.Map", (cmd,args) => { PostMsg(VceMSG.Map);return true; });
  72. OP.Subscribe($"{_modulename}.ReadMap", (cmd,args) => { PostMsg(VceMSG.ReadMap);return true; });
  73. OP.Subscribe($"{_modulename}.Load", (cmd,args) => { PostMsg(VceMSG.Load);return true; });
  74. OP.Subscribe($"{_modulename}.UnLoad", (cmd,args) => { PostMsg(VceMSG.UnLoad);return true; });
  75. OP.Subscribe($"{_modulename}.Reset", (cmd,args) => { PostMsg(VceMSG.Reset);return true; });
  76. OP.Subscribe($"{_modulename}.Goto", (cmd,args) => { PostMsg(VceMSG.Goto);return true; });
  77. OP.Subscribe($"{_modulename}.Abort", (cmd, args) => { PostMsg(VceMSG.Abort); return true; });
  78. return true;
  79. }
  80. /// <summary>
  81. /// 定义状态机的迁移表
  82. /// </summary>
  83. private void InitFsmMap()
  84. {
  85. fsm = new StateMachine<VceEntity>(_modulename.ToString(), (int)VceSTATE.Init, 50);
  86. fsm.EnableRepeatedMsg(true);
  87. AnyStateTransition(VceMSG.Error, fnError, VceSTATE.Error);
  88. AnyStateTransition(VceMSG.Abort, fnAbort, VceSTATE.Idle);
  89. AnyStateTransition(VceMSG.Home, fnStartHome, VceSTATE.Homing);
  90. //HOME init->homing idle->homing
  91. Transition(VceSTATE.Init, VceMSG.Home, fnStartHome, VceSTATE.Homing);
  92. Transition(VceSTATE.Idle, VceMSG.Home, fnStartHome, VceSTATE.Homing);
  93. Transition(VceSTATE.Error, VceMSG.Home, fnStartHome, VceSTATE.Homing);
  94. Transition(VceSTATE.Homing, FSM_MSG.TIMER, fnHomeTimeout, VceSTATE.Idle);
  95. //Open Door 开门
  96. Transition(VceSTATE.Idle, VceMSG.DoorOpen, fnStartOpenDoor, VceSTATE.DoorOpenning);
  97. Transition(VceSTATE.DoorOpenning, FSM_MSG.TIMER, fnOpenDoorTimeout, VceSTATE.Idle);
  98. //Close Door 关门
  99. Transition(VceSTATE.Idle, VceMSG.DoorClose, fnStartCloseDoor, VceSTATE.DoorClosing);
  100. Transition(VceSTATE.DoorClosing, FSM_MSG.TIMER, fnCloseDoorTimeout, VceSTATE.Idle);
  101. //Map 扫片
  102. Transition(VceSTATE.Idle, VceMSG.Map, fnStartMapping, VceSTATE.Mapping);
  103. Transition(VceSTATE.Mapping, FSM_MSG.TIMER, fnMappingTimeout, VceSTATE.Idle);
  104. //Load 取cassette
  105. Transition(VceSTATE.Idle, VceMSG.Load, fnStartLoading, VceSTATE.Loading);
  106. Transition(VceSTATE.Loading, FSM_MSG.TIMER, fnLoadingTimeout, VceSTATE.Idle);
  107. //UnLoad 放cassette
  108. Transition(VceSTATE.Idle, VceMSG.UnLoad, fnStartUnLoading, VceSTATE.UnLoading);
  109. Transition(VceSTATE.UnLoading, FSM_MSG.TIMER, fnUnLoadingTimeout, VceSTATE.Idle);
  110. //Goto 指定槽对准窗口
  111. Transition(VceSTATE.Idle, VceMSG.Goto, fnStartGoto, VceSTATE.Goting);
  112. Transition(VceSTATE.Goting, FSM_MSG.TIMER, fnGotingTimeout, VceSTATE.Idle);
  113. //ReadMap
  114. Transition(VceSTATE.Idle, VceMSG.ReadMap, fnStartReadingMap, VceSTATE.ReadingMap);
  115. Transition(VceSTATE.ReadingMap, FSM_MSG.TIMER, fnReadingMapTimeout, VceSTATE.Idle);
  116. //Load Prepare
  117. Transition(VceSTATE.Idle, VceMSG.LoadPrepare,fnStartLoadPrepare,VceSTATE.LoadPreparing) ;
  118. Transition(VceSTATE.LoadPreparing, VceMSG.LoadPrepare,fnLoadingPrepareTimeout,VceSTATE.Idle) ;
  119. EnumLoop<VceSTATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  120. EnumLoop<VceMSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  121. Running = true;
  122. }
  123. private bool fnLoadingPrepareTimeout(object[] param)
  124. {
  125. throw new NotImplementedException();
  126. }
  127. private bool fnStartLoadPrepare(object[] param)
  128. {
  129. throw new NotImplementedException();
  130. }
  131. private bool fnReadingMapTimeout(object[] param)
  132. {
  133. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  134. {
  135. PostMsg(VceMSG.Error);
  136. return false;
  137. }
  138. return _vce.Status == RState.End;
  139. }
  140. private bool fnStartReadingMap(object[] param)
  141. {
  142. return _vce.ReadMap();
  143. }
  144. //急停
  145. private bool fnAbort(object[] param)
  146. {
  147. return true;
  148. }
  149. //升降到槽位
  150. private bool fnStartGoto(object[] param)
  151. {
  152. return _vce.Goto(Convert.ToInt32(param[0]));
  153. }
  154. private bool fnGotingTimeout(object[] param)
  155. {
  156. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  157. {
  158. PostMsg(VceMSG.Error);
  159. return false;
  160. }
  161. return _vce.Status == RState.End;
  162. }
  163. private bool fnError(object[] param)
  164. {
  165. return true;
  166. }
  167. private bool fnStartHome(object[] param)
  168. {
  169. return _vce.HomeALL();
  170. }
  171. private bool fnHomeTimeout(object[] param)
  172. {
  173. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  174. {
  175. PostMsg(VceMSG.Error);
  176. return false;
  177. }
  178. return _vce.Status == RState.End;
  179. }
  180. private bool fnStartOpenDoor(object[] param)
  181. {
  182. return _vce.OpenDoor();
  183. }
  184. private bool fnOpenDoorTimeout(object[] param)
  185. {
  186. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  187. {
  188. PostMsg(VceMSG.Error);
  189. return false;
  190. }
  191. return _vce.Status == RState.End;
  192. }
  193. private bool fnStartCloseDoor(object[] param)
  194. {
  195. return _vce.CloseDoor();
  196. }
  197. private bool fnCloseDoorTimeout(object[] param)
  198. {
  199. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  200. {
  201. PostMsg(VceMSG.Error);
  202. return false;
  203. }
  204. return _vce.Status == RState.End;
  205. }
  206. private bool fnStartMapping(object[] param)
  207. {
  208. return _vce.Map();
  209. }
  210. private bool fnMappingTimeout(object[] param)
  211. {
  212. if(_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  213. {
  214. PostMsg(VceMSG.Error);
  215. return false;
  216. }
  217. return _vce.Status == RState.End;
  218. }
  219. private bool fnStartLoading(object[] param)
  220. {
  221. return _vce.Load();
  222. }
  223. private bool fnLoadingTimeout(object[] param)
  224. {
  225. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  226. {
  227. PostMsg(VceMSG.Error);
  228. return false;
  229. }
  230. return _vce.Status == RState.End;
  231. }
  232. private bool fnStartUnLoading(object[] param)
  233. {
  234. return _vce.UnLoad();
  235. }
  236. private bool fnUnLoadingTimeout(object[] param)
  237. {
  238. if (_vce.Status == RState.Timeout || _vce.Status == RState.Failed)
  239. {
  240. PostMsg(VceMSG.Error);
  241. return false;
  242. }
  243. return _vce.Status == RState.End;
  244. }
  245. public bool Check(int msg, out string reason, params object[] args)
  246. {
  247. reason = "";
  248. return true;
  249. }
  250. public int Invoke(string function, params object[] args)
  251. {
  252. throw new NotImplementedException();
  253. }
  254. public bool CheckAcked(int msg)
  255. {
  256. throw new NotImplementedException();
  257. }
  258. }
  259. }