TransporterPickUpValidateRoutine.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.Routine;
  7. using MECF.Framework.Common.Utilities;
  8. using MECF.Framework.Common.WaferHolder;
  9. using CyberX8_Core;
  10. using CyberX8_RT.Devices.AXIS;
  11. using CyberX8_RT.Devices.TransPorter;
  12. using CyberX8_RT.Modules.Loader;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using Aitex.Core.Common;
  19. using MECF.Framework.Common.Alarm;
  20. using MECF.Framework.Common.CommonData;
  21. using System.Threading;
  22. using MECF.Framework.Common.SubstrateTrackings;
  23. namespace CyberX8_RT.Modules.Transporter
  24. {
  25. public class TransporterPickUpValidateRoutine : RoutineBase, IRoutine
  26. {
  27. private enum PickUpStep
  28. {
  29. PickUp,
  30. PickUpWait,
  31. ReadBarcodeConfirm,
  32. Place,
  33. PlaceWait,
  34. End
  35. }
  36. #region 内部变量
  37. private string _cellName;
  38. private TransporterPickUpFromRoutine _pickupFromRoutine;
  39. private TransporterPickDownToRoutine _placeRoutine;
  40. private JetAxisBase _gantryAxis;
  41. private TransporterCommon _transporterCommon;
  42. private bool _validate = false;
  43. #endregion
  44. /// <summary>
  45. /// 构造函数
  46. /// </summary>
  47. /// <param name="module"></param>
  48. public TransporterPickUpValidateRoutine(string module) : base(module)
  49. {
  50. _pickupFromRoutine=new TransporterPickUpFromRoutine(module);
  51. _placeRoutine=new TransporterPickDownToRoutine(module);
  52. }
  53. /// <summary>
  54. /// 中止
  55. /// </summary>
  56. public void Abort()
  57. {
  58. Runner.Stop("Manual Abort");
  59. }
  60. /// <summary>
  61. /// 监控
  62. /// </summary>
  63. /// <returns></returns>
  64. public RState Monitor()
  65. {
  66. //1.1 PickupFrom
  67. Runner .Run(PickUpStep.PickUp, () => { return _pickupFromRoutine.Start(_cellName) == RState.Running; }, _delay_1ms)
  68. .WaitWithStopCondition(PickUpStep.PickUpWait, () => CommonFunction.CheckRoutineEndState(_pickupFromRoutine),
  69. () => CheckRoutineStopStatus(_pickupFromRoutine, "PickUpValidate Routine", _pickupFromRoutine.ErrorMsg, 0))
  70. //2.1 Read Barcode 确认与Material Tracking的转移是否一致
  71. .Run(PickUpStep.ReadBarcodeConfirm, ReadBarcode, _delay_1ms)
  72. .RunIf(PickUpStep.Place, !_validate, ()=> { return _placeRoutine.Start(_cellName) == RState.Running; },_delay_1ms )
  73. .WaitWithStopConditionIf(PickUpStep.PlaceWait,!_validate, () => CommonFunction.CheckRoutineEndState(_placeRoutine),
  74. () => CheckRoutineStopStatus(_placeRoutine, "Place Routine", _placeRoutine.ErrorMsg, 1))
  75. .End(PickUpStep.End,NullFun,100);
  76. return Runner.Status;
  77. }
  78. /// <summary>
  79. /// 检验Routine异常结束状态
  80. /// </summary>
  81. /// <param name="routine"></param>
  82. /// <returns></returns>
  83. private bool CheckRoutineStopStatus(IRoutine routine, string routineName, string errorMsg, int step)
  84. {
  85. RState ret = routine.Monitor();
  86. if (ret == RState.Failed || ret == RState.Timeout)
  87. {
  88. NotifyError(eEvent.ERR_TRANSPORTER, $"PickUp Validate WaferHolder Routine\r\n{routineName}\\r\n{errorMsg}", step);
  89. return true;
  90. }
  91. return false;
  92. }
  93. /// <summary>
  94. /// 读取条码
  95. /// </summary>
  96. /// <returns></returns>
  97. private bool ReadBarcode()
  98. {
  99. //临时注销reader barcode 2025-03-15
  100. _validate = true;
  101. return true;
  102. TransporterEntity transporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(Module.ToString());
  103. if (transporterEntity == null)
  104. {
  105. return true;
  106. }
  107. WaferHolderInfo waferHolderInfo = transporterEntity.WaferHolderInfo;
  108. if (waferHolderInfo == null)
  109. {
  110. return true;
  111. }
  112. bool isSimulator = SC.GetValue<bool>("System.IsSimulatorMode");
  113. string str = CycleReadBarcode(isSimulator);
  114. string error = "";
  115. if(!string.IsNullOrEmpty(str))
  116. {
  117. if (waferHolderInfo.Id == str)
  118. {
  119. _validate = true;
  120. }
  121. else
  122. {
  123. error = $"Wafer Shuttle Id {waferHolderInfo?.Id} is not matched with reader {str}";
  124. _validate = false;
  125. }
  126. }
  127. else
  128. {
  129. if (isSimulator)
  130. {
  131. _validate = true;
  132. return true;
  133. }
  134. error = $"reader data is empty";
  135. }
  136. if (!_validate)
  137. {
  138. if (CheckWaferHolderAllAssistWafers(waferHolderInfo))
  139. {
  140. WaferHolderManager.Instance.DisableWaferHolder(waferHolderInfo);
  141. LOG.WriteLog(eEvent.WARN_TRANSPORTER, Module, error);
  142. LOG.WriteLog(eEvent.WARN_TRANSPORTER, Module, $"disable WaferHolder {waferHolderInfo.Id}");
  143. AlarmList alarmList = new AlarmList(Module.ToString(), "", 0, error, 0, (int)AlarmType.Warning);
  144. AlarmListManager.Instance.AddAlarm(alarmList);
  145. }
  146. else
  147. {
  148. _validate = true;
  149. }
  150. }
  151. return true;
  152. }
  153. /// <summary>
  154. /// 检验WaferHolder所有的Wafer是辅助片
  155. /// </summary>
  156. /// <param name="waferHolderInfo"></param>
  157. /// <returns></returns>
  158. private bool CheckWaferHolderAllAssistWafers(WaferHolderInfo waferHolderInfo)
  159. {
  160. if (!string.IsNullOrEmpty(waferHolderInfo.WaferAId))
  161. {
  162. WaferInfo waferInfo = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferAId);
  163. if (waferInfo!=null&&waferInfo.WaferType!=WaferType.Assit)
  164. {
  165. return false;
  166. }
  167. }
  168. if (!string.IsNullOrEmpty(waferHolderInfo.WaferBId))
  169. {
  170. WaferInfo waferInfo = WaferManager.Instance.GetWaferByWaferId(waferHolderInfo.WaferBId);
  171. if (waferInfo != null && waferInfo.WaferType != WaferType.Assit)
  172. {
  173. return false;
  174. }
  175. }
  176. return true;
  177. }
  178. /// <summary>
  179. /// 循环读取Barcode
  180. /// </summary>
  181. /// <param name="isSimulator"></param>
  182. /// <returns></returns>
  183. private string CycleReadBarcode(bool isSimulator)
  184. {
  185. int count = 0;
  186. string str = "";
  187. //读取Barcode3遍
  188. while (count < 3)
  189. {
  190. str = _transporterCommon.ReaderBarcode();
  191. str = str.Trim();
  192. if (!string.IsNullOrEmpty(str))
  193. {
  194. break;
  195. }
  196. if (isSimulator)
  197. {
  198. break;
  199. }
  200. Thread.Sleep(10);
  201. }
  202. return str;
  203. }
  204. /// <summary>
  205. /// 启动
  206. /// </summary>
  207. /// <param name="objs"></param>
  208. /// <returns></returns>
  209. public RState Start(params object[] objs)
  210. {
  211. _cellName = objs[0].ToString();
  212. _transporterCommon = DEVICE.GetDevice<TransporterCommon>($"{Module}.Common");
  213. _gantryAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Gantry");
  214. _validate = false;
  215. return Runner.Start(Module, $"PickUpValidate {_cellName}");
  216. }
  217. /// <summary>
  218. /// 重试
  219. /// </summary>
  220. /// <param name="step"></param>
  221. public RState Retry(int step)
  222. {
  223. if (string.IsNullOrEmpty(_cellName))
  224. {
  225. NotifyError(eEvent.ERR_TRANSPORTER, "source cell is empty", step);
  226. return RState.Failed;
  227. }
  228. List<Enum> preStepIds = new List<Enum>();
  229. if (step == 0 || step == -1)
  230. {
  231. return Runner.Retry(PickUpStep.PickUp, preStepIds, Module, "PickUp Validate Retry");
  232. }
  233. else
  234. {
  235. AddPreSteps(PickUpStep.Place, preStepIds);
  236. return Runner.Retry(PickUpStep.Place, preStepIds, Module, $"Pickup Validate step {PickUpStep.Place} Retry");
  237. }
  238. }
  239. /// <summary>
  240. /// 忽略前步骤
  241. /// </summary>
  242. /// <param name="step"></param>
  243. /// <param name="preStepIds"></param>
  244. private void AddPreSteps(PickUpStep step, List<Enum> preStepIds)
  245. {
  246. for (int i = 0; i < (int)step; i++)
  247. {
  248. preStepIds.Add((PickUpStep)i);
  249. }
  250. }
  251. /// <summary>
  252. /// 检验前面Unload完成状态
  253. /// </summary>
  254. /// <returns></returns>
  255. public bool CheckCompleteCondition(int index)
  256. {
  257. TransporterEntity transporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(Module);
  258. if (transporterEntity.WaferHolderInfo == null)
  259. {
  260. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} does not have waferholder", index);
  261. return false;
  262. }
  263. double gantryPsition = _gantryAxis.MotionData.MotorPosition;
  264. if (!_gantryAxis.CheckPositionIsInStation(gantryPsition, _cellName))
  265. {
  266. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} gantry not in {_cellName}", index);
  267. return false;
  268. }
  269. return true;
  270. }
  271. }
  272. }