Task.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.Util;
  4. using EFEM.RT.Tasks;
  5. using Efem.Protocol;
  6. using Aitex.Core.RT.SCCore;
  7. namespace EFEM.RT
  8. {
  9. public interface ITaskT
  10. {
  11. /// <summary>
  12. /// true if executed
  13. /// false not executed
  14. /// </summary>
  15. /// <param name="result"></param>
  16. /// <param name="cmd"></param>
  17. /// <param name="args"></param>
  18. /// <returns></returns>
  19. bool Execute(out string result, string cmd, params string[] args);
  20. /// <returns>
  21. /// null value, wait,
  22. /// true completed,
  23. /// false error
  24. /// </returns>
  25. bool? Monitor(out string result, params string[] args);
  26. bool HasInfoMessage { get; }
  27. bool IsAcked { get; }
  28. bool IsWaitAck { get; }
  29. bool Ack(EfemCommandType type, EfemCommand cmd, params string[] args);
  30. EfemCommandType CommandType { get; }
  31. EfemCommand CommandName { get; }
  32. string CommandData { get; set; }
  33. }
  34. public interface ITask
  35. {
  36. bool Execute(out string result, params string[] args);
  37. /// <returns>
  38. /// novalue, wait, true completed, false error
  39. /// </returns>
  40. bool? Monitor(out string result, params string[] args);
  41. bool HasInfoMessage { get; set; }
  42. }
  43. public class TaskT<T> : ITaskT, ICloneable
  44. where T : ITask, new()
  45. {
  46. private T _imp = default(T);
  47. private double _deley =Convert.ToDouble(SC.GetValue<int>("System.TimeLimitEfemComandDelay"));
  48. private DeviceTimer _timer = new DeviceTimer();
  49. private string _cmd;
  50. private string[] _args;
  51. public bool HasInfoMessage { get { return _imp.HasInfoMessage; } set { }}
  52. public bool IsAcked { get { return true; } }
  53. public bool IsWaitAck
  54. {
  55. get { return false; }
  56. }
  57. public EfemCommandType CommandType
  58. {
  59. get { return _commandType; }
  60. }
  61. public EfemCommand CommandName
  62. {
  63. get { return _commandName; }
  64. }
  65. public string CommandData
  66. {
  67. get;
  68. set;
  69. }
  70. private EfemCommandType _commandType;
  71. private EfemCommand _commandName;
  72. public TaskT(EfemCommandType type, EfemCommand cmd)
  73. {
  74. _commandType = type;
  75. _commandName = cmd;
  76. //if (type == EfemCommandType.SET && cmd == EfemCommand.CSTID)
  77. //{
  78. // _deley = 10;
  79. //}
  80. _imp = new T();
  81. }
  82. public bool Ack(EfemCommandType type, EfemCommand cmd, params string[] args)
  83. {
  84. return true;
  85. }
  86. public bool Execute(out string result, string cmd, params string[] args)
  87. {
  88. result = string.Empty;
  89. _cmd = cmd.Substring(4);
  90. if (!_imp.Execute(out result, args))
  91. {
  92. result = string.Format("CAN:{0}|{1}", _cmd, result);
  93. return false;
  94. }
  95. _args = new string[args.Length];
  96. args.CopyTo(_args, 0);
  97. _timer.Start(_deley*1000);
  98. result = string.Format("ACK:{0}", _cmd);
  99. return true;
  100. }
  101. public bool? Monitor(out string result, params string[] args)
  102. {
  103. result = string.Empty;
  104. /*
  105. if (_timer.IsTimeout())
  106. {
  107. _timer.Stop();
  108. result = string.Format("INF:{0}", _cmd);
  109. return true;
  110. }
  111. return false;
  112. */
  113. bool? ret = _imp.Monitor(out result, _args);
  114. if (ret.HasValue)
  115. {
  116. _timer.Stop();
  117. if(ret.Value) //completed
  118. {
  119. if(string.IsNullOrEmpty(result))
  120. result = string.Format("INF:{0}", _cmd);
  121. else
  122. result = string.Format("INF:{0}/{1}", _cmd, result);
  123. return true;
  124. }
  125. else
  126. {
  127. result = string.Format("ABS:{0}|ERROR/{1}/{2}", _cmd,result, "");
  128. return true;
  129. }
  130. }
  131. if(_timer.IsTimeout())
  132. {
  133. _timer.Stop();
  134. result = string.Format("ABS:{0}|ERROR/{1}/{2}", _cmd, "TIMEOUT", "TIMEOUT");
  135. return false;
  136. }
  137. return null;
  138. }
  139. public object Clone()
  140. {
  141. return this.MemberwiseClone();
  142. }
  143. }
  144. public class TaskFactory
  145. {
  146. private Dictionary<string, ITaskT> _tasks = new Dictionary<string, ITaskT>();
  147. private List<string> _hideTasks = new List<string>();
  148. public TaskFactory()
  149. {
  150. _tasks["MOV.INIT"] = new TaskT<InitTask>(EfemCommandType.MOV, EfemCommand.INIT);
  151. _tasks["MOV.ORGSH"] = new TaskT<OrgshTask>(EfemCommandType.MOV, EfemCommand.ORGSH);
  152. _tasks["MOV.HOME"] = new TaskT<HomeTask>(EfemCommandType.MOV, EfemCommand.HOME);
  153. _tasks["MOV.LOCK"] = new TaskT<LockTask>(EfemCommandType.MOV, EfemCommand.LOCK);
  154. _tasks["MOV.UNLOCK"] = new TaskT<UnlockTask>(EfemCommandType.MOV, EfemCommand.UNLOCK);
  155. _tasks["MOV.DOCK"] = new TaskT<DockTask>(EfemCommandType.MOV, EfemCommand.DOCK);
  156. _tasks["MOV.UNDOCK"] = new TaskT<UnDockTask>(EfemCommandType.MOV, EfemCommand.UNDOCK);
  157. //open cassette wafsh = open
  158. _tasks["MOV.OPEN"] = new TaskT<OpenTask>(EfemCommandType.MOV, EfemCommand.OPEN);
  159. _tasks["MOV.CLOSE"] = new TaskT<CloseDoorTask>(EfemCommandType.MOV, EfemCommand.CLOSE);
  160. _tasks["GET.CSTID"] = new TaskT<CstidTask>(EfemCommandType.GET, EfemCommand.CSTID);
  161. _tasks["SET.CSTID"] = new TaskT<SetCstidTask>(EfemCommandType.SET, EfemCommand.CSTID);
  162. _tasks["MOV.WAFSH"] = new TaskT<WafshTask>(EfemCommandType.MOV, EfemCommand.WAFSH);
  163. _tasks["GET.MAPDT"] = new TaskT<QueryWaferMappingTask>(EfemCommandType.GET, EfemCommand.MAPDT);
  164. _tasks["MOV.ALIGN"] = new TaskT<AlignTaskEx>(EfemCommandType.MOV, EfemCommand.ALIGN);
  165. _tasks["MOV.ALIGN2"] = new TaskT<AlignTaskEx2>(EfemCommandType.MOV, EfemCommand.ALIGN2);
  166. _tasks["MOV.LIFT"] = new TaskT<LiftTask>(EfemCommandType.MOV, EfemCommand.LIFT);
  167. _tasks["MOV.GOTO"] = new TaskT<GotoTask>(EfemCommandType.MOV, EfemCommand.GOTO);
  168. _tasks["MOV.LOAD"] = new TaskT<PickTask>(EfemCommandType.MOV, EfemCommand.LOAD);
  169. _tasks["MOV.UNLOAD"] = new TaskT<PlaceTask>(EfemCommandType.MOV, EfemCommand.UNLOAD);
  170. _tasks["MOV.TRANS"] = new TaskT<TransferTask>(EfemCommandType.MOV, EfemCommand.TRANS);
  171. _tasks["MOV.CHANGE"] = new TaskT<ExchangeTask>(EfemCommandType.MOV, EfemCommand.CHANGE);
  172. _tasks["MOV.MPNT"] = new TaskT<MpntTask>(EfemCommandType.MOV, EfemCommand.MPNT);
  173. _tasks["MOV.EMS"] = new TaskT<EmsTask>(EfemCommandType.MOV, EfemCommand.EMS);
  174. _tasks["MOV.HOLD"] = new TaskT<HoldTask>(EfemCommandType.MOV, EfemCommand.HOLD);
  175. _tasks["MOV.RESTR"] = new TaskT<RestrTask>(EfemCommandType.MOV, EfemCommand.RESTR);
  176. _tasks["MOV.ABORT"] = new TaskT<AbortTask>(EfemCommandType.MOV, EfemCommand.ABORT);
  177. _tasks["SET.ERROR"] = new TaskT<ClearErrorTask>(EfemCommandType.SET, EfemCommand.ERROR);
  178. _tasks["GET.ERROR"] = new TaskT<QueryErrorTask>(EfemCommandType.GET, EfemCommand.ERROR);
  179. _tasks["SET.THICKNESS"] = new TaskT<ThicknessTask>(EfemCommandType.SET, EfemCommand.THICKNESS);
  180. _tasks["GET.THICKNESS"] = new TaskT<GetThicknessTask>(EfemCommandType.GET, EfemCommand.THICKNESS);
  181. //_tasks["SET.SLOTSNUM"] = new TaskT<SetSlotsNumber>(EfemCommandType.SET, EfemCommand.SLOTSNUM);
  182. //_tasks["GET.SLOTSNUM"] = new TaskT<GetSlotsNumber>(EfemCommandType.GET, EfemCommand.SLOTSNUM);
  183. //_tasks["SET.WAFERSIZE"] = new TaskT<SetSlotsNumber>(EfemCommandType.SET, EfemCommand.WAFERSIZE);
  184. //_tasks["GET.WAFERSIZE"] = new TaskT<GetSlotsNumber>(EfemCommandType.GET, EfemCommand.WAFERSIZE);
  185. _tasks["SET.EVENT"] = new TaskT<SetEventTask>(EfemCommandType.SET, EfemCommand.EVENT);
  186. _tasks["GET.EVENT"] = new TaskT<QueryEventTask>(EfemCommandType.GET, EfemCommand.EVENT);
  187. _tasks["SET.SIGOUT"] = new TaskT<SigoutTask>(EfemCommandType.SET, EfemCommand.SIGOUT);
  188. _tasks["GET.SIGSTAT"] = new TaskT<SigStatTask>(EfemCommandType.GET, EfemCommand.SIGSTAT);
  189. _tasks["SET.CLAMP"] = new TaskT<SetClampTask>(EfemCommandType.SET, EfemCommand.CLAMP);
  190. _tasks["GET.CLAMP"] = new TaskT<GetClampTask>(EfemCommandType.GET, EfemCommand.CLAMP);
  191. _tasks["SET.MODE"] = new TaskT<SetModeTask>(EfemCommandType.SET, EfemCommand.MODE);
  192. _tasks["GET.MODE"] = new TaskT<QueryModeTask>(EfemCommandType.GET, EfemCommand.MODE);
  193. _tasks["MOV.TRANSREQ"] = new TaskT<SetTransferTask>(EfemCommandType.MOV, EfemCommand.TRANSREQ);
  194. _tasks["GET.TRANSREQ"] = new TaskT<QueryTransferTask>(EfemCommandType.GET, EfemCommand.TRANSREQ);
  195. _tasks["GET.STATE"] = new TaskT<QueryStateTask>(EfemCommandType.GET, EfemCommand.STATE);
  196. _tasks["MOV.FLIP"] = new TaskT<FlipTask>(EfemCommandType.MOV, EfemCommand.FLIP);
  197. // _tasks["GET.READID"] = new TaskT<QueryStateTask>(EfemCommandType.GET, EfemCommand.READID);
  198. }
  199. public bool UnSupport(EfemCommandType type, EfemCommand cmd)
  200. {
  201. string key = string.Format("{0}.{1}", type, cmd);
  202. return _hideTasks.Exists(item => item == key) || !_tasks.ContainsKey(key);
  203. }
  204. public ITaskT Create(EfemCommandType type, EfemCommand cmd)
  205. {
  206. if (!UnSupport(type,cmd))
  207. {
  208. string key = string.Format("{0}.{1}", type, cmd);
  209. return (ITaskT)(((ICloneable)_tasks[key]).Clone());
  210. }
  211. return null;
  212. }
  213. }
  214. }