CommonRoutine.cs 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Aitex.Core.Common;
  5. using Aitex.Core.RT.Device;
  6. using Aitex.Core.RT.Device.Unit;
  7. using Aitex.Core.RT.Event;
  8. using Aitex.Core.RT.Routine;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Util;
  11. using EFEM.RT.Devices;
  12. using Aitex.Sorter.Common;
  13. using EFEMSC;
  14. using MECF.Framework.Common.Equipment;
  15. using MECF.Framework.Common.SubstrateTrackings;
  16. using MECF.Framework.Common.Utilities;
  17. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  18. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.OcrReaders;
  19. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  20. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot.NX100;
  21. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  22. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  23. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  24. using Aitex.Core.RT.Log;
  25. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations;
  26. namespace EFEM.RT.Routines
  27. {
  28. public class CommonRoutine : SeqenecRoutine
  29. {
  30. protected bool bUINotify;
  31. public string Module { get; set; }
  32. public string Name { get; set; }
  33. public string Display { get; set; }
  34. //protected LoadPort loadportA = null;
  35. //protected LoadPort loadportB = null;
  36. //protected RIDReader ridreaderA = null;
  37. //protected RIDReader ridreaderB = null;
  38. protected RobotBaseDevice robot = null;
  39. protected Aligner aligner = null;
  40. protected OcrReader widreader = null;
  41. protected IoCoolingBuffer buffer1 = null;
  42. protected IoCoolingBuffer buffer2 = null;
  43. protected IoCoolingBuffer aligner1 = null;
  44. protected IoCoolingBuffer aligner2 = null;
  45. protected LoadLockDevice ll1 = null;
  46. protected LoadLockDevice ll2 = null;
  47. protected IoCoolingBuffer _ioCoolBuffer;
  48. protected BufferStation bf1 = null;
  49. protected BufferStation bf2 = null;
  50. private List<LoadPortBaseDevice> LPs;
  51. protected readonly bool HaveAligner = DeviceDefineManager.Instance.GetValue<bool>("AlignerInstalled") ?? false;
  52. protected readonly bool AlignerNeedMoveUpCommand = DeviceDefineManager.Instance.GetValue<bool>("AlignerNeedMoveUpCommand") ?? false;
  53. protected readonly int LoadPortQuantity = DeviceDefineManager.Instance.GetValue<int>("LoadPortQuantity") ?? 0;
  54. protected readonly string RobotTypeDefine = DeviceDefineManager.Instance.GetValue("RobotType");
  55. protected readonly bool HaveMotionAxis = DeviceDefineManager.Instance.GetValue<bool>("MotionAxisInstalled") ?? false;
  56. protected static readonly bool LoadLockDoorControlByStation = DeviceDefineManager.Instance.GetValue<bool>("LLDoorControlByStation") ?? false;
  57. protected readonly string LoadPortTypeDefine = DeviceDefineManager.Instance.GetValue("LoadPortType");
  58. protected int OffsetX;
  59. protected int OffsetY;
  60. protected int OffsetZ;
  61. private DeviceTimer _timerQuery = new DeviceTimer();
  62. private int _queryPeriod = 500; //ms
  63. protected bool NeedSetParameter;
  64. protected bool IsStopped;
  65. private int _existInterval = SC.GetValue<int>("Robot.Robot.ExistInterval");
  66. protected bool NeedRobotGripAndUngrip=SC.GetValue<bool>("System.EnableRobotGripAndUngrip");
  67. public bool IsEnableIdentifyThickness
  68. {
  69. get
  70. {
  71. if (SC.ContainsItem("System.IsEnableIdentifyThickness"))
  72. return SC.GetValue<bool>("System.IsEnableIdentifyThickness");
  73. return false;
  74. }
  75. }
  76. public bool IsEnableMultiWaferSize
  77. {
  78. get
  79. {
  80. if (SC.ContainsItem("System.IsEnableMultiWaferSize"))
  81. return SC.GetValue<bool>("System.IsEnableMultiWaferSize");
  82. return false;
  83. }
  84. }
  85. public string EFemNum
  86. {
  87. get
  88. {
  89. if (SC.ContainsItem("System.EFEMNUM"))
  90. return SC.GetStringValue("System.EFEMNUM");
  91. return "001";
  92. }
  93. }
  94. public bool IsVacuumMode
  95. {
  96. get
  97. {
  98. if (SC.ContainsItem("Robot.Robot.IsVacuumMode"))
  99. return SC.GetValue<bool>("Robot.Robot.IsVacuumMode");
  100. return true;
  101. }
  102. }
  103. private DeviceTimer _timerPerf = new DeviceTimer();
  104. public CommonRoutine()
  105. {
  106. robot = DEVICE.GetDevice<RobotBaseDevice>(DeviceName.Robot);
  107. aligner = DEVICE.GetDevice<Aligner>(DeviceName.Aligner);
  108. widreader = DEVICE.GetDevice<OcrReader>(DeviceName.WIDReader);
  109. buffer1 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.CoolingBuffer1);
  110. buffer2 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.CoolingBuffer2);
  111. aligner1 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.Aligner1);
  112. aligner2 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.Aligner2);
  113. ll1 = DEVICE.GetDevice<LoadLockDevice>(DeviceName.LL1);
  114. ll2 = DEVICE.GetDevice<LoadLockDevice>(DeviceName.LL2);
  115. bf1 = DEVICE.GetDevice<BufferStation>(DeviceName.Buffer1);
  116. bf2 = DEVICE.GetDevice<BufferStation>(DeviceName.Buffer2);
  117. var lpNames = new List<ModuleName>(Singleton<DeviceManager>.Instance.LpNames);
  118. LPs = new List<LoadPortBaseDevice>();
  119. lpNames.ForEach(lp =>
  120. {
  121. if(!SC.GetValue<bool>($"LoadPort.{lp}.Disable"))
  122. LPs.Add(DEVICE.GetDevice<LoadPortBaseDevice>(lp.ToString()));
  123. });
  124. }
  125. public bool InitCommon()
  126. {
  127. return true;
  128. }
  129. protected void UpdateSCValue()
  130. {
  131. }
  132. //延时
  133. public void Delay(int id, string name, double time, Action<string> notify, Action<string> error)
  134. {
  135. Tuple<bool, Result> ret = Delay(id, () =>
  136. {
  137. notify(name);
  138. return true;
  139. }, time * 1000);
  140. if (ret.Item1)
  141. {
  142. if (ret.Item2 == Result.RUN)
  143. {
  144. throw (new RoutineBreakException());
  145. }
  146. }
  147. }
  148. #region waferID
  149. #endregion
  150. #region robot
  151. public void RobotReset(int id, RobotBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
  152. {
  153. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  154. {
  155. notify(String.Format("{0} clear error", device.Name));
  156. string reason = string.Empty;
  157. device.RobotReset();
  158. return true;
  159. }, () =>
  160. {
  161. if (!device.IsBusy&& device.RobotState != RobotStateEnum.Error && device.RobotState == RobotStateEnum.Idle)
  162. {
  163. return true;
  164. }
  165. return false;
  166. }, time * 1000);
  167. if (ret.Item1)
  168. {
  169. if (ret.Item2 == Result.FAIL)
  170. {
  171. throw (new RoutineFaildException());
  172. }
  173. else if (ret.Item2 == Result.TIMEOUT) //timeout
  174. {
  175. error(String.Format("{0} timeout, than {1} seconds", name, time));
  176. throw (new RoutineFaildException());
  177. }
  178. else
  179. throw (new RoutineBreakException());
  180. }
  181. }
  182. public void RobotServoOnOff(int id, Robot device, bool trueForOnFalseForOff, Action<string> notify, Action<string> error)
  183. {
  184. Tuple<bool, Result> ret = Execute(id, () =>
  185. {
  186. notify(String.Format("{0} Home", device.Name));
  187. string reason = string.Empty;
  188. return device.SetServoOnOff(trueForOnFalseForOff,out reason);
  189. });
  190. if (ret.Item1)
  191. {
  192. if (ret.Item2 == Result.FAIL)
  193. {
  194. throw (new RoutineFaildException());
  195. }
  196. }
  197. }
  198. public void RobotInit(int id, Robot device, string name, Action<string> notify, Action<string> error)
  199. {
  200. Tuple<bool, Result> ret = Execute(id, () =>
  201. {
  202. notify(String.Format("{0} Home", device.Name));
  203. string reason = string.Empty;
  204. return device.Init(out reason);
  205. });
  206. if (ret.Item1)
  207. {
  208. if (ret.Item2 == Result.FAIL)
  209. {
  210. throw (new RoutineFaildException());
  211. }
  212. }
  213. }
  214. public void RobotHome(int id, RobotBaseDevice device, string name, Action<string> notify, Action<string> error)
  215. {
  216. Tuple<bool, Result> ret = Execute(id, () =>
  217. {
  218. notify(String.Format("{0} Home", device.Name));
  219. string reason = string.Empty;
  220. return device.Home(null);
  221. });
  222. if (ret.Item1)
  223. {
  224. if (ret.Item2 == Result.FAIL)
  225. {
  226. throw (new RoutineFaildException());
  227. }
  228. }
  229. }
  230. public void RobotArmHome(int id, RobotBaseDevice device, string name, Action<string> notify, Action<string> error)
  231. {
  232. Tuple<bool, Result> ret = Execute(id, () =>
  233. {
  234. notify(String.Format("{0} Arm Home", device.Name));
  235. string reason = string.Empty;
  236. return device.Home(null);
  237. });
  238. if (ret.Item1)
  239. {
  240. if (ret.Item2 == Result.FAIL)
  241. {
  242. throw (new RoutineFaildException());
  243. }
  244. }
  245. }
  246. ///等待 Robot Motion
  247. public void WaitRobotMotion(int id, RobotBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
  248. {
  249. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  250. {
  251. notify("Wait robot finish motion");
  252. _timerQuery.Start(_queryPeriod); //开始查询
  253. return true;
  254. }, () =>
  255. {
  256. if (device.IsReady())
  257. {
  258. _timerQuery.Stop();
  259. return true;
  260. }
  261. if (query())
  262. {
  263. // string reason = string.Empty;
  264. // device.QueryState(out reason); //查询位置
  265. }
  266. return false;
  267. }, time * 1000);
  268. if (ret.Item1)
  269. {
  270. if (ret.Item2 == Result.FAIL)
  271. {
  272. throw (new RoutineFaildException());
  273. }
  274. else if (ret.Item2 == Result.TIMEOUT) //timeout
  275. {
  276. error(String.Format("{0} timeout, than {1} seconds", name, time));
  277. throw (new RoutineFaildException());
  278. }
  279. else
  280. throw (new RoutineBreakException());
  281. }
  282. }
  283. ///等待
  284. ///
  285. public void ReserveRobotToBusy(int id, RobotBaseDevice robot, string name,Action<string> notify, Action<string> error)
  286. {
  287. Tuple<bool, Result> ret = Execute(id, () =>
  288. {
  289. notify(String.Format("{0} set robot to busy", robot.Name));
  290. string reason = string.Empty;
  291. robot.IsBusy = true;
  292. return true;
  293. });
  294. if (ret.Item1)
  295. {
  296. if (ret.Item2 == Result.FAIL)
  297. {
  298. throw (new RoutineFaildException());
  299. }
  300. }
  301. }
  302. public void Wait(int id, string name, double time, Action<string> notify, Action<string> error)
  303. {
  304. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  305. {
  306. notify($"Wait {time} seconds");
  307. _timerQuery.Start(_queryPeriod); //开始查询
  308. return true;
  309. }, () =>
  310. {
  311. if (_timerQuery.GetElapseTime() >= time * 1000)
  312. {
  313. _timerQuery.Stop();
  314. return true;
  315. }
  316. return false;
  317. });
  318. if (ret.Item1)
  319. {
  320. if (ret.Item2 == Result.FAIL)
  321. {
  322. throw (new RoutineFaildException());
  323. }
  324. else
  325. throw (new RoutineBreakException());
  326. }
  327. }
  328. public void CoolBufferMoveUP(int id, IoCoolingBuffer device, WaferSize size, int time, Action<string> notify, Action<string> error)
  329. {
  330. Tuple<bool, Result> ret = Execute(id, () =>
  331. {
  332. notify($"Start {device.Name} Move Up");
  333. if (device.CheckPinUp()) return true;
  334. if (!device.Move(size, true, out string reason))
  335. {
  336. Stop(reason);
  337. return false;
  338. }
  339. return true;
  340. });
  341. if (ret.Item1)
  342. {
  343. if (ret.Item2 == Result.FAIL)
  344. {
  345. throw (new RoutineFaildException());
  346. }
  347. }
  348. }
  349. public void RobotBusytoSimif(int id, ModuleName moduleName,bool on,int time, Action<string> notify, Action<string> error)
  350. {
  351. Tuple<bool, Result> ret = Execute(id, () =>
  352. {
  353. notify($"set TrigRBbusytoSIMF of {moduleName} signal {on} ");
  354. if (on)
  355. {
  356. var value = moduleName == ModuleName.LP1 ? DeviceModel.TrigRBbusytoSIMF1.SetTrigger(true, out _) : DeviceModel.TrigRBbusytoSIMF2.SetTrigger(true, out _);
  357. if (!value)
  358. {
  359. Stop(null);
  360. return false;
  361. }
  362. }
  363. else
  364. {
  365. var value = moduleName == ModuleName.LP1 ? DeviceModel.TrigRBbusytoSIMF1.SetTrigger(false, out _) : DeviceModel.TrigRBbusytoSIMF2.SetTrigger(false, out _);
  366. if (!value)
  367. {
  368. Stop(null);
  369. return false;
  370. }
  371. }
  372. return true;
  373. });
  374. if (ret.Item1)
  375. {
  376. if (ret.Item2 == Result.FAIL)
  377. {
  378. throw (new RoutineFaildException());
  379. }
  380. }
  381. }
  382. public void UnGripRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
  383. {
  384. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  385. {
  386. Notify($"Release robot {blade}");
  387. //IoSensor sensorBlade = blade == Hand.Blade1
  388. // ? DeviceModel.SensorRobotFork1WaferOn
  389. // : DeviceModel.SensorRobotFork2WaferOn;
  390. //var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
  391. //int slot = blade == Hand.Blade1 ? 0 : 1;
  392. //if (WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot)) //!sensorBlade.Value &&
  393. {
  394. if (!device.Release((RobotArmEnum)blade))
  395. {
  396. Stop(null);
  397. return false;
  398. }
  399. }
  400. return true;
  401. }, () =>
  402. {
  403. if (!device.IsBusy)
  404. {
  405. return true;
  406. }
  407. //此处如果发生错误,忽略
  408. return false;
  409. }, time * 1000);
  410. if (ret.Item1)
  411. {
  412. if (ret.Item2 == Result.FAIL)
  413. {
  414. throw (new RoutineFaildException());
  415. }
  416. else if (ret.Item2 == Result.TIMEOUT) //timeout
  417. {
  418. Stop($"Release robot {blade} timeout, than {time} seconds");
  419. throw (new RoutineFaildException());
  420. }
  421. else
  422. throw (new RoutineBreakException());
  423. }
  424. }
  425. public void GripRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
  426. {
  427. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  428. {
  429. Notify($"Grip robot {blade}");
  430. //IoSensor sensorBlade = blade == Hand.Blade1
  431. // ? DeviceModel.SensorRobotFork1WaferOn
  432. // : DeviceModel.SensorRobotFork2WaferOn;
  433. //var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
  434. //int slot = blade == Hand.Blade1 ? 0 : 1;
  435. //if (!iswaferpersence && WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot)) //!sensorBlade.Value &&
  436. //{
  437. if (!device.Grip((RobotArmEnum)blade))
  438. {
  439. Stop(null);
  440. return false;
  441. }
  442. // }
  443. return true;
  444. }, () =>
  445. {
  446. if (device.IsReady())
  447. {
  448. return true;
  449. }
  450. //此处如果发生错误,忽略
  451. return false;
  452. }, time * 1000);
  453. if (ret.Item1)
  454. {
  455. if (ret.Item2 == Result.FAIL)
  456. {
  457. throw (new RoutineFaildException());
  458. }
  459. else if (ret.Item2 == Result.TIMEOUT) //timeout
  460. {
  461. Stop($"Release robot {blade} timeout, than {time} seconds");
  462. throw (new RoutineFaildException());
  463. }
  464. else
  465. throw (new RoutineBreakException());
  466. }
  467. }
  468. public void HomeReleaseRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
  469. {
  470. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  471. {
  472. Notify($"Release robot {blade}");
  473. //IoSensor sensorBlade = blade == Hand.Blade1
  474. // ? DeviceModel.SensorRobotFork1WaferOn
  475. // : DeviceModel.SensorRobotFork2WaferOn;
  476. //var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
  477. //int slot = blade == Hand.Blade1 ? 0 : 1;
  478. //if (!iswaferpersence&&WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot)) //!sensorBlade.Value &&
  479. //{
  480. if (!device.Release((RobotArmEnum)blade))
  481. {
  482. Stop(null);
  483. return false;
  484. }
  485. // }
  486. return true;
  487. }, () =>
  488. {
  489. if (device.IsReady())
  490. {
  491. return true;
  492. }
  493. //此处如果发生错误,忽略
  494. return false;
  495. }, time * 1000);
  496. if (ret.Item1)
  497. {
  498. if (ret.Item2 == Result.FAIL)
  499. {
  500. throw (new RoutineFaildException());
  501. }
  502. else if (ret.Item2 == Result.TIMEOUT) //timeout
  503. {
  504. Stop($"Release robot {blade} timeout, than {time} seconds");
  505. throw (new RoutineFaildException());
  506. }
  507. else
  508. throw (new RoutineBreakException());
  509. }
  510. }
  511. public void HomeGripAndUngripRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
  512. {
  513. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  514. {
  515. Notify($"Grip or Ungrip robot {blade}");
  516. int slot = blade == Hand.Blade1 ? 0 : 1;
  517. if (WaferManager.Instance.CheckHasWafer(ModuleName.Robot, slot))
  518. {
  519. if (!device.Grip((RobotArmEnum)blade))
  520. {
  521. Stop(null);
  522. return false;
  523. }
  524. }
  525. else
  526. {
  527. if (!device.Release((RobotArmEnum)blade))
  528. {
  529. Stop(null);
  530. return false;
  531. }
  532. }
  533. //Thread.Sleep(1000);
  534. return true;
  535. }, () =>
  536. {
  537. if (device.IsReady())
  538. {
  539. return true;
  540. }
  541. //此处如果发生错误,忽略
  542. return false;
  543. }, time * 1000);
  544. if (ret.Item1)
  545. {
  546. if (ret.Item2 == Result.FAIL)
  547. {
  548. throw (new RoutineFaildException());
  549. }
  550. else if (ret.Item2 == Result.TIMEOUT) //timeout
  551. {
  552. Stop($"Grip robot {blade} timeout, than {time} seconds");
  553. throw (new RoutineFaildException());
  554. }
  555. else
  556. throw (new RoutineBreakException());
  557. }
  558. }
  559. public void CheckBladeWaferIsExist(int id, RobotBaseDevice device,Hand blade, int time)
  560. {
  561. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  562. {
  563. Notify($"Check Blade {blade} Wafer Is Exist");
  564. try
  565. {
  566. if (!device.IsReady())
  567. {
  568. LOG.Write($"CheckBladeWaferIsExist:Robot IsReady={device.IsReady()}");
  569. throw (new RoutineBreakException());
  570. }
  571. if (!device.ReadParameter(new object[] { "CheckWaferIsPresence", blade == Hand.Blade1 ? 0 : 1, _existInterval }))
  572. {
  573. Stop(null);
  574. return false;
  575. }
  576. }
  577. catch (Exception ex)
  578. {
  579. LOG.Write(ex);
  580. }
  581. LOG.Write($"Check Blade Wafer Is Exist");
  582. //Thread.Sleep(1000);
  583. return true;
  584. }, () =>
  585. {
  586. // LOG.Write("CheckBladeWaferIsExist1: IsReady=false");
  587. try
  588. {
  589. if (device.IsReady())
  590. {
  591. LOG.Write("CheckBladeWaferIsExist: IsReady=true");
  592. return true;
  593. }
  594. }
  595. catch (Exception ex)
  596. {
  597. LOG.Write(ex);
  598. }
  599. //LOG.Write("CheckBladeWaferIsExist2: IsReady=false");
  600. //此处如果发生错误,忽略
  601. return false;
  602. }, time * 1000);
  603. if (ret.Item1)
  604. {
  605. if (ret.Item2 == Result.FAIL)
  606. {
  607. throw (new RoutineFaildException());
  608. }
  609. else if (ret.Item2 == Result.TIMEOUT) //timeout
  610. {
  611. Stop($"Check robot WaferPresence timeout, than {time} seconds");
  612. throw (new RoutineFaildException());
  613. }
  614. else
  615. throw (new RoutineBreakException());
  616. }
  617. }
  618. public void RobotSignalStatus(int id, RobotBaseDevice device , int time)
  619. {
  620. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  621. {
  622. Notify($"Query robot Signal Status");
  623. if (!device.ReadParameter(new object[] { "SignalStatus"}))
  624. {
  625. Stop(null);
  626. return false;
  627. }
  628. //Thread.Sleep(1000);
  629. return true;
  630. }, () =>
  631. {
  632. if (device.IsReady())
  633. {
  634. return true;
  635. }
  636. //此处如果发生错误,忽略
  637. return false;
  638. }, time * 1000);
  639. if (ret.Item1)
  640. {
  641. if (ret.Item2 == Result.FAIL)
  642. {
  643. throw (new RoutineFaildException());
  644. }
  645. else if (ret.Item2 == Result.TIMEOUT) //timeout
  646. {
  647. throw (new RoutineFaildException());
  648. }
  649. else
  650. throw (new RoutineBreakException());
  651. }
  652. }
  653. public void ConfirmRobotBladeWafer(int id, Hand blade)
  654. {
  655. Execute(id, () =>
  656. {
  657. Notify($"Confirm robot {blade} wafer");
  658. //IoSensor sensorBlade = blade == Hand.Blade1
  659. // ? DeviceModel.SensorRobotFork1WaferOn
  660. // : DeviceModel.SensorRobotFork2WaferOn;
  661. var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
  662. int slot = blade == Hand.Blade1 ? 0 : 1;
  663. if (iswaferpersence)
  664. {
  665. if (WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot))
  666. {
  667. EV.PostWarningLog(Module, $"Found wafer at robot {blade}");
  668. WaferManager.Instance.CreateWafer(ModuleName.Robot, slot, WaferStatus.Normal);
  669. }
  670. }
  671. else
  672. {
  673. if (WaferManager.Instance.CheckHasWafer(ModuleName.Robot, slot))
  674. {
  675. EV.PostWarningLog(Module, $"Not found wafer at robot {blade}, please manually confirm again.");
  676. WaferManager.Instance.DeleteWafer(ModuleName.Robot, slot);
  677. }
  678. }
  679. return true;
  680. });
  681. }
  682. public void CoolBufferMoveDown(int id, IoCoolingBuffer device, WaferSize size, int time, Action<string> notify, Action<string> error)
  683. {
  684. Tuple<bool, Result> ret = Execute(id, () =>
  685. {
  686. notify($"Start {device.Name} Move Down");
  687. if (device.CheckPinDown()) return true;
  688. if (!device.Move(size, false, out string reason))
  689. {
  690. Stop(reason);
  691. return false;
  692. }
  693. return true;
  694. });
  695. if (ret.Item1)
  696. {
  697. if (ret.Item2 == Result.FAIL)
  698. {
  699. throw (new RoutineFaildException());
  700. }
  701. }
  702. }
  703. public void WaitCoolBufferMoveUp(int id, IoCoolingBuffer device, string name, int time, Action<string> notify,
  704. Action<string> error)
  705. {
  706. var ret = ExecuteAndWait(id, () =>
  707. {
  708. notify(name);
  709. return true;
  710. }, () =>
  711. {
  712. if (device.Error)
  713. {
  714. Stop("Can not move up, device error");
  715. return null;
  716. }
  717. return device.CheckMovedUp() && !device.Busy ;
  718. }, time * 1000);
  719. if (ret.Item1)
  720. {
  721. if (ret.Item2 == Result.FAIL)
  722. throw new RoutineFaildException();
  723. if (ret.Item2 == Result.TIMEOUT) //timeout
  724. {
  725. error($"{name} timeout, than {time} seconds");
  726. throw new RoutineFaildException();
  727. }
  728. bool isMovedUp = device.CheckMovedUp() && !device.Busy && !device.Error;
  729. if (!isMovedUp)
  730. {
  731. throw new RoutineBreakException();
  732. }
  733. }
  734. }
  735. public void WaitCoolBufferMoveDown(int id, IoCoolingBuffer device, string name, int time, Action<string> notify,
  736. Action<string> error)
  737. {
  738. var ret = ExecuteAndWait(id, () =>
  739. {
  740. notify(name);
  741. _timerQuery.Start(_queryPeriod); //开始查询
  742. return true;
  743. }, () =>
  744. {
  745. if (device.Error)
  746. {
  747. Stop("Can not move down, device error");
  748. return null;
  749. }
  750. return device.CheckMovedDown() && !device.Busy;
  751. }, time * 1000);
  752. if (ret.Item1)
  753. {
  754. if (ret.Item2 == Result.FAIL) throw new RoutineFaildException();
  755. if (ret.Item2 == Result.TIMEOUT) //timeout
  756. {
  757. error($"{name} timeout, than {time} seconds");
  758. throw new RoutineFaildException();
  759. }
  760. bool isMovedDown = device.CheckMovedDown() && !device.Busy && !device.Error;
  761. if (!isMovedDown)
  762. {
  763. throw new RoutineBreakException();
  764. }
  765. }
  766. }
  767. public void SetWaferSize(int id, string name, int cmd, ModuleName station, int slot, int time, Action<string> notify, Action<string> error)
  768. {
  769. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  770. {
  771. WaferSize size = WaferSize.WS0;
  772. if (ModuleHelper.IsLoadPort(station))
  773. {
  774. }
  775. else
  776. {
  777. size = WaferManager.Instance.GetWaferSize(station, slot);
  778. }
  779. notify(String.Format($"Set WaferSize parameter {cmd} {size.ToString()}"));
  780. string reason = string.Empty;
  781. //robot.SetWaferSize(cmd, size, out reason);
  782. return true;
  783. }, () =>
  784. {
  785. if (robot.RobotState == RobotStateEnum.Idle)
  786. {
  787. return true;
  788. }
  789. return false;
  790. }, time * 1000);
  791. if (ret.Item1)
  792. {
  793. if (ret.Item2 == Result.FAIL)
  794. {
  795. throw (new RoutineFaildException());
  796. }
  797. else if (ret.Item2 == Result.TIMEOUT) //timeout
  798. {
  799. error(String.Format("Set WaferSize timeout, than {0} seconds", time));
  800. throw (new RoutineFaildException());
  801. }
  802. else
  803. throw (new RoutineBreakException());
  804. }
  805. }
  806. /// <summary>
  807. /// 目前只比对0114 parameter
  808. /// </summary>
  809. /// <param name="id"></param>
  810. /// <param name="name"></param>
  811. /// <param name="parameterNo"></param>
  812. /// <param name="parameterType"></param>
  813. /// <param name="waferSize"></param>
  814. /// <param name="time"></param>
  815. /// <param name="notify"></param>
  816. /// <param name="error"></param>
  817. /// <exception cref="RoutineFaildException"></exception>
  818. /// <exception cref="RoutineBreakException"></exception>
  819. protected void RobotGoto(int id, string name, ModuleName chamber, int slot, Hand blade, RobotPostionEnum postype,
  820. Action<string> notify, Action<string> error)
  821. {
  822. var reason = string.Empty;
  823. var ret = Execute(id, () =>
  824. {
  825. notify(string.Format("pick from {0}", chamber.ToString()));
  826. var obj = new object[] { (RobotArmEnum)(int)blade, chamber.ToString(), slot, postype };
  827. return robot.GoTo(obj);// (RobotArmEnum)(int)blade, chamber.ToString(), slot);
  828. });
  829. if (ret.Item1)
  830. if (ret.Item2 == Result.FAIL)
  831. {
  832. error(reason);
  833. throw new RoutineFaildException();
  834. }
  835. }
  836. protected void CheckTriggerSignalOn(int id,string name,ModuleName module,int time)
  837. {
  838. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  839. {
  840. Notify(String.Format("Check Trigger Signal"));
  841. string reason = string.Empty;
  842. return true;
  843. }, () =>
  844. {
  845. if (SC.GetValue<bool>("System.IsSimulatorMode")) return true;
  846. if (module.Equals(ModuleName.LL1))
  847. {
  848. if (DeviceModel.SensorPMASystemInterlock.Value && DeviceModel.TrigSafetytoPMA.Value)
  849. {
  850. return true;
  851. }
  852. }
  853. if (module.Equals(ModuleName.LL2))
  854. {
  855. if (DeviceModel.SensorPMBSystemInterlock.Value && DeviceModel.TrigSafetytoPMB.Value)
  856. {
  857. return true;
  858. }
  859. }
  860. return false;
  861. }, time * 1000);
  862. if (ret.Item1)
  863. {
  864. if (ret.Item2 == Result.FAIL)
  865. {
  866. throw (new RoutineFaildException());
  867. }
  868. else if (ret.Item2 == Result.TIMEOUT) //timeout
  869. {
  870. Stop(String.Format("Trigger Signal Change timeout, than {0} seconds", time));
  871. throw (new RoutineFaildException());
  872. }
  873. else
  874. throw (new RoutineBreakException());
  875. }
  876. }
  877. protected void PickWafer(int id, string name, ModuleName chamber, int slot, Hand blade, int x, int y, int z,
  878. Action<string> notify, Action<string> error)
  879. {
  880. var reason = string.Empty;
  881. var ret = Execute(id, () =>
  882. {
  883. notify(string.Format("pick from {0}", chamber.ToString()));
  884. if (x == 0 && y == 0 && z == 0)
  885. return robot.Pick((RobotArmEnum)(int)blade,chamber.ToString(), slot);
  886. return robot.PickEx((RobotArmEnum)(int)blade, chamber.ToString(), slot, x, y, z);
  887. });
  888. if (ret.Item1)
  889. if (ret.Item2 == Result.FAIL)
  890. {
  891. error(reason);
  892. throw new RoutineFaildException();
  893. }
  894. }
  895. protected void PlaceWafer(int id, string name, ModuleName chamber, int slot, Hand blade, int x, int y, int z,
  896. Action<string> notify, Action<string> error)
  897. {
  898. var ret = Execute(id, () =>
  899. {
  900. notify(string.Format("Place wafer to {0}", chamber.ToString()));
  901. var reason = string.Empty;
  902. if (x == 0 && y == 0 && z == 0)
  903. return robot.Place((RobotArmEnum)(int)blade, chamber.ToString(), slot);
  904. return robot.PlaceEx((RobotArmEnum)(int)blade, chamber.ToString(), slot, x, y, z);
  905. });
  906. if (ret.Item1)
  907. if (ret.Item2 == Result.FAIL)
  908. throw new RoutineFaildException();
  909. }
  910. #endregion
  911. protected bool CheckRobotMotionInterlock(ModuleName chamber, int slot, out string reason) //Pick/Place/Swap
  912. {
  913. reason = string.Empty;
  914. if (robot.RobotState == RobotStateEnum.Error)
  915. {
  916. reason = "robot is error.";
  917. return false;
  918. }
  919. //if (!robot.IsIdle)
  920. //{
  921. // reason = string.Format("robot is moving.");
  922. // return false;
  923. //}
  924. if (!CheckRobotReady())
  925. {
  926. reason = string.Format("robot isn't Ready.");
  927. return false;
  928. }
  929. if (chamber == ModuleName.Aligner)
  930. {
  931. if (aligner.Moving)
  932. {
  933. reason = string.Format("aligner is moving.");
  934. return false;
  935. }
  936. if (!CheckAlignerReady())
  937. {
  938. reason = string.Format("aligner isn't Ready.");
  939. return false;
  940. }
  941. /*
  942. if (aligner.Busy)
  943. {
  944. reason = string.Format("{0} is busy.", chamber.ToString());
  945. return false;
  946. }
  947. */
  948. return true;
  949. }
  950. else if (ModuleHelper.IsLoadPort(chamber))
  951. {
  952. LoadPortBaseDevice loadport = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
  953. if (!loadport.IsEnableTransferWafer(out _))
  954. {
  955. reason = string.Format("{0} isn't Ready.", chamber.ToString());
  956. return false;
  957. }
  958. if (loadport.MapError)
  959. {
  960. reason = string.Format("{0} Map has crossed error.", chamber.ToString());
  961. return false;
  962. }
  963. if (chamber.Equals(ModuleName.LP1))
  964. {
  965. if (SC.GetValue<int>($"LoadPort.LP1.CstType") == 0)
  966. {
  967. if (!DeviceModel.SensorSMIF1PODOPEN.Value)
  968. {
  969. reason = string.Format("{0} SMIF1PODOPEN signal is Off.", chamber.ToString());
  970. return false;
  971. }
  972. if (!DeviceModel.SensorSMIF1PODPRESENT.Value)
  973. {
  974. reason = string.Format("{0} SensorSMIF1PODPRESENT signal is Off,Foup is presence.", chamber.ToString());
  975. return false;
  976. }
  977. if (!DeviceModel.SensorSMIF1READY.Value)
  978. {
  979. reason = string.Format("{0} SensorSMIF1READY signal is Off.", chamber.ToString());
  980. return false;
  981. }
  982. }
  983. else if (SC.GetValue<int>($"LoadPort.LP1.CstType") == 1)
  984. {
  985. if(loadport.CassetteState!=LoadportCassetteState.Normal)// (DeviceModel.Sensor4InchCstPresence.Value&& DeviceModel.Sensor6InchCstPresence.Value&& DeviceModel.Sensor8InchCstPresence.Value)
  986. {
  987. reason = string.Format("{0} Cst Presence signal is Off,Foup is not presence.", chamber.ToString());
  988. return false;
  989. }
  990. }
  991. if (slot + 1 > loadport.ValidSlotsNumber)
  992. {
  993. reason = string.Format("{0} ValidSlotsNumber less than {1}.", chamber.ToString(), slot + 1);
  994. return false;
  995. }
  996. }
  997. else if (chamber.Equals(ModuleName.LP2))
  998. {
  999. if (SC.GetValue<int>($"LoadPort.LP2.CstType") == 0)
  1000. {
  1001. if (!DeviceModel.SensorSMIF2PODOPEN.Value)
  1002. {
  1003. reason = string.Format("{0} SMIF2PODOPEN signal is Off.", chamber.ToString());
  1004. return false;
  1005. }
  1006. if (!DeviceModel.SensorSMIF2PODPRESENT.Value)
  1007. {
  1008. reason = string.Format("{0} SensorSMIF2PODPRESENT signal is Off,Foup is not presence .", chamber.ToString());
  1009. return false;
  1010. }
  1011. if (!DeviceModel.SensorSMIF2READY.Value)
  1012. {
  1013. reason = string.Format("{0} SensorSMIF2READY signal is Off.", chamber.ToString());
  1014. return false;
  1015. }
  1016. }
  1017. else if (SC.GetValue<int>($"LoadPort.LP2.CstType") == 1)
  1018. {
  1019. if (loadport.CassetteState != LoadportCassetteState.Normal)// (DeviceModel.Sensor4InchCstPresence.Value&& DeviceModel.Sensor6InchCstPresence.Value&& DeviceModel.Sensor8InchCstPresence.Value)
  1020. {
  1021. reason = string.Format("{0} Cst Presence signal is Off,Foup is not presence.", chamber.ToString());
  1022. return false;
  1023. }
  1024. }
  1025. if (slot + 1 > loadport.ValidSlotsNumber)
  1026. {
  1027. reason = string.Format("{0} ValidSlotsNumber less than {1}.", chamber.ToString(), slot + 1);
  1028. return false;
  1029. }
  1030. }
  1031. return true;
  1032. }
  1033. if (ModuleHelper.IsLoadLock(chamber))
  1034. {
  1035. var ll = DEVICE.GetDevice<LoadLockDevice>(chamber.ToString());
  1036. if (!ll.IsEnableTransferWafer(out reason))
  1037. return false;
  1038. return true;
  1039. }
  1040. if (ModuleHelper.IsBuffer(chamber))
  1041. {
  1042. var bufferStation = DEVICE.GetDevice<BufferStation>(chamber.ToString());
  1043. if (!bufferStation.IsEnableTransferWafer(out reason))
  1044. return false;
  1045. return true;
  1046. }
  1047. if (ModuleHelper.IsCoolingBuffer(chamber)|| ModuleHelper.IsAligner(chamber))
  1048. {
  1049. IoCoolingBuffer buffer = DEVICE.GetDevice<IoCoolingBuffer>(chamber.ToString());
  1050. if (buffer.Busy)
  1051. {
  1052. reason = "buffer is not idle";
  1053. return false;
  1054. }
  1055. if (!buffer.CheckPinUp() )
  1056. {
  1057. reason = "buffer pin not up position";
  1058. return false;
  1059. }
  1060. return true;
  1061. }
  1062. reason = "error target";
  1063. return false;
  1064. }
  1065. protected bool CheckRobotReady()
  1066. {
  1067. return robot.IsReady();
  1068. }
  1069. protected bool CheckRobotMotionInterlock(out string reason)
  1070. {
  1071. reason = string.Empty;
  1072. if (robot.RobotState != RobotStateEnum.Idle )
  1073. {
  1074. reason = string.Format("robot is not idle.");
  1075. return false;
  1076. }
  1077. if (!CheckRobotReadySensor())
  1078. {
  1079. reason = string.Format("robot isn't ready.");
  1080. return false;
  1081. }
  1082. return true;
  1083. }
  1084. public void QueryLoadportState(int id, LoadPort device)
  1085. {
  1086. Tuple<bool, Result> ret = Execute(id, () =>
  1087. {
  1088. Notify(String.Format("Query {0} state", device.Name));
  1089. return device.IsIdle;
  1090. });
  1091. if (ret.Item1)
  1092. {
  1093. if (ret.Item2 == Result.FAIL)
  1094. {
  1095. Stop("not idle");
  1096. throw (new RoutineFaildException());
  1097. }
  1098. else
  1099. throw (new RoutineBreakException());
  1100. }
  1101. }
  1102. public void QueryAlignerState(int id, Aligner device)
  1103. {
  1104. Tuple<bool, Result> ret = Execute(id, () =>
  1105. {
  1106. Notify(String.Format("Query {0} state", device.Name));
  1107. return device.State == DeviceState.Idle;
  1108. });
  1109. if (ret.Item1)
  1110. {
  1111. if (ret.Item2 == Result.FAIL)
  1112. {
  1113. Stop("not idle");
  1114. throw (new RoutineFaildException());
  1115. }
  1116. else
  1117. throw (new RoutineBreakException());
  1118. }
  1119. }
  1120. public void QueryCoolBufferState(int id, IoCoolingBuffer device)
  1121. {
  1122. var ret = Execute(id, () =>
  1123. {
  1124. Notify(string.Format("Query {0} state", device.Name));
  1125. return true;
  1126. });
  1127. if (ret.Item1)
  1128. {
  1129. if (ret.Item2 == Result.FAIL)
  1130. {
  1131. Stop("Station wafer status error");
  1132. throw new RoutineFaildException();
  1133. }
  1134. throw new RoutineBreakException();
  1135. }
  1136. }
  1137. public IoCoolingBuffer GetCoolBuffer(ModuleName coolbufferName)
  1138. {
  1139. switch (coolbufferName)
  1140. {
  1141. case ModuleName.CoolingBuffer1:
  1142. _ioCoolBuffer = buffer1;
  1143. break;
  1144. case ModuleName.CoolingBuffer2:
  1145. _ioCoolBuffer = buffer2;
  1146. break;
  1147. case ModuleName.Aligner1:
  1148. _ioCoolBuffer = aligner1;
  1149. break;
  1150. case ModuleName.Aligner2:
  1151. _ioCoolBuffer = aligner2;
  1152. break;
  1153. }
  1154. return _ioCoolBuffer;
  1155. }
  1156. public void QueryLoadportState(int id, string deviceName, int time)
  1157. {
  1158. LoadPortBaseDevice device = DEVICE.GetDevice<LoadPortBaseDevice>(deviceName);
  1159. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1160. {
  1161. Notify(String.Format("{0} query state", deviceName));
  1162. string reason = string.Empty;
  1163. device.QueryState(out reason);
  1164. return true;
  1165. }, () =>
  1166. {
  1167. if (device.IsReady())
  1168. {
  1169. return true;
  1170. }
  1171. return false;
  1172. }, time * 1000);
  1173. if (ret.Item1)
  1174. {
  1175. if (ret.Item2 == Result.FAIL)
  1176. {
  1177. throw (new RoutineFaildException());
  1178. }
  1179. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1180. {
  1181. Stop(String.Format("{0} query timeout, than {1} seconds", device.Name, time));
  1182. throw (new RoutineFaildException());
  1183. }
  1184. else
  1185. throw (new RoutineBreakException());
  1186. }
  1187. }
  1188. public void IsLoadLockReadyToTransfer(string deviceName)
  1189. {
  1190. var device = DEVICE.GetDevice<LoadLockDevice>(deviceName);
  1191. if (!device.IsEnableTransferWafer(out var reason))
  1192. {
  1193. EV.PostMessage(deviceName, EventEnum.DefaultWarning, reason);
  1194. throw new RoutineBreakException();
  1195. }
  1196. }
  1197. public void LoadLockOpenAtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
  1198. {
  1199. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1200. {
  1201. notify(name);
  1202. _timerQuery.Start(_queryPeriod); //开始查询
  1203. return LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Opened || LoadLockDevice.OpenAtmDoor(out string reason);
  1204. }, () =>
  1205. {
  1206. if (LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Opened)
  1207. return true;
  1208. return false;
  1209. }, time * 1000);
  1210. if (ret.Item1)
  1211. {
  1212. if (ret.Item2 == Result.FAIL)
  1213. {
  1214. throw (new RoutineFaildException());
  1215. }
  1216. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1217. {
  1218. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1219. throw (new RoutineFaildException());
  1220. }
  1221. else
  1222. throw (new RoutineBreakException());
  1223. }
  1224. }
  1225. public void LoadLockCloseAtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
  1226. {
  1227. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1228. {
  1229. notify(name);
  1230. return LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Closed || LoadLockDevice.CloseAtmDoor(out string reason);
  1231. }, () =>
  1232. {
  1233. if (LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Closed)
  1234. return true;
  1235. return false;
  1236. }, time * 1000);
  1237. if (ret.Item1)
  1238. {
  1239. if (ret.Item2 == Result.FAIL)
  1240. {
  1241. throw (new RoutineFaildException());
  1242. }
  1243. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1244. {
  1245. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1246. throw (new RoutineFaildException());
  1247. }
  1248. else
  1249. throw (new RoutineBreakException());
  1250. }
  1251. }
  1252. public void LoadLockOpenVtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
  1253. {
  1254. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1255. {
  1256. notify(name);
  1257. _timerQuery.Start(_queryPeriod); //开始查询
  1258. return LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Opened || LoadLockDevice.OpenVtmDoor(out string reason);
  1259. }, () =>
  1260. {
  1261. if (LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Opened)
  1262. return true;
  1263. return false;
  1264. }, time * 1000);
  1265. if (ret.Item1)
  1266. {
  1267. if (ret.Item2 == Result.FAIL)
  1268. {
  1269. throw (new RoutineFaildException());
  1270. }
  1271. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1272. {
  1273. error($"{name} timeout, than {time} seconds");
  1274. throw (new RoutineFaildException());
  1275. }
  1276. else
  1277. throw (new RoutineBreakException());
  1278. }
  1279. }
  1280. public void LoadLockCloseVtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
  1281. {
  1282. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1283. {
  1284. notify(name);
  1285. return LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Closed || LoadLockDevice.CloseVtmDoor(out string reason);
  1286. }, () =>
  1287. {
  1288. if (LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Closed)
  1289. return true;
  1290. return false;
  1291. }, time * 1000);
  1292. if (ret.Item1)
  1293. {
  1294. if (ret.Item2 == Result.FAIL)
  1295. {
  1296. throw (new RoutineFaildException());
  1297. }
  1298. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1299. {
  1300. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1301. throw (new RoutineFaildException());
  1302. }
  1303. else
  1304. throw (new RoutineBreakException());
  1305. }
  1306. }
  1307. protected void Default()
  1308. {
  1309. string reason = String.Empty;
  1310. }
  1311. protected virtual void Warning(string message)
  1312. {
  1313. EV.PostMessage(Module, EventEnum.DefaultWarning, message);
  1314. }
  1315. ///等待 Aligner Motion
  1316. public void WaitAlignerMotion(int id, Aligner device, string name, int time, Action<string> notify, Action<string> error)
  1317. {
  1318. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1319. {
  1320. notify(name);
  1321. _timerQuery.Start(_queryPeriod); //开始查询
  1322. return true;
  1323. }, () =>
  1324. {
  1325. // if (device.Moving == false && CheckAlignerReady())
  1326. if (device.Busy == false && CheckAlignerReady())
  1327. {
  1328. _timerQuery.Stop();
  1329. return true;
  1330. }
  1331. if (query())
  1332. {
  1333. // string reason = string.Empty;
  1334. // device.QueryState(out reason); //查询位置
  1335. }
  1336. return false;
  1337. }, time * 1000);
  1338. if (ret.Item1)
  1339. {
  1340. if (ret.Item2 == Result.FAIL)
  1341. {
  1342. throw (new RoutineFaildException());
  1343. }
  1344. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1345. {
  1346. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1347. throw (new RoutineFaildException());
  1348. }
  1349. else
  1350. throw (new RoutineBreakException());
  1351. }
  1352. }
  1353. protected virtual void Notify(string message)
  1354. {
  1355. EV.PostInfoLog(Module, $"{Name}, {message}");
  1356. }
  1357. protected virtual void Stop(string failReason)
  1358. {
  1359. EV.PostAlarmLog(Module, $"{Name}, {failReason}");
  1360. }
  1361. public void Abort()
  1362. {
  1363. }
  1364. private bool query()
  1365. {
  1366. if (_timerQuery.IsTimeout())
  1367. {
  1368. _timerQuery.Start(_queryPeriod);
  1369. return true;
  1370. }
  1371. return false;
  1372. }
  1373. protected bool CheckSeneorHasWafer(ModuleName chamber, int slot)
  1374. {
  1375. if (!SC.GetValue<bool>(SorterCommon.ScPathName.System_IsSimulatorMode))
  1376. {
  1377. if (chamber == ModuleName.Robot)
  1378. {
  1379. if (slot == 0)
  1380. return robot.IsWaferPresenceOnBlade1;//!DeviceModel.SensorRBlowerArmhavewafer.Value;
  1381. return robot.IsWaferPresenceOnBlade2;
  1382. }
  1383. //if (chamber == ModuleName.Aligner)
  1384. //{
  1385. // return !DeviceModel.SensorPreAlignerWaferOn.Value;
  1386. //}
  1387. }
  1388. return WaferManager.Instance.CheckHasWafer(chamber, slot);
  1389. }
  1390. protected bool CheckSensorNoWafer(ModuleName chamber, int slot)
  1391. {
  1392. if (!SC.GetValue<bool>(SorterCommon.ScPathName.System_IsSimulatorMode))
  1393. {
  1394. if (chamber == ModuleName.Robot)
  1395. {
  1396. if (slot == 0)
  1397. return !robot.IsWaferPresenceOnBlade1; //DeviceModel.SensorRBlowerArmhavewafer.Value;
  1398. return !robot.IsWaferPresenceOnBlade2; //DeviceModel.SensorRBupperArmhavewafer.Value;
  1399. }
  1400. //if (chamber == ModuleName.Aligner)
  1401. //{
  1402. // return DeviceModel.SensorPreAlignerWaferOn.Value;
  1403. //}
  1404. }
  1405. return WaferManager.Instance.CheckNoWafer(chamber, slot);
  1406. }
  1407. protected bool CheckRobotReadySensor()
  1408. {
  1409. return (robot.RobotState == RobotStateEnum.Idle);
  1410. }
  1411. protected bool CheckAlignerReady()
  1412. {
  1413. return true;
  1414. }
  1415. ///等待 Loadport
  1416. public void LoadportReset(int id, LoadPortBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
  1417. {
  1418. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1419. {
  1420. notify(String.Format("{0} clear error", device.Name));
  1421. string reason = string.Empty;
  1422. return device.LoadportReset(out reason);
  1423. }, () =>
  1424. {
  1425. if (device.IsReady())
  1426. {
  1427. return true;
  1428. }
  1429. return false;
  1430. }, time * 1000);
  1431. if (ret.Item1)
  1432. {
  1433. if (ret.Item2 == Result.FAIL)
  1434. {
  1435. throw (new RoutineFaildException());
  1436. }
  1437. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1438. {
  1439. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1440. throw (new RoutineFaildException());
  1441. }
  1442. else
  1443. throw (new RoutineBreakException());
  1444. }
  1445. }
  1446. public void LoadportInit(int id, LoadPortBaseDevice device, string name, Action<string> notify, Action<string> error)
  1447. {
  1448. Tuple<bool, Result> ret = Execute(id, () =>
  1449. {
  1450. notify(String.Format("{0} Home", device.Name));
  1451. string reason = string.Empty;
  1452. return device.Home(out reason);
  1453. });
  1454. if (ret.Item1)
  1455. {
  1456. if (ret.Item2 == Result.FAIL)
  1457. {
  1458. throw (new RoutineFaildException());
  1459. }
  1460. }
  1461. }
  1462. protected bool CheckLoadportMotionInterlock(ModuleName chamber, out string reason)
  1463. {
  1464. reason = string.Empty;
  1465. if (robot.RobotState != RobotStateEnum.Idle)
  1466. {
  1467. reason = string.Format("robot is not idle.");
  1468. return false;
  1469. }
  1470. if (!CheckRobotReady())
  1471. {
  1472. reason = string.Format("robot isn't ready.");
  1473. return false;
  1474. }
  1475. return true;
  1476. }
  1477. ///等待 Loadport
  1478. public void WaitLoadportMotion(int id, LoadPortBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
  1479. {
  1480. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1481. {
  1482. notify(name);
  1483. string msg = string.Empty;
  1484. //device.QueryState(out msg); //查询状
  1485. _timerQuery.Start(_queryPeriod); //开始查询
  1486. return true;
  1487. }, () =>
  1488. {
  1489. if (device.CurrentState == LoadPortStateEnum.Error)
  1490. {
  1491. return null;
  1492. }
  1493. if (device.IsReady())
  1494. {
  1495. _timerQuery.Stop();
  1496. return true;
  1497. }
  1498. return false;
  1499. }, time * 1000);
  1500. if (ret.Item1)
  1501. {
  1502. if (ret.Item2 == Result.FAIL)
  1503. {
  1504. throw (new RoutineFaildException());
  1505. }
  1506. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1507. {
  1508. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1509. throw (new RoutineFaildException());
  1510. }
  1511. else
  1512. throw (new RoutineBreakException());
  1513. }
  1514. }
  1515. protected void LoadportAllReset(int id, int time)
  1516. {
  1517. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1518. {
  1519. Notify(String.Format("clear error for all loadports"));
  1520. string reason = string.Empty;
  1521. LPs.ForEach(lp => lp.ClearError(out reason));
  1522. return true;
  1523. }, () =>
  1524. {
  1525. if (LPs.Any(lp => lp.IsBusy))
  1526. {
  1527. return false;
  1528. }
  1529. return true;
  1530. }, time * 1000);
  1531. if (ret.Item1)
  1532. {
  1533. if (ret.Item2 == Result.FAIL)
  1534. {
  1535. throw (new RoutineFaildException());
  1536. }
  1537. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1538. {
  1539. Stop(String.Format("LoadportAllReset timeout, than {0} seconds", time));
  1540. throw (new RoutineFaildException());
  1541. }
  1542. else
  1543. throw (new RoutineBreakException());
  1544. }
  1545. }
  1546. protected void LoadportAllInit(int id, int time)
  1547. {
  1548. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1549. {
  1550. Notify(String.Format("All loadports Homing"));
  1551. string reason = string.Empty;
  1552. LPs.ForEach(lp =>lp.Home(out reason));
  1553. _timerQuery.Start(_queryPeriod); //开始查询
  1554. return true;
  1555. }, () =>
  1556. {
  1557. if (LPs.Any(lp => lp.CurrentState == LoadPortStateEnum.Error))
  1558. {
  1559. return null;
  1560. }
  1561. if (LPs.Any(lp => !lp.IsHomed)) //!lp.IsReady() &&
  1562. {
  1563. return false;
  1564. }
  1565. LPs.ForEach(m=>LOG.Write($"{m.Name}:{m.IsHomed }"));
  1566. return true;
  1567. }, time * 1000);
  1568. if (ret.Item1)
  1569. {
  1570. if (ret.Item2 == Result.FAIL)
  1571. {
  1572. throw (new RoutineFaildException());
  1573. }
  1574. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1575. {
  1576. Stop(String.Format("LoadportAllInit timeout, than {0} seconds", time));
  1577. throw (new RoutineFaildException());
  1578. }
  1579. else
  1580. throw (new RoutineBreakException());
  1581. }
  1582. }
  1583. protected void PostMessage(int id, string v)
  1584. {
  1585. Tuple<bool, Result> ret = Execute(id, () =>
  1586. {
  1587. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, v);
  1588. return true;
  1589. });
  1590. if (ret.Item1)
  1591. {
  1592. if (ret.Item2 == Result.FAIL)
  1593. {
  1594. throw (new RoutineFaildException());
  1595. }
  1596. }
  1597. }
  1598. public void TimeDelay(int id, int timeMs)
  1599. {
  1600. Tuple<bool, Result> ret = Delay(id, () =>
  1601. {
  1602. Notify($"Delay {timeMs} milliseconds");
  1603. return true;
  1604. }, timeMs);
  1605. if (ret.Item1)
  1606. {
  1607. if (ret.Item2 == Result.RUN)
  1608. {
  1609. throw (new RoutineBreakException());
  1610. }
  1611. }
  1612. }
  1613. }
  1614. }