CommonRoutine.cs 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292
  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. using EFEM.RT.Devices.Flipper;
  27. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Flipper.FlipperBase;
  28. using EFEM.RT.Modules;
  29. using static EFEM.RT.Devices.FlipperEntity;
  30. namespace EFEM.RT.Routines
  31. {
  32. public class CommonRoutine : SeqenecRoutine
  33. {
  34. protected bool bUINotify;
  35. public string Module { get; set; }
  36. public string Name { get; set; }
  37. public string Display { get; set; }
  38. //protected LoadPort loadportA = null;
  39. //protected LoadPort loadportB = null;
  40. //protected RIDReader ridreaderA = null;
  41. //protected RIDReader ridreaderB = null;
  42. protected RobotBaseDevice robot = null;
  43. protected Aligner aligner = null;
  44. protected OcrReader widreader = null;
  45. protected IoCoolingBuffer buffer1 = null;
  46. protected IoCoolingBuffer buffer2 = null;
  47. protected JetFlipper flipper = null;
  48. protected IoCoolingBuffer aligner1 = null;
  49. protected IoCoolingBuffer aligner2 = null;
  50. protected LoadLockDevice ll1 = null;
  51. protected LoadLockDevice ll2 = null;
  52. protected IoCoolingBuffer _ioCoolBuffer;
  53. protected BufferStation bf = null;
  54. protected BufferStation bf1 = null;
  55. protected BufferStation bf2 = null;
  56. private List<LoadPortBaseDevice> LPs;
  57. protected readonly bool HaveAligner = DeviceDefineManager.Instance.GetValue<bool>("AlignerInstalled") ?? false;
  58. protected readonly bool AlignerNeedMoveUpCommand = DeviceDefineManager.Instance.GetValue<bool>("AlignerNeedMoveUpCommand") ?? false;
  59. protected readonly int LoadPortQuantity = DeviceDefineManager.Instance.GetValue<int>("LoadPortQuantity") ?? 0;
  60. protected readonly string RobotTypeDefine = DeviceDefineManager.Instance.GetValue("RobotType");
  61. protected readonly bool HaveMotionAxis = DeviceDefineManager.Instance.GetValue<bool>("MotionAxisInstalled") ?? false;
  62. protected static readonly bool LoadLockDoorControlByStation = DeviceDefineManager.Instance.GetValue<bool>("LLDoorControlByStation") ?? false;
  63. //protected readonly string LoadPortTypeDefine = DeviceDefineManager.Instance.GetValue("LoadPortType");
  64. protected int OffsetX;
  65. protected int OffsetY;
  66. protected int OffsetZ;
  67. private DeviceTimer _timerQuery = new DeviceTimer();
  68. private int _queryPeriod = 500; //ms
  69. protected bool NeedSetParameter;
  70. protected bool IsStopped;
  71. private int _existInterval = SC.GetValue<int>("Robot.Robot.ExistInterval");
  72. protected bool NeedRobotGripAndUngrip=SC.GetValue<bool>("System.EnableRobotGripAndUngrip");
  73. public bool IsEnableIdentifyThickness
  74. {
  75. get
  76. {
  77. if (SC.ContainsItem("System.IsEnableIdentifyThickness"))
  78. return SC.GetValue<bool>("System.IsEnableIdentifyThickness");
  79. return false;
  80. }
  81. }
  82. public bool IsEnableMultiWaferSize
  83. {
  84. get
  85. {
  86. if (SC.ContainsItem("System.IsEnableMultiWaferSize"))
  87. return SC.GetValue<bool>("System.IsEnableMultiWaferSize");
  88. return false;
  89. }
  90. }
  91. public string EFemNum
  92. {
  93. get
  94. {
  95. if (SC.ContainsItem("System.EFEMNUM"))
  96. return SC.GetStringValue("System.EFEMNUM");
  97. return "001";
  98. }
  99. }
  100. public bool IsVacuumMode
  101. {
  102. get
  103. {
  104. if (SC.ContainsItem("Robot.Robot.IsVacuumMode"))
  105. return SC.GetValue<bool>("Robot.Robot.IsVacuumMode");
  106. return true;
  107. }
  108. }
  109. private DeviceTimer _timerPerf = new DeviceTimer();
  110. public CommonRoutine()
  111. {
  112. robot = DEVICE.GetDevice<RobotBaseDevice>(DeviceName.Robot);
  113. aligner = DEVICE.GetDevice<Aligner>(DeviceName.Aligner);
  114. widreader = DEVICE.GetDevice<OcrReader>(DeviceName.WIDReader);
  115. buffer1 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.CoolingBuffer1);
  116. buffer2 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.CoolingBuffer2);
  117. flipper = DEVICE.GetDevice<JetFlipper>(DeviceName.Flipper);
  118. aligner1 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.Aligner1);
  119. aligner2 = DEVICE.GetDevice<IoCoolingBuffer>(DeviceName.Aligner2);
  120. ll1 = DEVICE.GetDevice<LoadLockDevice>(DeviceName.LL1);
  121. ll2 = DEVICE.GetDevice<LoadLockDevice>(DeviceName.LL2);
  122. bf = DEVICE.GetDevice<BufferStation>(DeviceName.Buffer);
  123. bf1 = DEVICE.GetDevice<BufferStation>(DeviceName.Buffer1);
  124. bf2 = DEVICE.GetDevice<BufferStation>(DeviceName.Buffer2);
  125. var lpNames = new List<ModuleName>(Singleton<DeviceManager>.Instance.LpNames);
  126. LPs = new List<LoadPortBaseDevice>();
  127. lpNames.ForEach(lp =>
  128. {
  129. if(!SC.GetValue<bool>($"LoadPort.{lp}.Disable"))
  130. LPs.Add(DEVICE.GetDevice<LoadPortBaseDevice>(lp.ToString()));
  131. });
  132. }
  133. public bool InitCommon()
  134. {
  135. return true;
  136. }
  137. protected void UpdateSCValue()
  138. {
  139. }
  140. //延时
  141. public void Delay(int id, string name, double time, Action<string> notify, Action<string> error)
  142. {
  143. Tuple<bool, Result> ret = Delay(id, () =>
  144. {
  145. notify(name);
  146. return true;
  147. }, time * 1000);
  148. if (ret.Item1)
  149. {
  150. if (ret.Item2 == Result.RUN)
  151. {
  152. throw (new RoutineBreakException());
  153. }
  154. }
  155. }
  156. #region waferID
  157. #endregion
  158. #region robot
  159. public void RobotReset(int id, RobotBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
  160. {
  161. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  162. {
  163. notify(String.Format("{0} clear error", device.Name));
  164. string reason = string.Empty;
  165. device.RobotReset();
  166. return true;
  167. }, () =>
  168. {
  169. if (!device.IsBusy&& device.RobotState != RobotStateEnum.Error && device.RobotState == RobotStateEnum.Idle)
  170. {
  171. return true;
  172. }
  173. return false;
  174. }, time * 1000);
  175. if (ret.Item1)
  176. {
  177. if (ret.Item2 == Result.FAIL)
  178. {
  179. throw (new RoutineFaildException());
  180. }
  181. else if (ret.Item2 == Result.TIMEOUT) //timeout
  182. {
  183. error(String.Format("{0} timeout, than {1} seconds", name, time));
  184. throw (new RoutineFaildException());
  185. }
  186. else
  187. throw (new RoutineBreakException());
  188. }
  189. }
  190. public void RobotServoOnOff(int id, Robot device, bool trueForOnFalseForOff, Action<string> notify, Action<string> error)
  191. {
  192. Tuple<bool, Result> ret = Execute(id, () =>
  193. {
  194. notify(String.Format("{0} Home", device.Name));
  195. string reason = string.Empty;
  196. return device.SetServoOnOff(trueForOnFalseForOff,out reason);
  197. });
  198. if (ret.Item1)
  199. {
  200. if (ret.Item2 == Result.FAIL)
  201. {
  202. throw (new RoutineFaildException());
  203. }
  204. }
  205. }
  206. public void RobotInit(int id, Robot device, string name, Action<string> notify, Action<string> error)
  207. {
  208. Tuple<bool, Result> ret = Execute(id, () =>
  209. {
  210. notify(String.Format("{0} Home", device.Name));
  211. string reason = string.Empty;
  212. return device.Init(out reason);
  213. });
  214. if (ret.Item1)
  215. {
  216. if (ret.Item2 == Result.FAIL)
  217. {
  218. throw (new RoutineFaildException());
  219. }
  220. }
  221. }
  222. public void RobotHome(int id, RobotBaseDevice device, string name, Action<string> notify, Action<string> error)
  223. {
  224. Tuple<bool, Result> ret = Execute(id, () =>
  225. {
  226. notify(String.Format("{0} Home", device.Name));
  227. string reason = string.Empty;
  228. return device.Home(null);
  229. });
  230. if (ret.Item1)
  231. {
  232. if (ret.Item2 == Result.FAIL)
  233. {
  234. throw (new RoutineFaildException());
  235. }
  236. }
  237. }
  238. public void RobotArmHome(int id, RobotBaseDevice device, string name, Action<string> notify, Action<string> error)
  239. {
  240. Tuple<bool, Result> ret = Execute(id, () =>
  241. {
  242. notify(String.Format("{0} Arm Home", device.Name));
  243. string reason = string.Empty;
  244. return device.Home(null);
  245. });
  246. if (ret.Item1)
  247. {
  248. if (ret.Item2 == Result.FAIL)
  249. {
  250. throw (new RoutineFaildException());
  251. }
  252. }
  253. }
  254. ///等待 Robot Motion
  255. public void WaitRobotMotion(int id, RobotBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
  256. {
  257. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  258. {
  259. notify("Wait robot finish motion");
  260. _timerQuery.Start(_queryPeriod); //开始查询
  261. return true;
  262. }, () =>
  263. {
  264. if (device.IsReady())
  265. {
  266. _timerQuery.Stop();
  267. return true;
  268. }
  269. if (query())
  270. {
  271. // string reason = string.Empty;
  272. // device.QueryState(out reason); //查询位置
  273. }
  274. return false;
  275. }, time * 1000);
  276. if (ret.Item1)
  277. {
  278. if (ret.Item2 == Result.FAIL)
  279. {
  280. throw (new RoutineFaildException());
  281. }
  282. else if (ret.Item2 == Result.TIMEOUT) //timeout
  283. {
  284. error(String.Format("{0} timeout, than {1} seconds", name, time));
  285. throw (new RoutineFaildException());
  286. }
  287. else
  288. throw (new RoutineBreakException());
  289. }
  290. }
  291. ///等待
  292. ///
  293. public void ReserveRobotToBusy(int id, RobotBaseDevice robot, string name,Action<string> notify, Action<string> error)
  294. {
  295. Tuple<bool, Result> ret = Execute(id, () =>
  296. {
  297. notify(String.Format("{0} set robot to busy", robot.Name));
  298. string reason = string.Empty;
  299. robot.IsBusy = true;
  300. return true;
  301. });
  302. if (ret.Item1)
  303. {
  304. if (ret.Item2 == Result.FAIL)
  305. {
  306. throw (new RoutineFaildException());
  307. }
  308. }
  309. }
  310. public void Wait(int id, string name, double time, Action<string> notify, Action<string> error)
  311. {
  312. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  313. {
  314. notify($"Wait {time} seconds");
  315. _timerQuery.Start(_queryPeriod); //开始查询
  316. return true;
  317. }, () =>
  318. {
  319. if (_timerQuery.GetElapseTime() >= time * 1000)
  320. {
  321. _timerQuery.Stop();
  322. return true;
  323. }
  324. return false;
  325. });
  326. if (ret.Item1)
  327. {
  328. if (ret.Item2 == Result.FAIL)
  329. {
  330. throw (new RoutineFaildException());
  331. }
  332. else
  333. throw (new RoutineBreakException());
  334. }
  335. }
  336. public void CoolBufferMoveUP(int id, IoCoolingBuffer device, WaferSize size, int time, Action<string> notify, Action<string> error)
  337. {
  338. Tuple<bool, Result> ret = Execute(id, () =>
  339. {
  340. notify($"Start {device.Name} Move Up");
  341. if (device.CheckPinUp()) return true;
  342. if (!device.Move(size, true, out string reason))
  343. {
  344. Stop(reason);
  345. return false;
  346. }
  347. return true;
  348. });
  349. if (ret.Item1)
  350. {
  351. if (ret.Item2 == Result.FAIL)
  352. {
  353. throw (new RoutineFaildException());
  354. }
  355. }
  356. }
  357. public void RobotBusytoSimif(int id, ModuleName moduleName,bool on,int time, Action<string> notify, Action<string> error)
  358. {
  359. Tuple<bool, Result> ret = Execute(id, () =>
  360. {
  361. notify($"set TrigRBbusytoSIMF of {moduleName} signal {on} ");
  362. if (on)
  363. {
  364. var value = moduleName == ModuleName.LP1 ? DeviceModel.TrigRBbusytoSIMF1.SetTrigger(true, out _) : DeviceModel.TrigRBbusytoSIMF2.SetTrigger(true, out _);
  365. if (!value)
  366. {
  367. Stop(null);
  368. return false;
  369. }
  370. }
  371. else
  372. {
  373. var value = moduleName == ModuleName.LP1 ? DeviceModel.TrigRBbusytoSIMF1.SetTrigger(false, out _) : DeviceModel.TrigRBbusytoSIMF2.SetTrigger(false, out _);
  374. if (!value)
  375. {
  376. Stop(null);
  377. return false;
  378. }
  379. }
  380. return true;
  381. });
  382. if (ret.Item1)
  383. {
  384. if (ret.Item2 == Result.FAIL)
  385. {
  386. throw (new RoutineFaildException());
  387. }
  388. }
  389. }
  390. public void UnGripRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
  391. {
  392. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  393. {
  394. Notify($"Release robot {blade}");
  395. //IoSensor sensorBlade = blade == Hand.Blade1
  396. // ? DeviceModel.SensorRobotFork1WaferOn
  397. // : DeviceModel.SensorRobotFork2WaferOn;
  398. //var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
  399. //int slot = blade == Hand.Blade1 ? 0 : 1;
  400. //if (WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot)) //!sensorBlade.Value &&
  401. {
  402. if (!device.Release((RobotArmEnum)blade))
  403. {
  404. Stop(null);
  405. return false;
  406. }
  407. }
  408. return true;
  409. }, () =>
  410. {
  411. if (!device.IsBusy)
  412. {
  413. return true;
  414. }
  415. //此处如果发生错误,忽略
  416. return false;
  417. }, time * 1000);
  418. if (ret.Item1)
  419. {
  420. if (ret.Item2 == Result.FAIL)
  421. {
  422. throw (new RoutineFaildException());
  423. }
  424. else if (ret.Item2 == Result.TIMEOUT) //timeout
  425. {
  426. Stop($"Release robot {blade} timeout, than {time} seconds");
  427. throw (new RoutineFaildException());
  428. }
  429. else
  430. throw (new RoutineBreakException());
  431. }
  432. }
  433. public void GripRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
  434. {
  435. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  436. {
  437. Notify($"Grip robot {blade}");
  438. //IoSensor sensorBlade = blade == Hand.Blade1
  439. // ? DeviceModel.SensorRobotFork1WaferOn
  440. // : DeviceModel.SensorRobotFork2WaferOn;
  441. //var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
  442. //int slot = blade == Hand.Blade1 ? 0 : 1;
  443. //if (!iswaferpersence && WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot)) //!sensorBlade.Value &&
  444. //{
  445. if (!device.Grip((RobotArmEnum)blade))
  446. {
  447. Stop(null);
  448. return false;
  449. }
  450. // }
  451. return true;
  452. }, () =>
  453. {
  454. if (device.IsReady())
  455. {
  456. return true;
  457. }
  458. //此处如果发生错误,忽略
  459. return false;
  460. }, time * 1000);
  461. if (ret.Item1)
  462. {
  463. if (ret.Item2 == Result.FAIL)
  464. {
  465. throw (new RoutineFaildException());
  466. }
  467. else if (ret.Item2 == Result.TIMEOUT) //timeout
  468. {
  469. Stop($"Release robot {blade} timeout, than {time} seconds");
  470. throw (new RoutineFaildException());
  471. }
  472. else
  473. throw (new RoutineBreakException());
  474. }
  475. }
  476. public void HomeReleaseRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
  477. {
  478. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  479. {
  480. Notify($"Release robot {blade}");
  481. //IoSensor sensorBlade = blade == Hand.Blade1
  482. // ? DeviceModel.SensorRobotFork1WaferOn
  483. // : DeviceModel.SensorRobotFork2WaferOn;
  484. //var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
  485. //int slot = blade == Hand.Blade1 ? 0 : 1;
  486. //if (!iswaferpersence&&WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot)) //!sensorBlade.Value &&
  487. //{
  488. if (!device.Release((RobotArmEnum)blade))
  489. {
  490. Stop(null);
  491. return false;
  492. }
  493. // }
  494. return true;
  495. }, () =>
  496. {
  497. if (device.IsReady())
  498. {
  499. return true;
  500. }
  501. //此处如果发生错误,忽略
  502. return false;
  503. }, time * 1000);
  504. if (ret.Item1)
  505. {
  506. if (ret.Item2 == Result.FAIL)
  507. {
  508. throw (new RoutineFaildException());
  509. }
  510. else if (ret.Item2 == Result.TIMEOUT) //timeout
  511. {
  512. Stop($"Release robot {blade} timeout, than {time} seconds");
  513. throw (new RoutineFaildException());
  514. }
  515. else
  516. throw (new RoutineBreakException());
  517. }
  518. }
  519. public void HomeGripAndUngripRobotBlade(int id, Hand blade, RobotBaseDevice device, int time)
  520. {
  521. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  522. {
  523. Notify($"Grip or Ungrip robot {blade}");
  524. int slot = blade == Hand.Blade1 ? 0 : 1;
  525. if (WaferManager.Instance.CheckHasWafer(ModuleName.Robot, slot))
  526. {
  527. if (!device.Grip((RobotArmEnum)blade))
  528. {
  529. Stop(null);
  530. return false;
  531. }
  532. }
  533. else
  534. {
  535. if (!device.Release((RobotArmEnum)blade))
  536. {
  537. Stop(null);
  538. return false;
  539. }
  540. }
  541. //Thread.Sleep(1000);
  542. return true;
  543. }, () =>
  544. {
  545. if (device.IsReady())
  546. {
  547. return true;
  548. }
  549. //此处如果发生错误,忽略
  550. return false;
  551. }, time * 1000);
  552. if (ret.Item1)
  553. {
  554. if (ret.Item2 == Result.FAIL)
  555. {
  556. throw (new RoutineFaildException());
  557. }
  558. else if (ret.Item2 == Result.TIMEOUT) //timeout
  559. {
  560. Stop($"Grip robot {blade} timeout, than {time} seconds");
  561. throw (new RoutineFaildException());
  562. }
  563. else
  564. throw (new RoutineBreakException());
  565. }
  566. }
  567. public void CheckBladeWaferIsExist(int id, RobotBaseDevice device,Hand blade, int time)
  568. {
  569. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  570. {
  571. Notify($"Check Blade {blade} Wafer Is Exist");
  572. try
  573. {
  574. if (!device.IsReady())
  575. {
  576. LOG.Write($"CheckBladeWaferIsExist:Robot IsReady={device.IsReady()}");
  577. throw (new RoutineBreakException());
  578. }
  579. if (!device.ReadParameter(new object[] { "CheckWaferIsPresence", blade == Hand.Blade1 ? 0 : 1, _existInterval }))
  580. {
  581. Stop(null);
  582. return false;
  583. }
  584. }
  585. catch (Exception ex)
  586. {
  587. LOG.Write(ex);
  588. }
  589. LOG.Write($"Check Blade Wafer Is Exist");
  590. //Thread.Sleep(1000);
  591. return true;
  592. }, () =>
  593. {
  594. // LOG.Write("CheckBladeWaferIsExist1: IsReady=false");
  595. try
  596. {
  597. if (device.IsReady())
  598. {
  599. LOG.Write("CheckBladeWaferIsExist: IsReady=true");
  600. return true;
  601. }
  602. }
  603. catch (Exception ex)
  604. {
  605. LOG.Write(ex);
  606. }
  607. //LOG.Write("CheckBladeWaferIsExist2: IsReady=false");
  608. //此处如果发生错误,忽略
  609. return false;
  610. }, time * 1000);
  611. if (ret.Item1)
  612. {
  613. if (ret.Item2 == Result.FAIL)
  614. {
  615. throw (new RoutineFaildException());
  616. }
  617. else if (ret.Item2 == Result.TIMEOUT) //timeout
  618. {
  619. Stop($"Check robot WaferPresence timeout, than {time} seconds");
  620. throw (new RoutineFaildException());
  621. }
  622. else
  623. throw (new RoutineBreakException());
  624. }
  625. }
  626. public void RobotSignalStatus(int id, RobotBaseDevice device , int time)
  627. {
  628. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  629. {
  630. Notify($"Query robot Signal Status");
  631. if (!device.ReadParameter(new object[] { "SignalStatus"}))
  632. {
  633. Stop(null);
  634. return false;
  635. }
  636. //Thread.Sleep(1000);
  637. return true;
  638. }, () =>
  639. {
  640. if (device.IsReady())
  641. {
  642. return true;
  643. }
  644. //此处如果发生错误,忽略
  645. return false;
  646. }, time * 1000);
  647. if (ret.Item1)
  648. {
  649. if (ret.Item2 == Result.FAIL)
  650. {
  651. throw (new RoutineFaildException());
  652. }
  653. else if (ret.Item2 == Result.TIMEOUT) //timeout
  654. {
  655. throw (new RoutineFaildException());
  656. }
  657. else
  658. throw (new RoutineBreakException());
  659. }
  660. }
  661. public void ConfirmRobotBladeWafer(int id, Hand blade)
  662. {
  663. Execute(id, () =>
  664. {
  665. Notify($"Confirm robot {blade} wafer");
  666. //IoSensor sensorBlade = blade == Hand.Blade1
  667. // ? DeviceModel.SensorRobotFork1WaferOn
  668. // : DeviceModel.SensorRobotFork2WaferOn;
  669. var iswaferpersence = blade == Hand.Blade1 ? robot.IsWaferPresenceOnBlade1 : robot.IsWaferPresenceOnBlade2;
  670. int slot = blade == Hand.Blade1 ? 0 : 1;
  671. if (iswaferpersence)
  672. {
  673. if (WaferManager.Instance.CheckNoWafer(ModuleName.Robot, slot))
  674. {
  675. EV.PostWarningLog(Module, $"Found wafer at robot {blade}");
  676. WaferManager.Instance.CreateWafer(ModuleName.Robot, slot, WaferStatus.Normal);
  677. }
  678. }
  679. else
  680. {
  681. if (WaferManager.Instance.CheckHasWafer(ModuleName.Robot, slot))
  682. {
  683. EV.PostWarningLog(Module, $"Not found wafer at robot {blade}, please manually confirm again.");
  684. WaferManager.Instance.DeleteWafer(ModuleName.Robot, slot);
  685. }
  686. }
  687. return true;
  688. });
  689. }
  690. public void CoolBufferMoveDown(int id, IoCoolingBuffer device, WaferSize size, int time, Action<string> notify, Action<string> error)
  691. {
  692. Tuple<bool, Result> ret = Execute(id, () =>
  693. {
  694. notify($"Start {device.Name} Move Down");
  695. if (device.CheckPinDown()) return true;
  696. if (!device.Move(size, false, out string reason))
  697. {
  698. Stop(reason);
  699. return false;
  700. }
  701. return true;
  702. });
  703. if (ret.Item1)
  704. {
  705. if (ret.Item2 == Result.FAIL)
  706. {
  707. throw (new RoutineFaildException());
  708. }
  709. }
  710. }
  711. public void WaitCoolBufferMoveUp(int id, IoCoolingBuffer device, string name, int time, Action<string> notify,
  712. Action<string> error)
  713. {
  714. var ret = ExecuteAndWait(id, () =>
  715. {
  716. notify(name);
  717. return true;
  718. }, () =>
  719. {
  720. if (device.Error)
  721. {
  722. Stop("Can not move up, device error");
  723. return null;
  724. }
  725. return device.CheckMovedUp() && !device.Busy ;
  726. }, time * 1000);
  727. if (ret.Item1)
  728. {
  729. if (ret.Item2 == Result.FAIL)
  730. throw new RoutineFaildException();
  731. if (ret.Item2 == Result.TIMEOUT) //timeout
  732. {
  733. error($"{name} timeout, than {time} seconds");
  734. throw new RoutineFaildException();
  735. }
  736. bool isMovedUp = device.CheckMovedUp() && !device.Busy && !device.Error;
  737. if (!isMovedUp)
  738. {
  739. throw new RoutineBreakException();
  740. }
  741. }
  742. }
  743. public void WaitCoolBufferMoveDown(int id, IoCoolingBuffer device, string name, int time, Action<string> notify,
  744. Action<string> error)
  745. {
  746. var ret = ExecuteAndWait(id, () =>
  747. {
  748. notify(name);
  749. _timerQuery.Start(_queryPeriod); //开始查询
  750. return true;
  751. }, () =>
  752. {
  753. if (device.Error)
  754. {
  755. Stop("Can not move down, device error");
  756. return null;
  757. }
  758. return device.CheckMovedDown() && !device.Busy;
  759. }, time * 1000);
  760. if (ret.Item1)
  761. {
  762. if (ret.Item2 == Result.FAIL) throw new RoutineFaildException();
  763. if (ret.Item2 == Result.TIMEOUT) //timeout
  764. {
  765. error($"{name} timeout, than {time} seconds");
  766. throw new RoutineFaildException();
  767. }
  768. bool isMovedDown = device.CheckMovedDown() && !device.Busy && !device.Error;
  769. if (!isMovedDown)
  770. {
  771. throw new RoutineBreakException();
  772. }
  773. }
  774. }
  775. public void SetWaferSize(int id, string name, int cmd, ModuleName station, int slot, int time, Action<string> notify, Action<string> error)
  776. {
  777. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  778. {
  779. WaferSize size = WaferSize.WS0;
  780. if (ModuleHelper.IsLoadPort(station))
  781. {
  782. }
  783. else
  784. {
  785. size = WaferManager.Instance.GetWaferSize(station, slot);
  786. }
  787. notify(String.Format($"Set WaferSize parameter {cmd} {size.ToString()}"));
  788. string reason = string.Empty;
  789. //robot.SetWaferSize(cmd, size, out reason);
  790. return true;
  791. }, () =>
  792. {
  793. if (robot.RobotState == RobotStateEnum.Idle)
  794. {
  795. return true;
  796. }
  797. return false;
  798. }, time * 1000);
  799. if (ret.Item1)
  800. {
  801. if (ret.Item2 == Result.FAIL)
  802. {
  803. throw (new RoutineFaildException());
  804. }
  805. else if (ret.Item2 == Result.TIMEOUT) //timeout
  806. {
  807. error(String.Format("Set WaferSize timeout, than {0} seconds", time));
  808. throw (new RoutineFaildException());
  809. }
  810. else
  811. throw (new RoutineBreakException());
  812. }
  813. }
  814. /// <summary>
  815. /// 目前只比对0114 parameter
  816. /// </summary>
  817. /// <param name="id"></param>
  818. /// <param name="name"></param>
  819. /// <param name="parameterNo"></param>
  820. /// <param name="parameterType"></param>
  821. /// <param name="waferSize"></param>
  822. /// <param name="time"></param>
  823. /// <param name="notify"></param>
  824. /// <param name="error"></param>
  825. /// <exception cref="RoutineFaildException"></exception>
  826. /// <exception cref="RoutineBreakException"></exception>
  827. protected void RobotGoto(int id, string name, ModuleName chamber, int slot, Hand blade, RobotPostionEnum postype,
  828. Action<string> notify, Action<string> error)
  829. {
  830. var reason = string.Empty;
  831. var ret = Execute(id, () =>
  832. {
  833. notify(string.Format("pick from {0}", chamber.ToString()));
  834. var obj = new object[] { (RobotArmEnum)(int)blade, chamber.ToString(), slot, postype };
  835. return robot.GoTo(obj);// (RobotArmEnum)(int)blade, chamber.ToString(), slot);
  836. });
  837. if (ret.Item1)
  838. if (ret.Item2 == Result.FAIL)
  839. {
  840. error(reason);
  841. throw new RoutineFaildException();
  842. }
  843. }
  844. protected void CheckTriggerSignalOn(int id,string name,ModuleName module,int time)
  845. {
  846. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  847. {
  848. Notify(String.Format("Check Trigger Signal"));
  849. string reason = string.Empty;
  850. return true;
  851. }, () =>
  852. {
  853. if (SC.GetValue<bool>("System.IsSimulatorMode")) return true;
  854. if (module.Equals(ModuleName.LL1))
  855. {
  856. if (DeviceModel.SensorPMASystemInterlock.Value && DeviceModel.TrigSafetytoPMA.Value)
  857. {
  858. return true;
  859. }
  860. }
  861. if (module.Equals(ModuleName.LL2))
  862. {
  863. if (DeviceModel.SensorPMBSystemInterlock.Value && DeviceModel.TrigSafetytoPMB.Value)
  864. {
  865. return true;
  866. }
  867. }
  868. return false;
  869. }, time * 1000);
  870. if (ret.Item1)
  871. {
  872. if (ret.Item2 == Result.FAIL)
  873. {
  874. throw (new RoutineFaildException());
  875. }
  876. else if (ret.Item2 == Result.TIMEOUT) //timeout
  877. {
  878. Stop(String.Format("Trigger Signal Change timeout, than {0} seconds", time));
  879. throw (new RoutineFaildException());
  880. }
  881. else
  882. throw (new RoutineBreakException());
  883. }
  884. }
  885. protected void PickWafer(int id, string name, ModuleName chamber, int slot, Hand blade, int x, int y, int z,
  886. Action<string> notify, Action<string> error)
  887. {
  888. var reason = string.Empty;
  889. var ret = Execute(id, () =>
  890. {
  891. notify(string.Format("pick from {0}", chamber.ToString()));
  892. if (x == 0 && y == 0 && z == 0)
  893. return robot.Pick((RobotArmEnum)(int)blade,chamber.ToString(), slot);
  894. return robot.PickEx((RobotArmEnum)(int)blade, chamber.ToString(), slot, x, y, z);
  895. });
  896. if (ret.Item1)
  897. if (ret.Item2 == Result.FAIL)
  898. {
  899. error(reason);
  900. throw new RoutineFaildException();
  901. }
  902. }
  903. protected void PlaceWafer(int id, string name, ModuleName chamber, int slot, Hand blade, int x, int y, int z,
  904. Action<string> notify, Action<string> error)
  905. {
  906. var ret = Execute(id, () =>
  907. {
  908. notify(string.Format("Place wafer to {0}", chamber.ToString()));
  909. var reason = string.Empty;
  910. if (x == 0 && y == 0 && z == 0)
  911. return robot.Place((RobotArmEnum)(int)blade, chamber.ToString(), slot);
  912. return robot.PlaceEx((RobotArmEnum)(int)blade, chamber.ToString(), slot, x, y, z);
  913. });
  914. if (ret.Item1)
  915. if (ret.Item2 == Result.FAIL)
  916. throw new RoutineFaildException();
  917. }
  918. #endregion
  919. protected bool CheckRobotMotionInterlock(ModuleName chamber, int slot, out string reason) //Pick/Place/Swap
  920. {
  921. reason = string.Empty;
  922. if (robot.RobotState == RobotStateEnum.Error)
  923. {
  924. reason = "robot is error.";
  925. return false;
  926. }
  927. //if (!robot.IsIdle)
  928. //{
  929. // reason = string.Format("robot is moving.");
  930. // return false;
  931. //}
  932. if (!CheckRobotReady())
  933. {
  934. reason = string.Format("robot isn't Ready.");
  935. return false;
  936. }
  937. if (chamber == ModuleName.Aligner)
  938. {
  939. if (aligner.Moving)
  940. {
  941. reason = string.Format("aligner is moving.");
  942. return false;
  943. }
  944. if (!CheckAlignerReady())
  945. {
  946. reason = string.Format("aligner isn't Ready.");
  947. return false;
  948. }
  949. /*
  950. if (aligner.Busy)
  951. {
  952. reason = string.Format("{0} is busy.", chamber.ToString());
  953. return false;
  954. }
  955. */
  956. return true;
  957. }
  958. else if (ModuleHelper.IsLoadPort(chamber))
  959. {
  960. LoadPortBaseDevice loadport = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
  961. if (!loadport.IsEnableTransferWafer(out _))
  962. {
  963. reason = string.Format("{0} isn't Ready.", chamber.ToString());
  964. return false;
  965. }
  966. if (loadport.MapError)
  967. {
  968. reason = string.Format("{0} Map has crossed error.", chamber.ToString());
  969. return false;
  970. }
  971. if (chamber.Equals(ModuleName.LP1))
  972. {
  973. if (SC.GetValue<int>($"LoadPort.LP1.CstType") == 0)
  974. {
  975. if (!DeviceModel.SensorSMIF1PODOPEN.Value)
  976. {
  977. reason = string.Format("{0} SMIF1PODOPEN signal is Off.", chamber.ToString());
  978. return false;
  979. }
  980. if (!DeviceModel.SensorSMIF1PODPRESENT.Value)
  981. {
  982. reason = string.Format("{0} SensorSMIF1PODPRESENT signal is Off,Foup is presence.", chamber.ToString());
  983. return false;
  984. }
  985. if (!DeviceModel.SensorSMIF1READY.Value)
  986. {
  987. reason = string.Format("{0} SensorSMIF1READY signal is Off.", chamber.ToString());
  988. return false;
  989. }
  990. }
  991. else if (SC.GetValue<int>($"LoadPort.LP1.CstType") == 1)
  992. {
  993. if(loadport.CassetteState!=LoadportCassetteState.Normal)// (DeviceModel.Sensor4InchCstPresence.Value&& DeviceModel.Sensor6InchCstPresence.Value&& DeviceModel.Sensor8InchCstPresence.Value)
  994. {
  995. reason = string.Format("{0} Cst Presence signal is Off,Foup is not presence.", chamber.ToString());
  996. return false;
  997. }
  998. }
  999. else if (SC.GetValue<int>($"LoadPort.LP1.CstType") == 2)
  1000. {
  1001. if (!DeviceModel.SensorLP1FoupOpen.Value)
  1002. {
  1003. reason = string.Format("{0} SensorLP1FoupOpen signal is Off. Foup is not open.", chamber.ToString());
  1004. return false;
  1005. }
  1006. if (!DeviceModel.SensorLP1FoupPlacement.Value)
  1007. {
  1008. reason = string.Format("{0} SensorLP1FoupPlacement signal is Off. Foup is not placed.", chamber.ToString());
  1009. return false;
  1010. }
  1011. if (!DeviceModel.SensorLP1OperationStatus.Value)
  1012. {
  1013. reason = string.Format("{0} SensorLP1OperationStatus signal is Off. Foup is not in operation status.", chamber.ToString());
  1014. return false;
  1015. }
  1016. if (!DeviceModel.SensorLP1Ready.Value)
  1017. {
  1018. reason = string.Format("{0} SensorLP1Ready signal is Off. Foup is not ready.", chamber.ToString());
  1019. return false;
  1020. }
  1021. if (!DeviceModel.SensorLP1Presence.Value)
  1022. {
  1023. reason = string.Format("{0} SensorLP1Presence signal is Off. Foup is not present.", chamber.ToString());
  1024. return false;
  1025. }
  1026. }
  1027. if (slot + 1 > loadport.ValidSlotsNumber)
  1028. {
  1029. reason = string.Format("{0} ValidSlotsNumber less than {1}.", chamber.ToString(), slot + 1);
  1030. return false;
  1031. }
  1032. }
  1033. else if (chamber.Equals(ModuleName.LP2))
  1034. {
  1035. if (SC.GetValue<int>($"LoadPort.LP2.CstType") == 0)
  1036. {
  1037. if (!DeviceModel.SensorSMIF2PODOPEN.Value)
  1038. {
  1039. reason = string.Format("{0} SMIF2PODOPEN signal is Off.", chamber.ToString());
  1040. return false;
  1041. }
  1042. if (!DeviceModel.SensorSMIF2PODPRESENT.Value)
  1043. {
  1044. reason = string.Format("{0} SensorSMIF2PODPRESENT signal is Off,Foup is not presence .", chamber.ToString());
  1045. return false;
  1046. }
  1047. if (!DeviceModel.SensorSMIF2READY.Value)
  1048. {
  1049. reason = string.Format("{0} SensorSMIF2READY signal is Off.", chamber.ToString());
  1050. return false;
  1051. }
  1052. }
  1053. else if (SC.GetValue<int>($"LoadPort.LP2.CstType") == 1)
  1054. {
  1055. if (loadport.CassetteState != LoadportCassetteState.Normal)// (DeviceModel.Sensor4InchCstPresence.Value&& DeviceModel.Sensor6InchCstPresence.Value&& DeviceModel.Sensor8InchCstPresence.Value)
  1056. {
  1057. reason = string.Format("{0} Cst Presence signal is Off,Foup is not presence.", chamber.ToString());
  1058. return false;
  1059. }
  1060. }
  1061. else if (SC.GetValue<int>($"LoadPort.LP2.CstType") == 2)
  1062. {
  1063. if (!DeviceModel.SensorLP2FoupOpen.Value)
  1064. {
  1065. reason = string.Format("{0} SensorLP2FoupOpen signal is Off. Foup is not open.", chamber.ToString());
  1066. return false;
  1067. }
  1068. if (!DeviceModel.SensorLP2FoupPlacement.Value)
  1069. {
  1070. reason = string.Format("{0} SensorLP2FoupPlacement signal is Off. Foup is not placed.", chamber.ToString());
  1071. return false;
  1072. }
  1073. if (!DeviceModel.SensorLP2OperationStatus.Value)
  1074. {
  1075. reason = string.Format("{0} SensorLP2OperationStatus signal is Off. Foup is not in operation status.", chamber.ToString());
  1076. return false;
  1077. }
  1078. if (!DeviceModel.SensorLP2Ready.Value)
  1079. {
  1080. reason = string.Format("{0} SensorLP2Ready signal is Off. Foup is not ready.", chamber.ToString());
  1081. return false;
  1082. }
  1083. if (!DeviceModel.SensorLP2Presence.Value)
  1084. {
  1085. reason = string.Format("{0} SensorLP2Presence signal is Off. Foup is not present.", chamber.ToString());
  1086. return false;
  1087. }
  1088. }
  1089. if (slot + 1 > loadport.ValidSlotsNumber)
  1090. {
  1091. reason = string.Format("{0} ValidSlotsNumber less than {1}.", chamber.ToString(), slot + 1);
  1092. return false;
  1093. }
  1094. }
  1095. return true;
  1096. }
  1097. if (ModuleHelper.IsLoadLock(chamber))
  1098. {
  1099. var ll = DEVICE.GetDevice<LoadLockDevice>(chamber.ToString());
  1100. if (ll != null && !ll.IsEnableTransferWafer(out reason))
  1101. return false;
  1102. return true;
  1103. }
  1104. if (ModuleHelper.IsBuffer(chamber))
  1105. {
  1106. var bufferStation = DEVICE.GetDevice<BufferStation>(chamber.ToString());
  1107. if (bufferStation !=null && !bufferStation.IsEnableTransferWafer(out reason))
  1108. return false;
  1109. return true;
  1110. }
  1111. if (ModuleHelper.IsCoolingBuffer(chamber)|| ModuleHelper.IsAligner(chamber))
  1112. {
  1113. IoCoolingBuffer buffer = DEVICE.GetDevice<IoCoolingBuffer>(chamber.ToString());
  1114. if(buffer != null)
  1115. {
  1116. if (buffer.Busy)
  1117. {
  1118. reason = "buffer is not idle";
  1119. return false;
  1120. }
  1121. if (!buffer.CheckPinUp())
  1122. {
  1123. reason = "buffer pin not up position";
  1124. return false;
  1125. }
  1126. }
  1127. return true;
  1128. }
  1129. if (ModuleHelper.IsFlipper(chamber))
  1130. {
  1131. if(flipper != null && flipper.IsEnableTransferWafer(out reason))
  1132. {
  1133. return true;
  1134. }
  1135. return false;
  1136. }
  1137. reason = "error target";
  1138. return false;
  1139. }
  1140. protected bool CheckRobotReady()
  1141. {
  1142. return robot.IsReady();
  1143. }
  1144. protected bool CheckRobotMotionInterlock(out string reason)
  1145. {
  1146. reason = string.Empty;
  1147. if (robot.RobotState != RobotStateEnum.Idle )
  1148. {
  1149. reason = string.Format("robot is not idle.");
  1150. return false;
  1151. }
  1152. if (!CheckRobotReadySensor())
  1153. {
  1154. reason = string.Format("robot isn't ready.");
  1155. return false;
  1156. }
  1157. return true;
  1158. }
  1159. public void QueryLoadportState(int id, LoadPort device)
  1160. {
  1161. Tuple<bool, Result> ret = Execute(id, () =>
  1162. {
  1163. Notify(String.Format("Query {0} state", device.Name));
  1164. return device.IsIdle;
  1165. });
  1166. if (ret.Item1)
  1167. {
  1168. if (ret.Item2 == Result.FAIL)
  1169. {
  1170. Stop("not idle");
  1171. throw (new RoutineFaildException());
  1172. }
  1173. else
  1174. throw (new RoutineBreakException());
  1175. }
  1176. }
  1177. public void QueryAlignerState(int id, Aligner device)
  1178. {
  1179. Tuple<bool, Result> ret = Execute(id, () =>
  1180. {
  1181. Notify(String.Format("Query {0} state", device.Name));
  1182. return device.State == DeviceState.Idle;
  1183. });
  1184. if (ret.Item1)
  1185. {
  1186. if (ret.Item2 == Result.FAIL)
  1187. {
  1188. Stop("not idle");
  1189. throw (new RoutineFaildException());
  1190. }
  1191. else
  1192. throw (new RoutineBreakException());
  1193. }
  1194. }
  1195. public void QueryCoolBufferState(int id, IoCoolingBuffer device)
  1196. {
  1197. var ret = Execute(id, () =>
  1198. {
  1199. Notify(string.Format("Query {0} state", device.Name));
  1200. return true;
  1201. });
  1202. if (ret.Item1)
  1203. {
  1204. if (ret.Item2 == Result.FAIL)
  1205. {
  1206. Stop("Station wafer status error");
  1207. throw new RoutineFaildException();
  1208. }
  1209. throw new RoutineBreakException();
  1210. }
  1211. }
  1212. public IoCoolingBuffer GetCoolBuffer(ModuleName coolbufferName)
  1213. {
  1214. switch (coolbufferName)
  1215. {
  1216. case ModuleName.CoolingBuffer1:
  1217. _ioCoolBuffer = buffer1;
  1218. break;
  1219. case ModuleName.CoolingBuffer2:
  1220. _ioCoolBuffer = buffer2;
  1221. break;
  1222. case ModuleName.Aligner1:
  1223. _ioCoolBuffer = aligner1;
  1224. break;
  1225. case ModuleName.Aligner2:
  1226. _ioCoolBuffer = aligner2;
  1227. break;
  1228. }
  1229. return _ioCoolBuffer;
  1230. }
  1231. public JetFlipper GetFlipper()
  1232. {
  1233. return flipper;
  1234. }
  1235. public void QueryLoadportState(int id, string deviceName, int time)
  1236. {
  1237. LoadPortBaseDevice device = DEVICE.GetDevice<LoadPortBaseDevice>(deviceName);
  1238. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1239. {
  1240. Notify(String.Format("{0} query state", deviceName));
  1241. string reason = string.Empty;
  1242. device.QueryState(out reason);
  1243. return true;
  1244. }, () =>
  1245. {
  1246. if (device.IsReady())
  1247. {
  1248. return true;
  1249. }
  1250. return false;
  1251. }, time * 1000);
  1252. if (ret.Item1)
  1253. {
  1254. if (ret.Item2 == Result.FAIL)
  1255. {
  1256. throw (new RoutineFaildException());
  1257. }
  1258. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1259. {
  1260. Stop(String.Format("{0} query timeout, than {1} seconds", device.Name, time));
  1261. throw (new RoutineFaildException());
  1262. }
  1263. else
  1264. throw (new RoutineBreakException());
  1265. }
  1266. }
  1267. public void IsLoadLockReadyToTransfer(string deviceName)
  1268. {
  1269. var device = DEVICE.GetDevice<LoadLockDevice>(deviceName);
  1270. if (!device.IsEnableTransferWafer(out var reason))
  1271. {
  1272. EV.PostMessage(deviceName, EventEnum.DefaultWarning, reason);
  1273. throw new RoutineBreakException();
  1274. }
  1275. }
  1276. public void LoadLockOpenAtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
  1277. {
  1278. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1279. {
  1280. notify(name);
  1281. _timerQuery.Start(_queryPeriod); //开始查询
  1282. return LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Opened || LoadLockDevice.OpenAtmDoor(out string reason);
  1283. }, () =>
  1284. {
  1285. if (LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Opened)
  1286. return true;
  1287. return false;
  1288. }, time * 1000);
  1289. if (ret.Item1)
  1290. {
  1291. if (ret.Item2 == Result.FAIL)
  1292. {
  1293. throw (new RoutineFaildException());
  1294. }
  1295. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1296. {
  1297. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1298. throw (new RoutineFaildException());
  1299. }
  1300. else
  1301. throw (new RoutineBreakException());
  1302. }
  1303. }
  1304. public void LoadLockCloseAtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
  1305. {
  1306. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1307. {
  1308. notify(name);
  1309. return LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Closed || LoadLockDevice.CloseAtmDoor(out string reason);
  1310. }, () =>
  1311. {
  1312. if (LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Closed)
  1313. return true;
  1314. return false;
  1315. }, time * 1000);
  1316. if (ret.Item1)
  1317. {
  1318. if (ret.Item2 == Result.FAIL)
  1319. {
  1320. throw (new RoutineFaildException());
  1321. }
  1322. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1323. {
  1324. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1325. throw (new RoutineFaildException());
  1326. }
  1327. else
  1328. throw (new RoutineBreakException());
  1329. }
  1330. }
  1331. public void LoadLockOpenVtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
  1332. {
  1333. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1334. {
  1335. notify(name);
  1336. _timerQuery.Start(_queryPeriod); //开始查询
  1337. return LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Opened || LoadLockDevice.OpenVtmDoor(out string reason);
  1338. }, () =>
  1339. {
  1340. if (LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Opened)
  1341. return true;
  1342. return false;
  1343. }, time * 1000);
  1344. if (ret.Item1)
  1345. {
  1346. if (ret.Item2 == Result.FAIL)
  1347. {
  1348. throw (new RoutineFaildException());
  1349. }
  1350. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1351. {
  1352. error($"{name} timeout, than {time} seconds");
  1353. throw (new RoutineFaildException());
  1354. }
  1355. else
  1356. throw (new RoutineBreakException());
  1357. }
  1358. }
  1359. public void LoadLockCloseVtmDoor(int id, LoadLockDevice device, string name, int time, Action<string> notify, Action<string> error)
  1360. {
  1361. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1362. {
  1363. notify(name);
  1364. return LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Closed || LoadLockDevice.CloseVtmDoor(out string reason);
  1365. }, () =>
  1366. {
  1367. if (LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Closed)
  1368. return true;
  1369. return false;
  1370. }, time * 1000);
  1371. if (ret.Item1)
  1372. {
  1373. if (ret.Item2 == Result.FAIL)
  1374. {
  1375. throw (new RoutineFaildException());
  1376. }
  1377. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1378. {
  1379. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1380. throw (new RoutineFaildException());
  1381. }
  1382. else
  1383. throw (new RoutineBreakException());
  1384. }
  1385. }
  1386. protected void Default()
  1387. {
  1388. string reason = String.Empty;
  1389. }
  1390. protected virtual void Warning(string message)
  1391. {
  1392. EV.PostMessage(Module, EventEnum.DefaultWarning, message);
  1393. }
  1394. ///等待 Aligner Motion
  1395. public void WaitAlignerMotion(int id, Aligner device, string name, int time, Action<string> notify, Action<string> error)
  1396. {
  1397. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1398. {
  1399. notify(name);
  1400. _timerQuery.Start(_queryPeriod); //开始查询
  1401. return true;
  1402. }, () =>
  1403. {
  1404. // if (device.Moving == false && CheckAlignerReady())
  1405. if (device.Busy == false && CheckAlignerReady())
  1406. {
  1407. _timerQuery.Stop();
  1408. return true;
  1409. }
  1410. if (query())
  1411. {
  1412. // string reason = string.Empty;
  1413. // device.QueryState(out reason); //查询位置
  1414. }
  1415. return false;
  1416. }, time * 1000);
  1417. if (ret.Item1)
  1418. {
  1419. if (ret.Item2 == Result.FAIL)
  1420. {
  1421. throw (new RoutineFaildException());
  1422. }
  1423. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1424. {
  1425. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1426. throw (new RoutineFaildException());
  1427. }
  1428. else
  1429. throw (new RoutineBreakException());
  1430. }
  1431. }
  1432. protected virtual void Notify(string message)
  1433. {
  1434. EV.PostInfoLog(Module, $"{Name}, {message}");
  1435. }
  1436. protected virtual void Stop(string failReason)
  1437. {
  1438. EV.PostAlarmLog(Module, $"{Name}, {failReason}");
  1439. }
  1440. public void Abort()
  1441. {
  1442. }
  1443. private bool query()
  1444. {
  1445. if (_timerQuery.IsTimeout())
  1446. {
  1447. _timerQuery.Start(_queryPeriod);
  1448. return true;
  1449. }
  1450. return false;
  1451. }
  1452. protected bool CheckSeneorHasWafer(ModuleName chamber, int slot)
  1453. {
  1454. if (!SC.GetValue<bool>(SorterCommon.ScPathName.System_IsSimulatorMode))
  1455. {
  1456. if (chamber == ModuleName.Robot)
  1457. {
  1458. if (slot == 0)
  1459. return robot.IsWaferPresenceOnBlade1;//!DeviceModel.SensorRBlowerArmhavewafer.Value;
  1460. return robot.IsWaferPresenceOnBlade2;
  1461. }
  1462. //if (chamber == ModuleName.Aligner)
  1463. //{
  1464. // return !DeviceModel.SensorPreAlignerWaferOn.Value;
  1465. //}
  1466. }
  1467. return WaferManager.Instance.CheckHasWafer(chamber, slot);
  1468. }
  1469. protected bool CheckSensorNoWafer(ModuleName chamber, int slot)
  1470. {
  1471. if (!SC.GetValue<bool>(SorterCommon.ScPathName.System_IsSimulatorMode))
  1472. {
  1473. if (chamber == ModuleName.Robot)
  1474. {
  1475. if (slot == 0)
  1476. return !robot.IsWaferPresenceOnBlade1; //DeviceModel.SensorRBlowerArmhavewafer.Value;
  1477. return !robot.IsWaferPresenceOnBlade2; //DeviceModel.SensorRBupperArmhavewafer.Value;
  1478. }
  1479. //if (chamber == ModuleName.Aligner)
  1480. //{
  1481. // return DeviceModel.SensorPreAlignerWaferOn.Value;
  1482. //}
  1483. }
  1484. return WaferManager.Instance.CheckNoWafer(chamber, slot);
  1485. }
  1486. protected bool CheckRobotReadySensor()
  1487. {
  1488. return (robot.RobotState == RobotStateEnum.Idle);
  1489. }
  1490. protected bool CheckAlignerReady()
  1491. {
  1492. return true;
  1493. }
  1494. ///等待 Loadport
  1495. public void LoadportReset(int id, LoadPortBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
  1496. {
  1497. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1498. {
  1499. notify(String.Format("{0} clear error", device.Name));
  1500. string reason = string.Empty;
  1501. return device.LoadportReset(out reason);
  1502. }, () =>
  1503. {
  1504. if (device.IsReady())
  1505. {
  1506. return true;
  1507. }
  1508. return false;
  1509. }, time * 1000);
  1510. if (ret.Item1)
  1511. {
  1512. if (ret.Item2 == Result.FAIL)
  1513. {
  1514. throw (new RoutineFaildException());
  1515. }
  1516. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1517. {
  1518. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1519. throw (new RoutineFaildException());
  1520. }
  1521. else
  1522. throw (new RoutineBreakException());
  1523. }
  1524. }
  1525. public void LoadportInit(int id, LoadPortBaseDevice device, string name, Action<string> notify, Action<string> error)
  1526. {
  1527. Tuple<bool, Result> ret = Execute(id, () =>
  1528. {
  1529. notify(String.Format("{0} Home", device.Name));
  1530. string reason = string.Empty;
  1531. return device.Home(out reason);
  1532. });
  1533. if (ret.Item1)
  1534. {
  1535. if (ret.Item2 == Result.FAIL)
  1536. {
  1537. throw (new RoutineFaildException());
  1538. }
  1539. }
  1540. }
  1541. protected bool CheckLoadportMotionInterlock(ModuleName chamber, out string reason)
  1542. {
  1543. reason = string.Empty;
  1544. if (robot.RobotState != RobotStateEnum.Idle)
  1545. {
  1546. reason = string.Format("robot is not idle.");
  1547. return false;
  1548. }
  1549. if (!CheckRobotReady())
  1550. {
  1551. reason = string.Format("robot isn't ready.");
  1552. return false;
  1553. }
  1554. return true;
  1555. }
  1556. ///等待 Loadport
  1557. public void WaitLoadportMotion(int id, LoadPortBaseDevice device, string name, int time, Action<string> notify, Action<string> error)
  1558. {
  1559. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1560. {
  1561. notify(name);
  1562. string msg = string.Empty;
  1563. //device.QueryState(out msg); //查询状
  1564. _timerQuery.Start(_queryPeriod); //开始查询
  1565. return true;
  1566. }, () =>
  1567. {
  1568. if (device.CurrentState == LoadPortStateEnum.Error)
  1569. {
  1570. return null;
  1571. }
  1572. if (device.IsReady())
  1573. {
  1574. _timerQuery.Stop();
  1575. return true;
  1576. }
  1577. return false;
  1578. }, time * 1000);
  1579. if (ret.Item1)
  1580. {
  1581. if (ret.Item2 == Result.FAIL)
  1582. {
  1583. throw (new RoutineFaildException());
  1584. }
  1585. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1586. {
  1587. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1588. throw (new RoutineFaildException());
  1589. }
  1590. else
  1591. throw (new RoutineBreakException());
  1592. }
  1593. }
  1594. protected void LoadportAllReset(int id, int time)
  1595. {
  1596. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1597. {
  1598. Notify(String.Format("clear error for all loadports"));
  1599. string reason = string.Empty;
  1600. LPs.ForEach(lp => lp.ClearError(out reason));
  1601. return true;
  1602. }, () =>
  1603. {
  1604. if (LPs.Any(lp => lp.IsBusy))
  1605. {
  1606. return false;
  1607. }
  1608. return true;
  1609. }, time * 1000);
  1610. if (ret.Item1)
  1611. {
  1612. if (ret.Item2 == Result.FAIL)
  1613. {
  1614. throw (new RoutineFaildException());
  1615. }
  1616. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1617. {
  1618. Stop(String.Format("LoadportAllReset timeout, than {0} seconds", time));
  1619. throw (new RoutineFaildException());
  1620. }
  1621. else
  1622. throw (new RoutineBreakException());
  1623. }
  1624. }
  1625. protected void LoadportAllInit(int id, int time)
  1626. {
  1627. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1628. {
  1629. Notify(String.Format("All loadports Homing"));
  1630. string reason = string.Empty;
  1631. LPs.ForEach(lp =>lp.Home(out reason));
  1632. _timerQuery.Start(_queryPeriod); //开始查询
  1633. return true;
  1634. }, () =>
  1635. {
  1636. if (LPs.Any(lp => lp.CurrentState == LoadPortStateEnum.Error))
  1637. {
  1638. return null;
  1639. }
  1640. if (LPs.Any(lp => !lp.IsHomed)) //!lp.IsReady() &&
  1641. {
  1642. return false;
  1643. }
  1644. LPs.ForEach(m=>LOG.Write($"{m.Name}:{m.IsHomed }"));
  1645. return true;
  1646. }, time * 1000);
  1647. if (ret.Item1)
  1648. {
  1649. if (ret.Item2 == Result.FAIL)
  1650. {
  1651. throw (new RoutineFaildException());
  1652. }
  1653. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1654. {
  1655. Stop(String.Format("LoadportAllInit timeout, than {0} seconds", time));
  1656. throw (new RoutineFaildException());
  1657. }
  1658. else
  1659. throw (new RoutineBreakException());
  1660. }
  1661. }
  1662. protected void PostMessage(int id, string v)
  1663. {
  1664. Tuple<bool, Result> ret = Execute(id, () =>
  1665. {
  1666. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, v);
  1667. return true;
  1668. });
  1669. if (ret.Item1)
  1670. {
  1671. if (ret.Item2 == Result.FAIL)
  1672. {
  1673. throw (new RoutineFaildException());
  1674. }
  1675. }
  1676. }
  1677. public void TimeDelay(int id, int timeMs)
  1678. {
  1679. Tuple<bool, Result> ret = Delay(id, () =>
  1680. {
  1681. Notify($"Delay {timeMs} Milliseconds");
  1682. return true;
  1683. }, timeMs);
  1684. if (ret.Item1)
  1685. {
  1686. if (ret.Item2 == Result.RUN)
  1687. {
  1688. throw (new RoutineBreakException());
  1689. }
  1690. }
  1691. }
  1692. /// <summary>
  1693. /// Fliper Reset
  1694. /// </summary>
  1695. /// <param name="id"></param>
  1696. /// <param name="device"></param>
  1697. /// <param name="name"></param>
  1698. /// <param name="time"></param>
  1699. /// <param name="notify"></param>
  1700. /// <param name="error"></param>
  1701. public void FlipperReset(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
  1702. {
  1703. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1704. {
  1705. notify(String.Format("{0} Clear Error", device.Name));
  1706. string reason = string.Empty;
  1707. device.Reset();
  1708. return true;
  1709. }, () =>
  1710. {
  1711. if (device.IsBusy || device.State != FlipperState.Idle)
  1712. {
  1713. //忙状态
  1714. //_flipper.ShowAction();
  1715. LOG.Info($"{device.Name} is busy state");
  1716. return false;
  1717. }
  1718. else
  1719. {
  1720. //空闲状态
  1721. LOG.Info($"{device.Name} enters idle state");
  1722. return true;
  1723. }
  1724. }, time * 1000);
  1725. if (ret.Item1)
  1726. {
  1727. if (ret.Item2 == Result.FAIL)
  1728. {
  1729. throw (new RoutineFaildException());
  1730. }
  1731. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1732. {
  1733. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1734. throw (new RoutineFaildException());
  1735. }
  1736. else
  1737. throw (new RoutineBreakException());
  1738. }
  1739. }
  1740. /// <summary>
  1741. /// Flipper Clamp Open
  1742. /// </summary>
  1743. /// <param name="id"></param>
  1744. /// <param name="device"></param>
  1745. /// <param name="name"></param>
  1746. /// <param name="time"></param>
  1747. /// <param name="notify"></param>
  1748. /// <param name="error"></param>
  1749. public void FlipperClampOpen(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
  1750. {
  1751. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1752. {
  1753. notify(String.Format("{0} clamp open", device.Name));
  1754. //有错误 驱动层已打出原因log
  1755. if (device.Clamp(false))
  1756. {
  1757. LOG.Info($"{device.Name} starts unclamp");
  1758. return true;
  1759. }
  1760. else
  1761. {
  1762. LOG.Error($"{device.Name} unclamps failed");
  1763. return false;
  1764. }
  1765. }, () =>
  1766. {
  1767. if (device.IsBusy && device.IsClampOpen)
  1768. {
  1769. //忙状态
  1770. //_flipper.ShowAction();
  1771. LOG.Info($"{device.Name} is busy state");
  1772. return false;
  1773. }
  1774. else
  1775. {
  1776. //空闲状态
  1777. LOG.Info($"{device.Name} enter idle state");
  1778. return true;
  1779. }
  1780. }, time * 1000);
  1781. if (ret.Item1)
  1782. {
  1783. if (ret.Item2 == Result.FAIL)
  1784. {
  1785. throw (new RoutineFaildException());
  1786. }
  1787. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1788. {
  1789. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1790. throw (new RoutineFaildException());
  1791. }
  1792. else
  1793. throw (new RoutineBreakException());
  1794. }
  1795. }
  1796. /// <summary>
  1797. /// Flipper Clamp Close
  1798. /// </summary>
  1799. /// <param name="id"></param>
  1800. /// <param name="device"></param>
  1801. /// <param name="name"></param>
  1802. /// <param name="time"></param>
  1803. /// <param name="notify"></param>
  1804. /// <param name="error"></param>
  1805. public void FlipperClampClose(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
  1806. {
  1807. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1808. {
  1809. notify(String.Format("{0} Clamp Close", device.Name));
  1810. //有错误 驱动层已打出原因log
  1811. if (device.Clamp(true))
  1812. {
  1813. LOG.Info($"{device.Name} starts clamp");
  1814. return true;
  1815. }
  1816. else
  1817. {
  1818. LOG.Error($"{device.Name} clamps failed");
  1819. return false;
  1820. }
  1821. }, () =>
  1822. {
  1823. if (device.IsBusy && device.IsClampClose)
  1824. {
  1825. //忙状态
  1826. //_flipper.ShowAction();
  1827. LOG.Info($"{device.Name} is busy state");
  1828. return false;
  1829. }
  1830. else
  1831. {
  1832. //空闲状态
  1833. LOG.Info($"{device.Name} enter idle state");
  1834. return true;
  1835. }
  1836. }, time * 1000);
  1837. if (ret.Item1)
  1838. {
  1839. if (ret.Item2 == Result.FAIL)
  1840. {
  1841. throw (new RoutineFaildException());
  1842. }
  1843. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1844. {
  1845. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1846. throw (new RoutineFaildException());
  1847. }
  1848. else
  1849. throw (new RoutineBreakException());
  1850. }
  1851. }
  1852. /// <summary>
  1853. /// Flipper Turn to Home
  1854. /// </summary>
  1855. /// <param name="id"></param>
  1856. /// <param name="device"></param>
  1857. /// <param name="name"></param>
  1858. /// <param name="time"></param>
  1859. /// <param name="notify"></param>
  1860. /// <param name="error"></param>
  1861. public void FlipperTurnToHome(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
  1862. {
  1863. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1864. {
  1865. notify(String.Format("{0} Turn to Home", device.Name));
  1866. //有错误 驱动层已打出log
  1867. if (device.Home())
  1868. {
  1869. LOG.Info($"{device.Name} start turn to home");
  1870. return true;
  1871. }
  1872. else
  1873. {
  1874. LOG.Error($"{device.Name} turn to home failed");
  1875. return false;
  1876. }
  1877. }, () =>
  1878. {
  1879. if (device.IsBusy || device.State != FlipperState.Idle)
  1880. {
  1881. //忙状态
  1882. //_flipper.ShowAction();
  1883. LOG.Info($"{device.Name} is busy state");
  1884. return false;
  1885. }
  1886. else
  1887. {
  1888. //空闲状态
  1889. LOG.Info($"{device.Name} enter busy state");
  1890. return true;
  1891. }
  1892. }, time * 1000);
  1893. if (ret.Item1)
  1894. {
  1895. if (ret.Item2 == Result.FAIL)
  1896. {
  1897. throw (new RoutineFaildException());
  1898. }
  1899. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1900. {
  1901. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1902. throw (new RoutineFaildException());
  1903. }
  1904. else
  1905. throw (new RoutineBreakException());
  1906. }
  1907. }
  1908. public void FlipperPrepare(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
  1909. {
  1910. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1911. {
  1912. if(device == null)
  1913. {
  1914. LOG.Error($"{device.Name} device is null, prepare transfer failed");
  1915. return false;
  1916. }
  1917. notify(String.Format("{0} Prepare Transfer", device.Name));
  1918. if (Singleton<RouteManager>.Instance.FLPEntity.CheckToPostMsg(FlipperEntity.FlipperMSG.PrepareTransfer))
  1919. {
  1920. LOG.Info($"{device.Name} start prepare transfer");
  1921. return true;
  1922. }
  1923. else
  1924. {
  1925. LOG.Error($"{device.Name} prepare transfer failed");
  1926. return false;
  1927. }
  1928. }, () =>
  1929. {
  1930. if (Singleton<RouteManager>.Instance.FLPEntity.IsTransfer)
  1931. {
  1932. LOG.Info($"{device.Name} end prepare transfer");
  1933. return true;
  1934. }
  1935. return false;
  1936. }, time * 1000);
  1937. if (ret.Item1)
  1938. {
  1939. if (ret.Item2 == Result.FAIL)
  1940. {
  1941. throw (new RoutineFaildException());
  1942. }
  1943. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1944. {
  1945. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1946. throw (new RoutineFaildException());
  1947. }
  1948. else
  1949. throw (new RoutineBreakException());
  1950. }
  1951. }
  1952. public void FlipperComplete(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
  1953. {
  1954. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1955. {
  1956. if (device == null)
  1957. {
  1958. LOG.Error($"{device.Name} device is null, prepare transfer failed");
  1959. return false;
  1960. }
  1961. notify(String.Format("{0} Complete Transfer", device.Name));
  1962. if (Singleton<RouteManager>.Instance.FLPEntity.CheckToPostMsg(FlipperEntity.FlipperMSG.EndTransfer))
  1963. {
  1964. LOG.Info($"{device.Name} start complete transfer");
  1965. return true;
  1966. }
  1967. else
  1968. {
  1969. LOG.Error($"{device.Name} complete transfer failed");
  1970. return false;
  1971. }
  1972. }, () =>
  1973. {
  1974. if (Singleton<RouteManager>.Instance.FLPEntity.IsIdle)
  1975. {
  1976. LOG.Info($"{device.Name} end complete transfer");
  1977. return true;
  1978. }
  1979. return false;
  1980. }, time * 1000);
  1981. if (ret.Item1)
  1982. {
  1983. if (ret.Item2 == Result.FAIL)
  1984. {
  1985. throw (new RoutineFaildException());
  1986. }
  1987. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1988. {
  1989. error(String.Format("{0} timeout, than {1} seconds", name, time));
  1990. throw (new RoutineFaildException());
  1991. }
  1992. else
  1993. throw (new RoutineBreakException());
  1994. }
  1995. }
  1996. public void FlipperHome(int id, FlipperBase device, string name, int time, Action<string> notify, Action<string> error)
  1997. {
  1998. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1999. {
  2000. if (device == null)
  2001. {
  2002. LOG.Error($"{device.Name} device is null, fliper home failed");
  2003. return false;
  2004. }
  2005. notify(String.Format("{0} Home", device.Name));
  2006. if (Singleton<RouteManager>.Instance.FLPEntity.CheckToPostMsg(FlipperMSG.Home))
  2007. {
  2008. LOG.Info($"{device.Name} start home");
  2009. return true;
  2010. }
  2011. else
  2012. {
  2013. LOG.Error($"{device.Name} home failed");
  2014. return false;
  2015. }
  2016. }, () =>
  2017. {
  2018. if (Singleton<RouteManager>.Instance.FLPEntity.IsIdle)
  2019. {
  2020. LOG.Info($"{device.Name} end home");
  2021. return true;
  2022. }
  2023. return false;
  2024. }, time * 1000);
  2025. if (ret.Item1)
  2026. {
  2027. if (ret.Item2 == Result.FAIL)
  2028. {
  2029. throw (new RoutineFaildException());
  2030. }
  2031. else if (ret.Item2 == Result.TIMEOUT) //timeout
  2032. {
  2033. error(String.Format("{0} timeout, than {1} seconds", name, time));
  2034. throw (new RoutineFaildException());
  2035. }
  2036. else
  2037. throw (new RoutineBreakException());
  2038. }
  2039. }
  2040. }
  2041. }