AlignRoutine.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  1. using System;
  2. using System.Windows;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.RT.Device;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using Aitex.Sorter.Common;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  11. using Aitex.Sorter.RT.Module;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.SubstrateTrackings;
  14. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  15. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.OcrReaders;
  16. using MECF.Framework.Common.DBCore;
  17. using FACore;
  18. using Aitex.Sorter.RT.SorterCommonFrame.SorterJobControl;
  19. using Aitex.Sorter.RT.SorterCommonFrame.Modules;
  20. using Aitex.Sorter.RT.Module.Recipe;
  21. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.AlignersBase;
  22. using System.Threading;
  23. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  24. using System.Text;
  25. using Aitex.Core.RT.Log;
  26. namespace Aitex.Sorter.RT.SorterCommonFrame.Routines
  27. {
  28. internal class AlignRoutine : CommonRoutineSorter, IRoutine
  29. {
  30. private enum Align
  31. {
  32. AlignForReader,
  33. WaitAlignForReader,
  34. ReaderWaferID,
  35. ReaderWaferID2,
  36. VerifyLM1WaitInput,
  37. VerifyLM2WaitInput,
  38. VerifyLM1WithHostDefine,
  39. VerifyLM2WithHostDefine,
  40. Align,
  41. WaitAlign,
  42. SendEventPreAlign,
  43. SendEventPostAlign,
  44. SendEventLM1,
  45. SendEventLM2,
  46. ReleaseAligner,
  47. WaitComplete,
  48. Finish,
  49. UpdateWaferNextStation,
  50. UpdataWaferProcessState,
  51. WaitOcrReady1,
  52. WaitOcrReady2,
  53. WaitOcrReady3,
  54. WaitOcrReady4,
  55. WaitOcrReady5,
  56. WaitOcrReady6,
  57. SaveOcrImage1,
  58. SaveOcrImage2,
  59. Retry,
  60. Retry2 =100,
  61. SetRetryFlag1,
  62. SetRetryFlag2,
  63. SetRetryFlag3,
  64. }
  65. private enum AlignEventType
  66. {
  67. PreAlignEnd,
  68. PostAlignEnd,
  69. ReadLM1,
  70. ReadLM2,
  71. }
  72. private ReadWaferIDRecipe _aligneRecipe;
  73. public ReadWaferIDRecipe AlignerRecipe
  74. {
  75. get => _aligneRecipe;
  76. set { _aligneRecipe = value; }
  77. }
  78. private ModuleName _alignerModulename = ModuleName.Aligner;
  79. public ModuleName AlignerModulename
  80. {
  81. get => _alignerModulename;
  82. set { _alignerModulename = value; }
  83. }
  84. private bool _isRemoteJob= false;
  85. public bool IsRemoteJob
  86. {
  87. get => _isRemoteJob;
  88. set { IsRemoteJob = value; }
  89. }
  90. public bool IsNeedRetryLaserMark1;
  91. public bool IsNeedRetryLaserMark2;
  92. public bool IsVerifyLM1WaitManualInput { get; private set; }
  93. public bool IsVerifyLM1WithHostDefine { get; private set; }
  94. public bool IsVerifyLM2WaitManualInput { get; private set; }
  95. public bool IsVerifyLM2WithHostDefine { get; private set; }
  96. private int _timeoutAlign => Aligner.TimeLimitAlignWafer;
  97. private int _timeoutReadOcr => Aligner.TimeLimitReadOcr;
  98. private int _timeoutVerifyOcr => Aligner.TimeLimitVerifyOcr;
  99. private int _retryTimes
  100. {
  101. get
  102. {
  103. if (SC.ContainsItem("Process.OcrRetryTimes"))
  104. return SC.GetValue<int>("Process.OcrRetryTimes");
  105. return 0;
  106. }
  107. }
  108. public const string EventStartAlign = "WAFER_ALIGN_START";
  109. public const string EventEndAlign = "WAFER_ALIGN_END";
  110. public const string AlarmAlignFailed = "AlignerAligningFailed";
  111. public const string EventWaferIdRead = "WAFER_LM_READ";
  112. public const string EventWaferIdReadFail = "WAFER_LM_READ_FAILED";
  113. public const string EventWaferIdVerifyFailed = "AlignerVerifyLaserMarkFailed";
  114. public const string EventWaferIdVerifySucceeded = "WAFER_LM_VERIFY_SUCCEEDED";
  115. public const string EventStartReturnLot = "START_RETURN_LOT";
  116. public AlignRoutine(string module, string name)
  117. {
  118. Name = module + name;
  119. }
  120. public bool Initalize()
  121. {
  122. Reset();
  123. IsRoutineActive = false;
  124. return true;
  125. }
  126. private bool IsOnSortingByID
  127. {
  128. get
  129. {
  130. if (Singleton<RouteManagerSorter>.Instance.CurrentSorterRTStateEnum == SorterRTStateEnum.SortingByID)
  131. return true;
  132. if (Singleton<RouteManagerSorter>.Instance.CurrentSorterRTStateEnum == SorterRTStateEnum.Canceling)
  133. return SorterJobManager.Instance.IsOnCancelSortingByID;
  134. return false;
  135. }
  136. }
  137. private bool IsOnDispatchByID
  138. {
  139. get
  140. {
  141. if (Singleton<RouteManagerSorter>.Instance.CurrentSorterRTStateEnum == SorterRTStateEnum.DispatchingByID)
  142. return true;
  143. return false;
  144. }
  145. }
  146. private bool IsOnSortingBySlot
  147. {
  148. get
  149. {
  150. if (Singleton<RouteManagerSorter>.Instance.CurrentSorterRTStateEnum == SorterRTStateEnum.SortingBySlot)
  151. return true;
  152. if (Singleton<RouteManagerSorter>.Instance.CurrentSorterRTStateEnum == SorterRTStateEnum.Canceling)
  153. return SorterJobManager.Instance.IsOnCancelSortingBySlot;
  154. return false;
  155. }
  156. }
  157. private double ConvertPreAlignAngle(double anglesp)
  158. {
  159. if (Aligner.IsReversePreAlignDirection) return anglesp * -1;
  160. return anglesp;
  161. }
  162. private double ConvertPostAlignAngle(double anglesp)
  163. {
  164. if (Aligner.IsReversePostAlignDirection) return anglesp * -1;
  165. return anglesp;
  166. }
  167. private bool _isSaveImageInRoutine
  168. {
  169. get
  170. {
  171. if (SC.ContainsItem("Process.SaveOcrImage"))
  172. return SC.GetValue<bool>("Process.SaveOcrImage");
  173. return false;
  174. }
  175. }
  176. public Result Start(params object[] paras)
  177. {
  178. Reset();
  179. Aligner = DEVICE.GetDevice<AlignerBaseDevice>(_alignerModulename.ToString());
  180. var wafer = WaferManager.Instance.GetWafers(AlignerModulename)[0];
  181. WaferManager.Instance.UpdateWaferProcessStatus(AlignerModulename, 0, EnumWaferProcessStatus.InProcess);
  182. if (!wafer.IsEmpty)
  183. {
  184. var carrierId = wafer.OriginCarrierID;
  185. var slotNumber = wafer.OriginSlot+1;
  186. var dvid = new SerializableDictionary<string, object>()
  187. {
  188. {DVIDName.LOT_ID, wafer.LotId},
  189. {DVIDName.WAFER_ID, wafer.WaferID},
  190. {DVIDName.CAR_ID, carrierId},
  191. {DVIDName.SLOT_NO, slotNumber},
  192. {DVIDName.ARRIVE_POS_NAME, "ALN1"},
  193. };
  194. EV.Notify(EventStartAlign, dvid);
  195. }
  196. IsVerifyLM1WaitManualInput = _aligneRecipe.IsVerifyLaserMarker1 &&
  197. (_aligneRecipe.IsVerifyLaserMarkLength || _aligneRecipe.IsVerifyLaserMarkSlotForNCD || _aligneRecipe.IsVerifyChecksumLaserMarker1);
  198. IsVerifyLM1WithHostDefine = _aligneRecipe.IsVerifyLaserMarker1 && _aligneRecipe.IsVerifyWithHostDefine;
  199. IsVerifyLM2WaitManualInput = _aligneRecipe.IsVerifyLaserMarker2 &&
  200. (_aligneRecipe.IsVerifyLaserMarkLength || _aligneRecipe.IsVerifyLaserMarkSlotForNCD || _aligneRecipe.IsVerifyChecksumLaserMarker2);
  201. IsVerifyLM2WithHostDefine = _aligneRecipe.IsVerifyLaserMarker2 && _aligneRecipe.IsVerifyWithHostDefine;
  202. if (_aligneRecipe.IsReadLaserMarker1 && _aligneRecipe.OcrReaderJob1.Count <= 0)
  203. {
  204. EV.Notify(AlarmAlignFailed);
  205. return Result.FAIL;
  206. }
  207. if (_aligneRecipe.IsReadLaserMarker2 && _aligneRecipe.OcrReaderJob2.Count <= 0)
  208. {
  209. EV.Notify(AlarmAlignFailed);
  210. return Result.FAIL;
  211. }
  212. if (_aligneRecipe.IsReadLaserMarker1)
  213. {
  214. if (string.IsNullOrEmpty(_aligneRecipe.OcrReaderJob1[0]))
  215. {
  216. EV.PostAlarmLog("System", $"Invalid job1 setting in sub recipe:{_aligneRecipe.RecipeName}.");
  217. EV.Notify(AlarmAlignFailed);
  218. return Result.FAIL;
  219. }
  220. }
  221. if (_aligneRecipe.IsReadLaserMarker2)
  222. {
  223. if (string.IsNullOrEmpty(_aligneRecipe.OcrReaderJob2[0]))
  224. {
  225. EV.PostAlarmLog("System", $"Invalid job2 setting in sub recipe:{_aligneRecipe.RecipeName}.");
  226. EV.Notify(AlarmAlignFailed);
  227. return Result.FAIL;
  228. }
  229. }
  230. Reset();
  231. EV.PostInfoLog("System", "Start to implement alignment routine");
  232. IsRoutineActive = true;
  233. return Monitor();
  234. }
  235. public Result Monitor()
  236. {
  237. if (!IsRoutineActive)
  238. return Result.DONE;
  239. var ret = MonitorRoutine();
  240. if (ret == Result.FAIL)
  241. {
  242. IsRoutineActive = false;
  243. }
  244. if (ret == Result.DONE)
  245. {
  246. IsRoutineActive = false;
  247. }
  248. return ret;
  249. }
  250. private Result MonitorRoutine()
  251. {
  252. try
  253. {
  254. if (_aligneRecipe != null)
  255. {
  256. if (_aligneRecipe.IsPreAlign)
  257. {
  258. RtPreAlignWafer((int)Align.AlignForReader, "Pre align the wafer", ConvertPreAlignAngle(_aligneRecipe.PreAlignAngle), Notify);
  259. if (ExecuteResult.Item1)
  260. {
  261. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  262. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  263. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  264. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  265. }
  266. RtWaitAlignerMotion((int)Align.WaitAlignForReader, Aligner, "Wait to finish the pre-alignment", _timeoutAlign, Notify, Stop);
  267. if (ExecuteResult.Item1)
  268. {
  269. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  270. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  271. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  272. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  273. }
  274. }
  275. if (_aligneRecipe.IsReadLaserMarker1)
  276. {
  277. RtWaitReaderReady((int)Align.WaitOcrReady1, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify, Stop);
  278. if (ExecuteResult.Item1)
  279. {
  280. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  281. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  282. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  283. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  284. }
  285. RtReadWaferID((int)Align.ReaderWaferID, _alignerModulename, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  286. 0, _aligneRecipe.OcrReaderJob1[0], Notify);
  287. if (ExecuteResult.Item1)
  288. {
  289. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  290. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  291. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  292. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  293. }
  294. RtWaitReaderReady((int)Align.WaitOcrReady2, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  295. Notify, Stop);
  296. if (ExecuteResult.Item1)
  297. {
  298. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  299. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  300. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  301. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  302. }
  303. if (_isSaveImageInRoutine)
  304. {
  305. RtSaveOcrPicture((int)Align.SaveOcrImage1, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify);
  306. if (ExecuteResult.Item1)
  307. {
  308. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  309. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  310. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  311. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  312. }
  313. }
  314. RtSetRetryLaserMarkFlag((int)Align.SetRetryFlag1,0, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify);
  315. if (ExecuteResult.Item1)
  316. {
  317. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  318. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  319. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  320. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  321. }
  322. if(IsNeedRetryLaserMark1)
  323. {
  324. for(int i=0;i<_retryTimes;i++)
  325. {
  326. RtAlignWaferForRetry((int)Align.Retry + 1 + i * 8, i+1,ConvertPreAlignAngle(_aligneRecipe.PreAlignAngle), Aligner.OCRs[_aligneRecipe.LaserMarkerWaferReaderIndex1 - 1], Notify);
  327. if (ExecuteResult.Item1)
  328. {
  329. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  330. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  331. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  332. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  333. }
  334. RtWaitAlignerMotion((int)Align.Retry + 2 + i * 8, Aligner, "Wait to finish the pre-alignment for retry ocr read", _timeoutAlign, Notify, Stop);
  335. if (ExecuteResult.Item1)
  336. {
  337. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  338. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  339. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  340. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  341. }
  342. RtWaitReaderReady((int)Align.Retry + 3 + i * 8, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  343. Notify, Stop);
  344. if (ExecuteResult.Item1)
  345. {
  346. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  347. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  348. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  349. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  350. }
  351. RtReadWaferIDForRetry((int)Align.Retry + 4 + i * 8,i+1, _alignerModulename, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  352. 0, _aligneRecipe.OcrReaderJob1[0], Notify);
  353. if (ExecuteResult.Item1)
  354. {
  355. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  356. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  357. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  358. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  359. }
  360. RtWaitReaderReady((int)Align.Retry + 5 + i * 8, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  361. Notify, Stop);
  362. if (ExecuteResult.Item1)
  363. {
  364. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  365. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  366. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  367. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  368. }
  369. if (_isSaveImageInRoutine)
  370. {
  371. RtSaveOcrPicture((int)Align.Retry + 6 + i * 8, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify);
  372. if (ExecuteResult.Item1)
  373. {
  374. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  375. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  376. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  377. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  378. }
  379. }
  380. RtSetRetryLaserMarkFlag((int)Align.Retry + 7 + i*8, 0, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify);
  381. if (ExecuteResult.Item1)
  382. {
  383. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  384. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  385. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  386. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  387. }
  388. }
  389. }
  390. //RtWaitReaderReady((int)Align.WaitOcrReady3, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  391. // Notify, Stop);
  392. //if (ExecuteResult.Item1)
  393. //{
  394. // if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  395. // if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  396. // if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  397. // if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  398. //}
  399. RtSendReadResult((int)Align.SendEventLM1, _alignerModulename, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  400. 0, _aligneRecipe.OcrReaderJob1[0], Notify);
  401. if (ExecuteResult.Item1)
  402. {
  403. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  404. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  405. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  406. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  407. }
  408. if (IsVerifyLM1WaitManualInput)
  409. {
  410. RtVerifyWaferIDAndWaitManualInput((int)Align.VerifyLM1WaitInput, _alignerModulename, _timeoutVerifyOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  411. 0, Notify, Stop);
  412. if (ExecuteResult.Item1)
  413. {
  414. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  415. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  416. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  417. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  418. }
  419. }
  420. if (IsVerifyLM1WithHostDefine)
  421. {
  422. RtVerifyWaferIDWithHostDefine((int)Align.VerifyLM1WithHostDefine, _alignerModulename, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  423. 0, Notify, Stop);
  424. if (ExecuteResult.Item1)
  425. {
  426. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  427. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  428. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  429. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  430. }
  431. }
  432. }
  433. if (_aligneRecipe.IsReadLaserMarker2)
  434. {
  435. RtWaitReaderReady((int)Align.WaitOcrReady4, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify, Stop);
  436. if (ExecuteResult.Item1)
  437. {
  438. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  439. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  440. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  441. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  442. }
  443. RtReadWaferID((int)Align.ReaderWaferID2, _alignerModulename, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  444. 1, _aligneRecipe.OcrReaderJob2[0], Notify);
  445. if (ExecuteResult.Item1)
  446. {
  447. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  448. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  449. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  450. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  451. }
  452. RtWaitReaderReady((int)Align.WaitOcrReady5, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  453. Notify, Stop);
  454. if (ExecuteResult.Item1)
  455. {
  456. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  457. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  458. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  459. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  460. }
  461. if (_isSaveImageInRoutine)
  462. {
  463. RtSaveOcrPicture((int)Align.SaveOcrImage2, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify);
  464. if (ExecuteResult.Item1)
  465. {
  466. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  467. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  468. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  469. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  470. }
  471. }
  472. RtSetRetryLaserMarkFlag((int)Align.SetRetryFlag1, 1, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify);
  473. if (ExecuteResult.Item1)
  474. {
  475. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  476. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  477. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  478. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  479. }
  480. if(IsNeedRetryLaserMark2)
  481. {
  482. for(int j=0;j<_retryTimes;j++)
  483. {
  484. RtAlignWaferForRetry((int)Align.Retry2+j*8,j+1, ConvertPreAlignAngle(_aligneRecipe.PreAlignAngle), Aligner.OCRs[_aligneRecipe.LaserMarkerWaferReaderIndex1 - 1], Notify);
  485. if (ExecuteResult.Item1)
  486. {
  487. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  488. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  489. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  490. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  491. }
  492. RtWaitAlignerMotion((int)Align.Retry2 + 1 + j * 8, Aligner, "Wait to finish the pre-alignment for retry ocr read", _timeoutAlign, Notify, Stop);
  493. if (ExecuteResult.Item1)
  494. {
  495. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  496. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  497. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  498. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  499. }
  500. RtWaitReaderReady((int)Align.Retry2 + 2 + j * 8, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  501. Notify, Stop);
  502. if (ExecuteResult.Item1)
  503. {
  504. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  505. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  506. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  507. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  508. }
  509. RtReadWaferIDForRetry((int)Align.Retry2 + 3 + j * 8,j+1, _alignerModulename, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  510. 1, _aligneRecipe.OcrReaderJob2[0], Notify);
  511. if (ExecuteResult.Item1)
  512. {
  513. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  514. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  515. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  516. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  517. }
  518. RtWaitReaderReady((int)Align.Retry2 + 4 + j * 8, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  519. Notify, Stop);
  520. if (ExecuteResult.Item1)
  521. {
  522. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  523. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  524. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  525. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  526. }
  527. if (_isSaveImageInRoutine)
  528. {
  529. RtSaveOcrPicture((int)Align.Retry2 + 5 + j * 8, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify);
  530. if (ExecuteResult.Item1)
  531. {
  532. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  533. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  534. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  535. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  536. }
  537. }
  538. RtSetRetryLaserMarkFlag((int)Align.Retry2 + 6 + j * 8, 1, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, Notify);
  539. if (ExecuteResult.Item1)
  540. {
  541. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  542. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  543. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  544. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  545. }
  546. }
  547. }
  548. //RtWaitReaderReady((int)Align.WaitOcrReady6, _timeoutReadOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  549. // Notify, Stop);
  550. //if (ExecuteResult.Item1)
  551. //{
  552. // if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  553. // if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  554. // if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  555. // if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  556. //}
  557. RtSendReadResult((int)Align.SendEventLM2, _alignerModulename, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1,
  558. 1, _aligneRecipe.OcrReaderJob2[0], Notify);
  559. if (ExecuteResult.Item1)
  560. {
  561. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  562. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  563. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  564. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  565. }
  566. if (IsVerifyLM2WaitManualInput)
  567. {
  568. RtVerifyWaferIDAndWaitManualInput((int)Align.VerifyLM2WaitInput, _alignerModulename, _timeoutVerifyOcr, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, 0, Notify, Stop);
  569. if (ExecuteResult.Item1)
  570. {
  571. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  572. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  573. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  574. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  575. }
  576. }
  577. if (IsVerifyLM2WithHostDefine)
  578. {
  579. RtVerifyWaferIDWithHostDefine((int)Align.VerifyLM2WithHostDefine, _alignerModulename, _aligneRecipe.LaserMarkerWaferReaderIndex1 - 1, 1, Notify, Stop);
  580. if (ExecuteResult.Item1)
  581. {
  582. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  583. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  584. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  585. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  586. }
  587. }
  588. }
  589. if (_aligneRecipe.IsPostAlign)
  590. {
  591. RtPostAlignWafer((int)Align.Align, "Post align the wafer", ConvertPostAlignAngle(_aligneRecipe.PostAlignAngle) + Aligner.PostAlignCompensationAngleValue, Notify);
  592. if (ExecuteResult.Item1)
  593. {
  594. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  595. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  596. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  597. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  598. }
  599. RtWaitAlignerMotion((int)Align.WaitAlign, Aligner, "Wait to finish post-alignment", _timeoutAlign, Notify, Stop);
  600. if (ExecuteResult.Item1)
  601. {
  602. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  603. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  604. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  605. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  606. }
  607. }
  608. }
  609. if (IsOnSortingByID)
  610. {
  611. RtUpdateWaferNextStationOnSortingByHost((int)Align.UpdateWaferNextStation, Notify, Stop);
  612. if (ExecuteResult.Item1)
  613. {
  614. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  615. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  616. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  617. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  618. }
  619. }
  620. if (IsOnSortingBySlot)
  621. {
  622. RtUpdateWaferNextStationOnSortingBySlot((int)Align.UpdateWaferNextStation, Notify, Stop);
  623. if (ExecuteResult.Item1)
  624. {
  625. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  626. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  627. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  628. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  629. }
  630. }
  631. if (IsOnDispatchByID)
  632. {
  633. RtUpdateWaferNextStationOnDispatchByID((int)Align.UpdateWaferNextStation, Notify, Stop);
  634. if (ExecuteResult.Item1)
  635. {
  636. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  637. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  638. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  639. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  640. }
  641. }
  642. RtUpdateWaferSingleStepProcessState((int)Align.UpdataWaferProcessState, "Update wafer to processed.", AlignerModulename, 0, Hand.Both, EnumWaferProcessStatus.Completed, Notify, Stop);
  643. if (ExecuteResult.Item1)
  644. {
  645. if (ExecuteResult.Item2 == Result.RUN) return Result.RUN;
  646. if (ExecuteResult.Item2 == Result.FAIL) return Result.FAIL;
  647. if (ExecuteResult.Item2 == Result.TIMEOUT) return Result.FAIL;
  648. if (ExecuteResult.Item2 == Result.DONE) return Result.DONE;
  649. }
  650. EV.PostInfoLog("System", $"Complete wafer align routine.");
  651. IsRoutineActive = false;
  652. return Result.DONE;
  653. }
  654. catch (Exception ex)
  655. {
  656. LOG.Write(ex);
  657. IsRoutineActive = false;
  658. return Result.FAIL;
  659. }
  660. }
  661. public new void Abort()
  662. {
  663. base.Abort();
  664. }
  665. public Tuple<bool, Result> RtUpdateWaferNextStationOnSortingByHost(int id, Action<string> notify, Action<string> error)
  666. {
  667. Tuple<bool, Result> ret = Execute(id, () =>
  668. {
  669. notify("Update wafer to next station sorting by host.");
  670. var wafer = WaferManager.Instance.GetWafer(AlignerModulename, 0);
  671. int slot = Singleton<SorterJobManager>.Instance.GetSlot(wafer.LaserMarker);
  672. if (slot == -1)
  673. {
  674. wafer.DestinationStation = wafer.OriginStation;
  675. wafer.NextStation = wafer.OriginStation;
  676. wafer.DestinationSlot = wafer.OriginSlot;
  677. wafer.NextStationSlot = wafer.OriginSlot;
  678. EV.PostAlarmLog("System", $"Can't find the postion for wafer with ID:{wafer.LaserMarker}.");
  679. Singleton<RouteManagerSorter>.Instance.CheckToPostMsg(RouteManagerSorter.MSG.CancelJob);
  680. return true;
  681. }
  682. wafer.DestinationStation = Singleton<SorterJobManager>.Instance.SortByHostDestPort;
  683. wafer.NextStation = Singleton<SorterJobManager>.Instance.SortByHostDestPort;
  684. wafer.DestinationSlot = slot-1;
  685. wafer.NextStationSlot = slot-1;
  686. if (Singleton<SorterJobManager>.Instance.SortByHostSourcePort != Singleton<SorterJobManager>.Instance.SortByHostDestPort
  687. && WaferManager.Instance.CheckHasWafer((ModuleName)wafer.NextStation, wafer.NextStationSlot))
  688. {
  689. wafer.DestinationStation = wafer.OriginStation;
  690. wafer.NextStation = wafer.OriginStation;
  691. wafer.DestinationSlot = wafer.OriginSlot;
  692. wafer.NextStationSlot = wafer.OriginSlot;
  693. EV.PostAlarmLog("System", $"The destination was occuppied for wafer with ID:{wafer.LaserMarker}.");
  694. Singleton<RouteManagerSorter>.Instance.CheckToPostMsg(RouteManagerSorter.MSG.CancelJob);
  695. return true;
  696. }
  697. return true;
  698. });
  699. if (ret.Item1)
  700. {
  701. if (ret.Item2 == Result.FAIL)
  702. {
  703. error(String.Format("Failed to update wafer information to nex station OnSortingByHost."));
  704. }
  705. }
  706. return ret;
  707. }
  708. public Tuple<bool, Result> RtUpdateWaferNextStationOnSortingBySlot(int id, Action<string> notify, Action<string> error)
  709. {
  710. Tuple<bool, Result> ret = Execute(id, () =>
  711. {
  712. notify("Update wafer to next station sorting by slot.");
  713. var wafer = WaferManager.Instance.GetWafer(AlignerModulename, 0);
  714. int slot = ParseSlot(wafer.LaserMarker,Singleton<SorterJobManager>.Instance.SortByHostSlotIndex);
  715. if (slot == -1)
  716. {
  717. wafer.DestinationStation = wafer.OriginStation;
  718. wafer.NextStation = wafer.OriginStation;
  719. wafer.DestinationSlot = wafer.OriginSlot;
  720. wafer.NextStationSlot = wafer.OriginSlot;
  721. Singleton<RouteManagerSorter>.Instance.CheckToPostMsg(RouteManagerSorter.MSG.CancelJob);
  722. EV.PostAlarmLog("System", $"Can't find the postion for wafer with ID:{wafer.LaserMarker}.");
  723. return true;
  724. }
  725. wafer.DestinationStation = Singleton<SorterJobManager>.Instance.SortByHostDestPort;
  726. wafer.NextStation = Singleton<SorterJobManager>.Instance.SortByHostDestPort;
  727. wafer.DestinationSlot = slot - 1;
  728. wafer.NextStationSlot = slot - 1;
  729. if (Singleton<SorterJobManager>.Instance.SortByHostSourcePort != Singleton<SorterJobManager>.Instance.SortByHostDestPort
  730. && WaferManager.Instance.CheckHasWafer((ModuleName)wafer.NextStation,wafer.NextStationSlot))
  731. {
  732. wafer.DestinationStation = wafer.OriginStation;
  733. wafer.NextStation = wafer.OriginStation;
  734. wafer.DestinationSlot = wafer.OriginSlot;
  735. wafer.NextStationSlot = wafer.OriginSlot;
  736. Singleton<RouteManagerSorter>.Instance.CheckToPostMsg(RouteManagerSorter.MSG.CancelJob);
  737. EV.PostAlarmLog("System", $"The destination was occuppied for wafer with ID:{wafer.LaserMarker}.");
  738. return true;
  739. }
  740. return true;
  741. });
  742. if (ret.Item1)
  743. {
  744. if (ret.Item2 == Result.FAIL)
  745. {
  746. error(String.Format("Failed to update wafer information to next station OnSortingBySlot."));
  747. }
  748. }
  749. return ret;
  750. }
  751. private int ParseSlot(string waferID,int index)
  752. {
  753. if (waferID.Length < index + 1) return -1;
  754. string strSlot = waferID.Substring(index - 1, 2);
  755. int ret;
  756. if(int.TryParse(strSlot,out ret))
  757. {
  758. if (ret <= 0) return - 1;
  759. if (ret > 25) return -1;
  760. return ret;
  761. }
  762. return -1;
  763. }
  764. public void RtAlignWaferForRetry(int id,int timeNo, double notch,OCRReaderBaseDevice reader, Action<string> notify)
  765. {
  766. var ret = Execute(id, () =>
  767. {
  768. var reason = string.Empty;
  769. if (reader.ReadOK)
  770. {
  771. notify($"Skip the re-alignment for read ocr base on the result OK");
  772. return true;
  773. }
  774. notify($"start to re-align the wafer to read ocr for the {timeNo}st time");
  775. Aligner.Align(notch, out reason);
  776. return true;
  777. });
  778. }
  779. private void RtReadWaferIDForRetry(int id,int timeNo, ModuleName name, int ocrindex, int waferIDindex, string job, Action<string> notify)
  780. {
  781. var ret = Execute(id, () =>
  782. {
  783. var reason = string.Empty;
  784. if(Aligner.OCRs[ocrindex].ReadOK)
  785. {
  786. notify($"Skip re-read laser mark with reader:{ocrindex} for the NO.{waferIDindex + 1} ID.");
  787. return true;
  788. }
  789. notify($"Start re-read laser mark with reader:{ocrindex} for the NO.{waferIDindex + 1} ID for the {timeNo}st time");
  790. if (!Aligner.OCRs[ocrindex].ReadWaferID(job, waferIDindex))
  791. {
  792. var wafer = WaferManager.Instance.GetWafers(name)[0];
  793. var destlp = DEVICE.GetDevice<LoadPortBaseDevice>(((ModuleName)wafer.DestinationStation).ToString());
  794. string destcarrierID = destlp == null ? "" : destlp.CarrierId;
  795. var dvid = new SerializableDictionary<string, object>()
  796. {
  797. {DVIDName.LOT_ID, wafer.LotId},
  798. {DVIDName.WAFER_ID, wafer.WaferID},
  799. {DVIDName.SOURCE_CAR_ID, wafer.OriginCarrierID},
  800. {DVIDName.CarrierID,wafer.OriginCarrierID},
  801. {DVIDName.SOURCE_SLOT, (wafer.OriginSlot +1)},
  802. {DVIDName.ARRIVE_POS_NAME, Aligner.RobotModuleName.ToString()},
  803. {DVIDName.LASERMARK, Aligner.OCRs[ocrindex].CurrentLaserMark},
  804. {DVIDName.LM_READER_NO,ocrindex+1},
  805. {DVIDName.OCR_SCORE, waferIDindex == 0?
  806. Aligner.OCRs[ocrindex].LaserMark1Score: Aligner.OCRs[ocrindex].LaserMark2Score},
  807. {DVIDName.LM_NO, waferIDindex+1},
  808. {"DestCarrier",destcarrierID},
  809. {"DestSlot",wafer.DestinationSlot+1},
  810. { "SourcePort",wafer.OriginStation},
  811. { "DestPort",wafer.DestinationStation},
  812. };
  813. EV.Notify(EventWaferIdReadFail, dvid);
  814. EV.PostAlarmLog(Aligner.RobotModuleName.ToString(), $"Wafer:{wafer.WaferID} failed to read laser mark.");
  815. EV.Notify(AlarmID.ReadWaferLaserMarkFailed);
  816. }
  817. return true;
  818. });
  819. }
  820. public void RtPreAlignWafer(int id,string msg, double notch, Action<string> notify)
  821. {
  822. var ret = Execute(id, () =>
  823. {
  824. notify($"{msg} to {notch}.");
  825. var reason = string.Empty;
  826. Aligner.PreAlign(notch, out reason);
  827. return true;
  828. });
  829. }
  830. public void RtPostAlignWafer(int id, string msg, double notch, Action<string> notify)
  831. {
  832. var ret = Execute(id, () =>
  833. {
  834. notify($"{msg} to {notch}.");
  835. var reason = string.Empty;
  836. Aligner.PostAlign(notch, out reason);
  837. return true;
  838. });
  839. }
  840. public void RtUpdateWaferNextStationOnDispatchByID(int id, Action<string> notify, Action<string> error)
  841. {
  842. var ret= Execute(id, () =>
  843. {
  844. var wafer = WaferManager.Instance.GetWafer(AlignerModulename, 0);
  845. notify($"Update wafer:{wafer.WaferID} to next station on dispatch by ID.");
  846. int station, slotindex;
  847. if (Singleton<SorterJobManager>.Instance.IdentifyStationAndSlot(wafer.LaserMarker, out station, out slotindex))
  848. {
  849. wafer.DestinationStation = station;
  850. wafer.NextStation = station;
  851. wafer.DestinationSlot = slotindex;
  852. wafer.NextStationSlot = slotindex;
  853. EV.PostInfoLog("System", $"Wafer:{wafer.WaferID} with laser mark:{wafer.LaserMarker} from carrier:{wafer.OriginCarrierID} " +
  854. $"is identify to dispatch to station:{(ModuleName)station} slot:{slotindex + 1}.");
  855. }
  856. else
  857. {
  858. wafer.NextStation = wafer.DestinationStation;
  859. wafer.NextStationSlot = wafer.DestinationSlot;
  860. EV.PostInfoLog("System", $"Wafer:{wafer.WaferID} with laser mark:{wafer.LaserMarker} from carrier:{wafer.OriginCarrierID} " +
  861. $"can't be identify will be return.");
  862. }
  863. return true;
  864. });
  865. }
  866. private void RtReadWaferID(int id, ModuleName name, int ocrindex, int waferIDindex, string job, Action<string> notify)
  867. {
  868. var ret = Execute(id, () =>
  869. {
  870. notify($"Start read laser mark with reader:{ocrindex} for the NO.{waferIDindex + 1} ID.");
  871. var reason = string.Empty;
  872. if (!Aligner.OCRs[ocrindex].ReadWaferID(job, waferIDindex))
  873. {
  874. var wafer = WaferManager.Instance.GetWafers(name)[0];
  875. var destlp = DEVICE.GetDevice<LoadPortBaseDevice>(((ModuleName)wafer.DestinationStation).ToString());
  876. string destcarrierID = destlp == null ? "" : destlp.CarrierId;
  877. var dvid = new SerializableDictionary<string, object>()
  878. {
  879. {DVIDName.LOT_ID, wafer.LotId},
  880. {DVIDName.WAFER_ID, wafer.WaferID},
  881. {DVIDName.CarrierID,wafer.OriginCarrierID},
  882. {DVIDName.SOURCE_CAR_ID, wafer.OriginCarrierID},
  883. {DVIDName.SOURCE_SLOT, (wafer.OriginSlot +1)},
  884. {DVIDName.ARRIVE_POS_NAME, Aligner.RobotModuleName.ToString()},
  885. {DVIDName.LASERMARK, Aligner.OCRs[ocrindex].CurrentLaserMark},
  886. {DVIDName.LM_READER_NO,ocrindex+1},
  887. {DVIDName.OCR_SCORE, waferIDindex == 0?
  888. Aligner.OCRs[ocrindex].LaserMark1Score: Aligner.OCRs[ocrindex].LaserMark2Score},
  889. {DVIDName.LM_NO, waferIDindex+1},
  890. {"DestCarrier",destcarrierID},
  891. {"DestSlot",wafer.DestinationSlot+1},
  892. { "SourcePort",wafer.OriginStation},
  893. { "DestPort",wafer.DestinationStation},
  894. };
  895. EV.Notify(EventWaferIdReadFail, dvid);
  896. EV.PostAlarmLog(Aligner.RobotModuleName.ToString(), $"Wafer:{wafer.WaferID} failed to read laser mark.");
  897. EV.Notify(AlarmID.ReadWaferLaserMarkFailed);
  898. }
  899. return true;
  900. });
  901. }
  902. public void RtSendReadResult(int id, ModuleName name, int ocrindex, int waferIDindex, string job, Action<string> notify)
  903. {
  904. var ret = Execute(id, () =>
  905. {
  906. notify($"{name} start to send read result.");
  907. var wafer = WaferManager.Instance.GetWafers(name)[0];
  908. if (waferIDindex == 0)
  909. {
  910. WaferManager.Instance.UpdateWaferLaserWithScoreAndFileName(name, 0, Aligner.OCRs[ocrindex].LaserMark1,
  911. Aligner.OCRs[ocrindex].LaserMark1Score, job, "");
  912. WaferManager.Instance.UpdateWaferHistory(AlignerModulename, 0, SubstAccessType.UpdateLM1);
  913. }
  914. if (waferIDindex == 1)
  915. {
  916. WaferManager.Instance.UpdateWaferT7CodeWithScoreAndFileName(name, 0, Aligner.OCRs[ocrindex].LaserMark2,
  917. Aligner.OCRs[ocrindex].LaserMark2Score, job, "");
  918. WaferManager.Instance.UpdateWaferHistory(AlignerModulename, 0, SubstAccessType.UpdateLM1);
  919. }
  920. var destlp = DEVICE.GetDevice<LoadPortBaseDevice>(((ModuleName)wafer.DestinationStation).ToString());
  921. string destcarrierID = destlp == null ? "" : destlp.CarrierId;
  922. var dvid2 = new SerializableDictionary<string, object>()
  923. {
  924. {DVIDName.LOT_ID, wafer.LotId},
  925. {DVIDName.WAFER_ID, wafer.WaferID},
  926. {DVIDName.CarrierID,wafer.OriginCarrierID},
  927. {DVIDName.SOURCE_CAR_ID, wafer.OriginCarrierID},
  928. {DVIDName.SOURCE_SLOT, (wafer.OriginSlot +1)},
  929. {DVIDName.ARRIVE_POS_NAME, Aligner.RobotModuleName.ToString()},
  930. {DVIDName.LASERMARK, Aligner.OCRs[ocrindex].CurrentLaserMark},
  931. {DVIDName.LM_READER_NO,ocrindex+1},
  932. {DVIDName.OCR_SCORE, waferIDindex == 0?
  933. Aligner.OCRs[ocrindex].LaserMark1Score: Aligner.OCRs[ocrindex].LaserMark2Score},
  934. {DVIDName.LM_NO, waferIDindex+1},
  935. {"DestCarrier",destcarrierID},
  936. {"DestSlot",wafer.DestinationSlot+1},
  937. { "SourcePort",wafer.OriginStation},
  938. { "DestPort",wafer.DestinationStation},
  939. };
  940. EV.PostInfoLog(Aligner.RobotModuleName.ToString(), $"Wafer:{wafer.WaferID} succeed to read laser mark:" +
  941. $"{Aligner.OCRs[ocrindex].CurrentLaserMark ?? ""} with score:{Aligner.OCRs[ocrindex].CurrentLaserMarkScore.ToString() ?? ""} in time:" +
  942. $"{Aligner.OCRs[ocrindex].CurrentLaserMarkReadTime ?? ""}.");
  943. EV.Notify(EventWaferIdRead, dvid2);
  944. if (!Aligner.OCRs[ocrindex].ReadOK || Aligner.OCRs[ocrindex].CurrentLaserMark.Contains("*"))
  945. {
  946. var dvid3 = new SerializableDictionary<string, object>()
  947. {
  948. { "AlarmDescription",
  949. $"Read lasermark on wafer:{wafer.WaferID} failed:{Aligner.OCRs[ocrindex].CurrentLaserMark}"
  950. }
  951. };
  952. EV.Notify(AlarmID.ReadWaferLaserMarkFailed, dvid3);
  953. EV.Notify(EventWaferIdReadFail, dvid2);
  954. }
  955. return true;
  956. });
  957. }
  958. private void RtSetRetryLaserMarkFlag(int id, int lasermarkIndex, int ocrindex,Action<string> notify)
  959. {
  960. var ret = Execute(id, () =>
  961. {
  962. notify($"Start set laser mark reader{ocrindex} retry flag to {Aligner.OCRs[ocrindex].ReadOK}");
  963. if(lasermarkIndex ==0)
  964. IsNeedRetryLaserMark1 = !Aligner.OCRs[ocrindex].ReadOK;
  965. else
  966. IsNeedRetryLaserMark2 = !Aligner.OCRs[ocrindex].ReadOK;
  967. return true;
  968. });
  969. }
  970. private void RtWaitReaderReady(int id, int time, int ocrindex, Action<string> notify, Action<string> error)
  971. {
  972. var ret = ExecuteAndWait(id, () =>
  973. {
  974. notify($"Wait reader index:{ocrindex} to be ready.");
  975. var reason = string.Empty;
  976. return true;
  977. }, () =>
  978. {
  979. if (Aligner.OCRs[ocrindex].IsReady())
  980. {
  981. return Result.DONE;
  982. }
  983. if(Aligner.OCRs[ocrindex].DeviceState == OCRReaderStateEnum.Error)
  984. {
  985. return Result.FAIL;
  986. }
  987. return Result.RUN;
  988. }, time * 1000);
  989. if (ret.Item1)
  990. {
  991. if (ret.Item2 == Result.FAIL)
  992. {
  993. }
  994. else if (ret.Item2 == Result.TIMEOUT) //timeout
  995. {
  996. EV.PostAlarmLog(Aligner.RobotModuleName.ToString(), $"Wait reader index:{ocrindex} to be ready timeout.");
  997. var wafer = WaferManager.Instance.GetWafer(Aligner.RobotModuleName,0);
  998. var destlp = DEVICE.GetDevice<LoadPortBaseDevice>(((ModuleName)wafer.DestinationStation).ToString());
  999. string destcarrierID = destlp == null ? "" : destlp.CarrierId;
  1000. var dvid = new SerializableDictionary<string, object>()
  1001. {
  1002. {DVIDName.LOT_ID, wafer.LotId},
  1003. {DVIDName.WAFER_ID, wafer.WaferID},
  1004. {DVIDName.CarrierID,wafer.OriginCarrierID},
  1005. {DVIDName.SOURCE_CAR_ID, wafer.OriginCarrierID},
  1006. {DVIDName.SOURCE_SLOT, (wafer.OriginSlot +1)},
  1007. {DVIDName.ARRIVE_POS_NAME, Aligner.RobotModuleName.ToString()},
  1008. {DVIDName.LASERMARK, Aligner.OCRs[ocrindex].CurrentLaserMark},
  1009. {DVIDName.LM_READER_NO,ocrindex+1},
  1010. {DVIDName.OCR_SCORE, ocrindex == 0?
  1011. Aligner.OCRs[ocrindex].LaserMark1Score: Aligner.OCRs[ocrindex].LaserMark2Score},
  1012. {DVIDName.LM_NO, ocrindex+1},
  1013. {"DestCarrier",destcarrierID},
  1014. {"DestSlot",wafer.DestinationSlot+1},
  1015. { "SourcePort",wafer.OriginStation},
  1016. { "DestPort",wafer.DestinationStation},
  1017. };
  1018. EV.Notify(EventWaferIdReadFail, dvid);
  1019. EV.Notify(AlarmID.ReadWaferLaserMarkFailed);
  1020. }
  1021. else
  1022. {
  1023. }
  1024. }
  1025. }
  1026. public void RtSaveOcrPicture(int id, int ocrindex, Action<string> notify)
  1027. {
  1028. var ret = Execute(id, () =>
  1029. {
  1030. notify($"Start to save image for the ocr reader index:{ocrindex}.");
  1031. return Aligner.OCRs[ocrindex].SavePicture();
  1032. });
  1033. }
  1034. private void RtVerifyWaferIDWithHostDefine(int id, ModuleName name, int ocrindex, int waferIDindex, Action<string> notify, Action<string> error)
  1035. {
  1036. var ret = Execute(id, () =>
  1037. {
  1038. var aligner = DEVICE.GetDevice<AlignerBaseDevice>(name.ToString());
  1039. var wafer = WaferManager.Instance.GetWafer(name, 0);
  1040. string lasermark = aligner.OCRs[ocrindex].CurrentLaserMark;
  1041. string hostdefineMark = wafer.HostLaserMark1;
  1042. if (waferIDindex == 1)
  1043. hostdefineMark = wafer.HostLaserMark2;
  1044. notify($"Start verifying waferID:{wafer.WaferID},lasermark:{lasermark} with host define:{hostdefineMark}.");
  1045. var reason = string.Empty;
  1046. WaferManager.Instance.UpdateWaferLMVerifyResult(Aligner.RobotModuleName, 0, true);
  1047. if ((waferIDindex == 0 && lasermark != wafer.HostLaserMark1) || (waferIDindex == 1 && lasermark != wafer.HostLaserMark2))
  1048. {
  1049. WaferManager.Instance.UpdateWaferLMVerifyResult(Aligner.RobotModuleName, 0, false);
  1050. EV.Notify(Aligner.AlarmVerifyLaserMarkFailed);
  1051. notify($"Verify waferID:{wafer.WaferID},lasermark:{lasermark} failed with host define:{hostdefineMark}," +
  1052. $"action is:{Singleton<SorterJobManager>.Instance.MisMatchHandler}");
  1053. if (Singleton<SorterJobManager>.Instance.MisMatchHandler == VerifyFailHandlerEnum.Stop) //Stop
  1054. return false;
  1055. if (Singleton<SorterJobManager>.Instance.MisMatchHandler == VerifyFailHandlerEnum.Continue) //Continue
  1056. return true;// throw new RoutineBreakException(); ;
  1057. if (Singleton<SorterJobManager>.Instance.MisMatchHandler == VerifyFailHandlerEnum.ReturnCurrentWafer ||
  1058. Singleton<SorterJobManager>.Instance.MisMatchHandler == VerifyFailHandlerEnum.ReturnAllWafer ||
  1059. Singleton<SorterJobManager>.Instance.MisMatchHandler == VerifyFailHandlerEnum.ReturnAllWaferExcpetComplete)
  1060. {
  1061. if (Singleton<RouteManagerSorter>.Instance.CurrentSorterRTStateEnum == SorterRTStateEnum.DispatchingToPort)
  1062. Singleton<SorterJobManager>.Instance.ReleaseLastSlotOnDispatch((ModuleName)wafer.DestinationStation);
  1063. else
  1064. Singleton<SorterJobManager>.Instance.ReleaseToBePresentModuleSlot((ModuleName)wafer.DestinationStation, wafer.DestinationSlot);
  1065. wafer.DestinationStation = wafer.OriginStation;
  1066. wafer.DestinationSlot = wafer.OriginSlot;
  1067. wafer.NextStation = wafer.OriginStation;
  1068. wafer.NextStationSlot = wafer.OriginSlot;
  1069. }
  1070. if (Singleton<SorterJobManager>.Instance.MisMatchHandler == VerifyFailHandlerEnum.Transfer)
  1071. {
  1072. if (Singleton<SorterJobManager>.Instance.MisMatchCollectPort == ModuleName.System)
  1073. {
  1074. EV.PostAlarmLog("System", $"The mismatch collection port setting is wrong.");
  1075. return false;
  1076. }
  1077. if (Singleton<RouteManagerSorter>.Instance.CurrentSorterRTStateEnum == SorterRTStateEnum.DispatchingToPort)
  1078. {
  1079. Singleton<SorterJobManager>.Instance.ReleaseLastSlotOnDispatch((ModuleName)wafer.DestinationStation);
  1080. wafer.DestinationStation = (int)Singleton<SorterJobManager>.Instance.MisMatchCollectPort;
  1081. wafer.DestinationSlot = -1;
  1082. wafer.NextStation = (int)Singleton<SorterJobManager>.Instance.MisMatchCollectPort;
  1083. wafer.NextStationSlot = -1;
  1084. }
  1085. else
  1086. {
  1087. Singleton<SorterJobManager>.Instance.ReleaseToBePresentModuleSlot((ModuleName)wafer.DestinationStation, wafer.DestinationSlot);
  1088. wafer.DestinationStation = (int)Singleton<SorterJobManager>.Instance.MisMatchCollectPort;
  1089. int collectSlot;
  1090. if (!Singleton<SorterJobManager>.Instance.BidCollectionSlot(out collectSlot)) return false;
  1091. wafer.DestinationSlot = collectSlot;
  1092. wafer.NextStation = (int)Singleton<SorterJobManager>.Instance.MisMatchCollectPort;
  1093. wafer.NextStationSlot = collectSlot;
  1094. }
  1095. }
  1096. Singleton<SorterJobManager>.Instance.AutoAbortCurrentPJ();
  1097. Thread.Sleep(2000);
  1098. }
  1099. return true;
  1100. });
  1101. }
  1102. private void RtVerifyWaferIDAndWaitManualInput(int id, ModuleName name, int time, int ocrindex, int waferIDindex, Action<string> notify, Action<string> error)
  1103. {
  1104. var ret = ExecuteAndWait(id, () =>
  1105. {
  1106. notify("Start verifying waferID");
  1107. var reason = string.Empty;
  1108. _trigAlarmVerifyLMLengthFail.RST = true;
  1109. _trigAlarmReadInvalidSlotFail.RST = true;
  1110. _trigAlarmVerifyLMLengthFail.RST = true;
  1111. _trigAlarmVerifyWithHostDefineFail.RST = true;
  1112. _trigAlarmVerifyChecksumFail.RST = true;
  1113. if (!VerifyWaferIDWithAlarm(name, ocrindex, waferIDindex))
  1114. {
  1115. EV.Notify(Aligner.AlarmVerifyLaserMarkFailed);
  1116. Singleton<RouteManagerSorter>.Instance.IsVerifyLaserMarkAlarm = true;
  1117. if (_trigAlarmDestinationOccuppiedFail.Q)
  1118. EV.Notify(Aligner.AlarmSlotInLaserMarkIsOccuppied);
  1119. if (_trigAlarmReadInvalidSlotFail.Q)
  1120. EV.Notify(Aligner.AlarmVerifyLaserMarkSlotNoFailed);
  1121. if (_trigAlarmVerifyLMLengthFail.Q)
  1122. EV.Notify(Aligner.AlarmVerifyLaserMarkLengthFailed);
  1123. if (_trigAlarmVerifyChecksumFail.Q)
  1124. EV.Notify(Aligner.AlarmVerifyLaserMarkChecksumFailed);
  1125. }
  1126. return true;
  1127. }, () =>
  1128. {
  1129. if (!VerifyWaferIDWithAlarm(name, ocrindex, waferIDindex))
  1130. {
  1131. Singleton<RouteManagerSorter>.Instance.IsVerifyLaserMarkAlarm = true;
  1132. if (_trigAlarmDestinationOccuppiedFail.Q)
  1133. EV.Notify(Aligner.AlarmSlotInLaserMarkIsOccuppied);
  1134. if (_trigAlarmReadInvalidSlotFail.Q)
  1135. EV.Notify(Aligner.AlarmVerifyLaserMarkSlotNoFailed);
  1136. if (_trigAlarmVerifyLMLengthFail.Q)
  1137. EV.Notify(Aligner.AlarmVerifyLaserMarkLengthFailed);
  1138. if (_trigAlarmVerifyChecksumFail.Q)
  1139. EV.Notify(Aligner.AlarmVerifyLaserMarkChecksumFailed);
  1140. WaferManager.Instance.UpdateWaferLMVerifyResult(Aligner.RobotModuleName, 0, false);
  1141. return Result.RUN;
  1142. }
  1143. WaferManager.Instance.UpdateWaferLMVerifyResult(Aligner.RobotModuleName, 0, true);
  1144. Singleton<RouteManagerSorter>.Instance.IsVerifyLaserMarkAlarm = false;
  1145. _trigAlarmVerifyLMLengthFail.RST = true;
  1146. _trigAlarmReadInvalidSlotFail.RST = true;
  1147. _trigAlarmVerifyLMLengthFail.RST = true;
  1148. _trigAlarmVerifyWithHostDefineFail.RST = true;
  1149. _trigAlarmVerifyChecksumFail.RST = true;
  1150. return Result.DONE;
  1151. }, time * 1000);
  1152. if (ret.Item1)
  1153. {
  1154. if (ret.Item2 == Result.FAIL)
  1155. {
  1156. }
  1157. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1158. {
  1159. EV.Notify(Aligner.AlarmVerifyLaserMarkTimeout);
  1160. error($"verify WaferID timeout after {time} seconds");
  1161. }
  1162. else
  1163. {
  1164. }
  1165. }
  1166. }
  1167. private string _previousLasermark;
  1168. private bool VerifyWaferIDWithAlarm(ModuleName alignername,int ocrindex, int waferIDindex)
  1169. {
  1170. var aligner = DEVICE.GetDevice<AlignerBaseDevice>(alignername.ToString());
  1171. var wafer = WaferManager.Instance.GetWafer(alignername, 0);
  1172. string lasermark = aligner.OCRs[ocrindex].CurrentLaserMark;
  1173. if(_previousLasermark != lasermark)
  1174. {
  1175. _previousLasermark = lasermark;
  1176. _trigAlarmVerifyLMLengthFail.RST = true;
  1177. _trigAlarmReadInvalidSlotFail.RST = true;
  1178. _trigAlarmVerifyLMLengthFail.RST = true;
  1179. _trigAlarmVerifyWithHostDefineFail.RST = true;
  1180. _trigAlarmVerifyChecksumFail.RST = true;
  1181. }
  1182. int slot;
  1183. if ((_aligneRecipe.IsVerifyLaserMarkLength && lasermark.Length != AlignerRecipe.LaserMarkLength)||lasermark.Contains("*"))
  1184. {
  1185. _trigAlarmVerifyLMLengthFail.CLK = true;
  1186. return false;
  1187. }
  1188. if(_aligneRecipe.IsVerifyLaserMarkSlotForNCD)
  1189. {
  1190. if (lasermark.Length < _aligneRecipe.SlotStartPositionForNCD +1)
  1191. {
  1192. _trigAlarmVerifyLMLengthFail.CLK = true;
  1193. return false;
  1194. }
  1195. if(!int.TryParse(lasermark.Substring(_aligneRecipe.SlotStartPositionForNCD-1,2),out slot))
  1196. {
  1197. _trigAlarmReadInvalidSlotFail.CLK = true;
  1198. return false;
  1199. }
  1200. if(slot<1 || slot >25)
  1201. {
  1202. _trigAlarmReadInvalidSlotFail.CLK = true;
  1203. return false;
  1204. }
  1205. }
  1206. if (_aligneRecipe.IsVerifyChecksumLaserMarker1)
  1207. {
  1208. if(!VerifyCheckCharater(lasermark))
  1209. {
  1210. _trigAlarmVerifyChecksumFail.CLK = true;
  1211. return false;
  1212. }
  1213. }
  1214. //if (_aligneRecipe.IsVerifyWithHostDefine)
  1215. //{
  1216. // if (waferIDindex == 0 && lasermark != wafer.HostLaserMark1)
  1217. // {
  1218. // _trigAlarmVerifyWithHostDefineFail.CLK = true;
  1219. // return false;
  1220. // }
  1221. // if (waferIDindex == 1 && lasermark != wafer.HostLaserMark2)
  1222. // {
  1223. // _trigAlarmVerifyWithHostDefineFail.CLK = true;
  1224. // return false;
  1225. // }
  1226. //}
  1227. if (wafer.DestinationSlot == 99)
  1228. {
  1229. if (_aligneRecipe.SlotStartPositionForNCD < 1)
  1230. _aligneRecipe.SlotStartPositionForNCD = 1;
  1231. if (!int.TryParse(lasermark.Substring(_aligneRecipe.SlotStartPositionForNCD - 1, 2), out slot))
  1232. {
  1233. _trigAlarmReadInvalidSlotFail.CLK = true;
  1234. return false;
  1235. }
  1236. //if (slot < 1 || slot > 25)
  1237. //{
  1238. // _trigAlarmReadInvalidSlotFail.CLK = true;
  1239. // return false;
  1240. //}
  1241. if (WaferManager.Instance.CheckHasWafer((ModuleName)wafer.DestinationStation, slot - 1))
  1242. {
  1243. if (wafer.OriginStation != wafer.DestinationStation)
  1244. {
  1245. _trigAlarmDestinationOccuppiedFail.CLK = true;
  1246. return false;
  1247. }
  1248. }
  1249. var lp = DEVICE.GetDevice<LoadPortBaseDevice>($"{(ModuleName)wafer.DestinationStation}");
  1250. if ((slot - 1) < lp.ValidStartSlotIndex || (slot - 1) > lp.ValidEndSlotIndex)
  1251. {
  1252. _trigAlarmReadInvalidSlotFail.CLK = true;
  1253. return false;
  1254. }
  1255. wafer.DestinationSlot = slot - 1;
  1256. }
  1257. if (wafer.DestinationSlot == 100)
  1258. {
  1259. if (_aligneRecipe.SlotStartPositionForNCD < 1)
  1260. _aligneRecipe.SlotStartPositionForNCD = 1;
  1261. if (!int.TryParse(lasermark.Substring(_aligneRecipe.SlotStartPositionForNCD - 1, 2), out slot))
  1262. {
  1263. _trigAlarmReadInvalidSlotFail.CLK = true;
  1264. return false;
  1265. }
  1266. var lp = DEVICE.GetDevice<LoadPortBaseDevice>($"{(ModuleName)wafer.DestinationStation}");
  1267. int destslot = lp.ValidEndSlotIndex - slot + 1;
  1268. if (destslot < lp.ValidStartSlotIndex || destslot > lp.ValidEndSlotIndex)
  1269. {
  1270. _trigAlarmReadInvalidSlotFail.CLK = true;
  1271. return false;
  1272. }
  1273. if (WaferManager.Instance.CheckHasWafer((ModuleName)wafer.DestinationStation, destslot))
  1274. {
  1275. if (wafer.OriginStation != wafer.DestinationStation)
  1276. {
  1277. _trigAlarmDestinationOccuppiedFail.CLK = true;
  1278. return false;
  1279. }
  1280. }
  1281. wafer.DestinationSlot = destslot;
  1282. }
  1283. return true;
  1284. }
  1285. private R_TRIG _trigAlarmVerifyLMLengthFail = new R_TRIG();
  1286. private R_TRIG _trigAlarmReadInvalidSlotFail = new R_TRIG();
  1287. private R_TRIG _trigAlarmVerifyChecksumFail = new R_TRIG();
  1288. private R_TRIG _trigAlarmDestinationOccuppiedFail = new R_TRIG();
  1289. private R_TRIG _trigAlarmVerifyWithHostDefineFail = new R_TRIG();
  1290. private bool VerifyCheckCharater(string lasermark)
  1291. {
  1292. UInt64 checksum = 0;
  1293. for(int i=0;i<lasermark.Length;i++)
  1294. {
  1295. uint charNumValue = (uint)(Convert.ToInt32(lasermark[i])-32);
  1296. checksum = checksum * 8 + charNumValue;
  1297. }
  1298. if (Convert.ToInt32(lasermark[lasermark.Length - 2]) > Convert.ToInt32('H') ||
  1299. Convert.ToInt32(lasermark[lasermark.Length - 2]) < Convert.ToInt32('A'))
  1300. return false;
  1301. if (Convert.ToInt32(lasermark[lasermark.Length - 1]) > Convert.ToInt32('7') ||
  1302. Convert.ToInt32(lasermark[lasermark.Length - 1]) < Convert.ToInt32('0'))
  1303. return false;
  1304. return checksum % 59 == 0;
  1305. }
  1306. }
  1307. }