CommonRoutine.cs 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Device.Unit;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.IOCore;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.Routine;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.RT.Properties;
  10. using Aitex.Triton160.Common;
  11. using Aitex.Triton160.RT.Device;
  12. namespace Aitex.Triton160.RT.Routine
  13. {
  14. public class CommonRoutine : SeqenecRoutine
  15. {
  16. //SC
  17. protected SCItem<int> scOpenGasVavleTimeout = null;
  18. protected int dOpenGasVavleTimeout = 1; //1S
  19. protected SCItem<int> scCloseGasVavleTimeout = null;
  20. protected int dCloseGasVavleTimeout = 2; //2s
  21. protected SCItem<int> scOpenCloseSlitVavleTimeout = null;
  22. protected int valveOpenCloseTimeout = 2; //2s
  23. //private double fInaccuracy = 0.2; //mbar
  24. protected bool bUINotify;
  25. //Device
  26. protected IoValve PV1 = null;
  27. protected IoValve PV2 = null;
  28. protected IoValve PV3 = null;
  29. protected IoValve PV4 = null;
  30. protected IoValve PV5 = null;
  31. protected IoValve PV6 = null;
  32. protected IoValve PV7 = null;
  33. protected IoValve PV8 = null;
  34. protected IoValve PV9 = null;
  35. protected IoValve SV7 = null;
  36. protected IoMfc mfc1 = null;
  37. protected IoMfc mfc2 = null;
  38. protected IoMfc mfc3 = null;
  39. protected IoMfc mfc4 = null;
  40. protected IoMfc mfc5 = null;
  41. protected IoMfc MfcVapor = null;
  42. public string Module { get; set; }
  43. public string Name { get; set; }
  44. public string Display { get; set; }
  45. private IoValve[] _valvesForPumping =
  46. {
  47. DeviceModel.ValveChamberPurge,
  48. DeviceModel.ValveChamberVent,
  49. DeviceModel.ValveMfc1,
  50. DeviceModel.ValveMfc2,
  51. DeviceModel.ValveMfc3,
  52. DeviceModel.ValveMfc4,
  53. DeviceModel.ValveMfc5,
  54. DeviceModel.ValveProcessGasFinal
  55. };
  56. public CommonRoutine()
  57. {
  58. bUINotify = false;
  59. PV1 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  60. PV2 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  61. PV3 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  62. PV4 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  63. PV5 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  64. PV6 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  65. PV7 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  66. PV8 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  67. PV9 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  68. SV7 = DEVICE.GetDevice<IoValve>(TritonDevice.ValveChamberVent.ToString());
  69. mfc1 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
  70. mfc2 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
  71. mfc3 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
  72. mfc4 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
  73. mfc5 = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
  74. MfcVapor = DEVICE.GetDevice<IoMfc>(TritonDevice.ValveChamberVent.ToString());
  75. }
  76. public bool InitCommon()
  77. {
  78. scOpenGasVavleTimeout = SC.GetSC<int>(SCName.System_TimeLimitOfOpenGasVavle);
  79. dOpenGasVavleTimeout = scOpenGasVavleTimeout.Value;
  80. scCloseGasVavleTimeout = SC.GetSC<int>(SCName.System_TimeLimitOfCloseGasValve);
  81. dCloseGasVavleTimeout = scCloseGasVavleTimeout.Value;
  82. scOpenCloseSlitVavleTimeout = SC.GetSC<int>(SCName.System_TimeLimitForOpenCloseSlitVavle);
  83. valveOpenCloseTimeout = scOpenCloseSlitVavleTimeout.Value;
  84. return true;
  85. }
  86. protected void UpdateSCValue()
  87. {
  88. dOpenGasVavleTimeout = scOpenGasVavleTimeout.Value;
  89. dCloseGasVavleTimeout = scCloseGasVavleTimeout.Value;
  90. valveOpenCloseTimeout = scOpenCloseSlitVavleTimeout.Value;
  91. }
  92. public void Loop(int id, string name, int count, Action<string> notify, Action<string> error)
  93. {
  94. Tuple<bool, Result> ret = Loop(id, () =>
  95. {
  96. notify(String.Format("{0}, Loop {1}", name, LoopCounter + 1));
  97. return true;
  98. }, count);
  99. if (ret.Item1)
  100. {
  101. if (ret.Item2 == Result.FAIL)
  102. throw (new RoutineFaildException());
  103. }
  104. }
  105. public void EndLoop(int id, Action<string> notify, Action<string> error)
  106. {
  107. Tuple<bool, Result> ret = EndLoop(id, () => { return true; });
  108. if (ret.Item1)
  109. {
  110. if (ret.Item2 == Result.FAIL)
  111. throw (new RoutineFaildException());
  112. throw (new RoutineBreakException());
  113. }
  114. }
  115. public void CheckDoor(int id, string name, Action<string> notify, Action<string> error)
  116. {
  117. Tuple<bool, Result> ret = Check(id, () =>
  118. {
  119. notify(name);
  120. notify(Resources.CommonRoutine_CheckDoor_CheckChamberDoor);
  121. if (DeviceModel.SensorChamberDoor != null && !DeviceModel.SensorChamberDoor.Value)
  122. {
  123. error(Resources.CommonRoutine_CheckDoor_ChamberDoorNotClosed);
  124. return false;
  125. }
  126. notify(Resources.CommonRoutine_CheckDoor_CheckBackpanelDoor);
  127. if (DeviceModel.SensorBackPanelDoor != null && !DeviceModel.SensorBackPanelDoor.Value)
  128. {
  129. error(Resources.CommonRoutine_CheckDoor_BackpanelDoorNotClosed);
  130. return false;
  131. }
  132. return true;
  133. });
  134. if (ret.Item1)
  135. {
  136. if (ret.Item2 == Result.FAIL)
  137. {
  138. //error("Door Not Closed");
  139. throw (new RoutineFaildException());
  140. }
  141. }
  142. }
  143. public void CheckDryPump(int id, string name, Action<string> notify, Action<string> error)
  144. {
  145. Tuple<bool, Result> ret = Check(id, () =>
  146. {
  147. notify(name);
  148. if (DeviceModel.MainPump.HasError)
  149. {
  150. error("pump is in error state");
  151. return false;
  152. }
  153. if (DeviceModel.MainPump.HasWarning)
  154. {
  155. error("pump is in warning state");
  156. return false;
  157. }
  158. if (!DeviceModel.MainPump.IsRunning)
  159. {
  160. error("pump not running");
  161. return false;
  162. }
  163. return true;
  164. });
  165. if (ret.Item1)
  166. {
  167. if (ret.Item2 == Result.FAIL)
  168. {
  169. throw (new RoutineFaildException());
  170. }
  171. }
  172. }
  173. public void CheckPSWCommunaction(int id, string name, Action<string> notify, Action<string> error)
  174. {
  175. Tuple<bool, Result> ret = Check(id, () =>
  176. {
  177. notify(name);
  178. //Add实际判断
  179. return true;
  180. });
  181. if (ret.Item1)
  182. {
  183. if (ret.Item2 == Result.FAIL)
  184. {
  185. error("Pressure Switch Lost Communcation");
  186. throw (new RoutineFaildException());
  187. }
  188. }
  189. }
  190. public void CloseAllValve(int id, string name, int time, Action<string> notify, Action<string> error)
  191. {
  192. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  193. {
  194. notify(name);
  195. string reason;
  196. foreach (IoValve valve in _valvesForPumping)
  197. {
  198. if (valve != null && !valve.TurnValve(false, out reason))
  199. {
  200. error(string.Format(Resources.CommonRoutine_CloseAllValve_CanNotCloseValve01, valve.Name, reason));
  201. }
  202. }
  203. return true;
  204. }, () =>
  205. {
  206. foreach (IoValve valve in _valvesForPumping)
  207. {
  208. if (valve != null && valve.Status)
  209. {
  210. return false;
  211. }
  212. }
  213. return true;
  214. }, time * 1000);
  215. if (ret.Item1)
  216. {
  217. if (ret.Item2 == Result.FAIL)
  218. {
  219. throw (new RoutineFaildException());
  220. }
  221. else if (ret.Item2 == Result.TIMEOUT) //timeout
  222. {
  223. foreach (IoValve valve in _valvesForPumping)
  224. {
  225. if (valve != null && !valve.Status)
  226. {
  227. error(string.Format(Resources.CommonRoutine_CloseAllValve_CanNotCloseValve0In1S, valve.Name, time));
  228. }
  229. }
  230. throw (new RoutineFaildException());
  231. }
  232. else
  233. throw (new RoutineBreakException());
  234. }
  235. }
  236. public void StopAllGasFlow(int id, string name, int time, Action<string> notify, Action<string> error)
  237. {
  238. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  239. {
  240. notify(name);
  241. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  242. for (int i = 0; i < mfcs.Length; i++)
  243. {
  244. if (mfcs[i] != null)
  245. mfcs[i].Ramp(0, 0);
  246. }
  247. return true;
  248. }, () =>
  249. {
  250. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  251. for (int i = 0; i < mfcs.Length; i++)
  252. {
  253. if (mfcs[i] != null)
  254. {
  255. if (mfcs[i].FeedBack > 1)
  256. return false;
  257. }
  258. }
  259. return true;
  260. }, time * 1000);
  261. if (ret.Item1)
  262. {
  263. throw (new RoutineBreakException());
  264. }
  265. }
  266. public void OpenPumpingValve(int id, string name, int time, Action<string> notify, Action<string> error)
  267. {
  268. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  269. {
  270. notify(name);
  271. string reason = string.Empty;
  272. if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(true, out reason))
  273. {
  274. error("can not set chamber pumping open valve to open, " + reason);
  275. return false;
  276. }
  277. return true;
  278. }, () =>
  279. {
  280. return DeviceModel.ValveChamberPumping.Status;
  281. }, time * 1000);
  282. if (ret.Item1)
  283. {
  284. if (ret.Item2 == Result.FAIL)
  285. {
  286. throw (new RoutineFaildException());
  287. }
  288. else if (ret.Item2 == Result.TIMEOUT) //timeout
  289. {
  290. if (!DeviceModel.ValveChamberPumping.Status)
  291. {
  292. error("can not set chamber pumping open valve to open");
  293. }
  294. throw (new RoutineFaildException());
  295. }
  296. else
  297. throw (new RoutineBreakException());
  298. }
  299. }
  300. public void OpenValve(int id, string name, IoValve valve, int time, Action<string> notify, Action<string> error)
  301. {
  302. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  303. {
  304. notify(String.Format(Resources.CommonRoutine_OpenValve_Open0, name));
  305. //打开阀门
  306. string reason = string.Empty;
  307. if (valve != null && !valve.TurnValve(true, out reason))
  308. {
  309. return false;
  310. }
  311. return true;
  312. }, () =>
  313. {
  314. //检查阀门是否打开
  315. return valve == null || (valve != null && valve.Status);
  316. }, time * 1000);
  317. if (ret.Item1)
  318. {
  319. if (ret.Item2 == Result.FAIL)
  320. {
  321. error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, name));
  322. throw (new RoutineFaildException());
  323. }
  324. else if (ret.Item2 == Result.TIMEOUT) //timeout
  325. {
  326. //添加具体阀门
  327. error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, name));
  328. throw (new RoutineFaildException());
  329. }
  330. else
  331. throw (new RoutineBreakException());
  332. }
  333. }
  334. public void ClosePumpValve(int id, string name, int time, Action<string> notify, Action<string> error)
  335. {
  336. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  337. {
  338. notify(name);
  339. string reason = string.Empty;
  340. if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(false, out reason))
  341. {
  342. return false;
  343. }
  344. return true;
  345. }, () =>
  346. {
  347. if (DeviceModel.ValveChamberPumping != null && DeviceModel.ValveChamberPumping.Status)
  348. return false;
  349. return true;
  350. }, time * 1000);
  351. if (ret.Item1)
  352. {
  353. if (ret.Item2 == Result.FAIL)
  354. {
  355. error(String.Format("pump valve can not be closed"));
  356. throw (new RoutineFaildException());
  357. }
  358. else if (ret.Item2 == Result.TIMEOUT) //timeout
  359. {
  360. error(String.Format("pump valve can not be closed in {0} seconds", time));
  361. throw (new RoutineFaildException());
  362. }
  363. else
  364. throw (new RoutineBreakException());
  365. }
  366. }
  367. public void CloseValve(int id, string name, IoValve valve, int time, Action<string> notify, Action<string> error)
  368. {
  369. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  370. {
  371. notify(String.Format(Resources.CommonRoutine_CloseValve_Close0, name));
  372. //打开阀门
  373. string reason = string.Empty;
  374. if (valve != null && !valve.TurnValve(false, out reason))
  375. {
  376. return false;
  377. }
  378. return true;
  379. }, () =>
  380. {
  381. //检查阀门是否打开
  382. return valve == null || (valve != null && !valve.Status);
  383. }, time * 1000);
  384. if (ret.Item1)
  385. {
  386. if (ret.Item2 == Result.FAIL)
  387. {
  388. error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, name));
  389. throw (new RoutineFaildException());
  390. }
  391. else if (ret.Item2 == Result.TIMEOUT) //timeout
  392. {
  393. //添加具体阀门
  394. error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, name));
  395. throw (new RoutineFaildException());
  396. }
  397. else
  398. throw (new RoutineBreakException());
  399. }
  400. }
  401. public void OpenValve(int id, string name, IoValve[] valves, int time, Action<string> notify, Action<string> error)
  402. {
  403. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  404. {
  405. notify(String.Format(Resources.CommonRoutine_OpenValve_Open0, name));
  406. //打开阀门
  407. string reason = string.Empty;
  408. foreach (var item in valves)
  409. {
  410. if (item != null && !item.TurnValve(true, out reason))
  411. {
  412. error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, item.Name));
  413. return false;
  414. }
  415. }
  416. return true;
  417. }, () =>
  418. {
  419. //检查阀门是否打开
  420. foreach (var item in valves)
  421. {
  422. if (item != null && !item.Status)
  423. {
  424. return false;
  425. }
  426. }
  427. return true;
  428. }, time * 1000);
  429. if (ret.Item1)
  430. {
  431. if (ret.Item2 == Result.FAIL)
  432. {
  433. throw (new RoutineFaildException());
  434. }
  435. else if (ret.Item2 == Result.TIMEOUT) //timeout
  436. {
  437. //添加具体阀门
  438. foreach (var item in valves)
  439. {
  440. if (item != null && !item.Status)
  441. {
  442. error(String.Format(Resources.CommonRoutine_OpenValve_0CanNotBeOpen, item.Name));
  443. }
  444. }
  445. throw (new RoutineFaildException());
  446. }
  447. else
  448. throw (new RoutineBreakException());
  449. }
  450. }
  451. public void CloseValve(int id, string name, IoValve[] valves, int time, Action<string> notify, Action<string> error)
  452. {
  453. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  454. {
  455. notify(String.Format(Resources.CommonRoutine_CloseValve_Close0, name));
  456. //打开阀门
  457. string reason = string.Empty;
  458. foreach (var item in valves)
  459. {
  460. if (item != null && !item.TurnValve(false, out reason))
  461. {
  462. error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, item.Name));
  463. return false;
  464. }
  465. }
  466. return true;
  467. }, () =>
  468. {
  469. //检查阀门是否打开
  470. foreach (var item in valves)
  471. {
  472. if (item != null && item.Status)
  473. {
  474. return false;
  475. }
  476. }
  477. return true;
  478. }, time * 1000);
  479. if (ret.Item1)
  480. {
  481. if (ret.Item2 == Result.FAIL)
  482. {
  483. throw (new RoutineFaildException());
  484. }
  485. else if (ret.Item2 == Result.TIMEOUT) //timeout
  486. {
  487. //添加具体阀门
  488. foreach (var item in valves)
  489. {
  490. if (item != null && item.Status)
  491. {
  492. error(String.Format(Resources.CommonRoutine_CloseValve_0CanNotBeClose, item.Name));
  493. }
  494. }
  495. throw (new RoutineFaildException());
  496. }
  497. else
  498. throw (new RoutineBreakException());
  499. }
  500. }
  501. public void OpenMFC(int id, string name, IoMfc[] valves, int time, Action<string> notify, Action<string> error)
  502. {
  503. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  504. {
  505. notify(String.Format("Open {0}", name));
  506. //打开阀门
  507. string reason = string.Empty;
  508. foreach (var item in valves)
  509. {
  510. // if (!item.Ramp(false, out reason))
  511. {
  512. error(String.Format("{0} Can Not Be Open", item.Name));
  513. return false;
  514. }
  515. }
  516. return true;
  517. }, () =>
  518. {
  519. //检查阀门是否打开
  520. foreach (var item in valves)
  521. {
  522. // if (!item.Status)
  523. {
  524. return false;
  525. }
  526. }
  527. return true;
  528. }, time * 1000);
  529. if (ret.Item1)
  530. {
  531. if (ret.Item2 == Result.FAIL)
  532. {
  533. throw (new RoutineFaildException());
  534. }
  535. else if (ret.Item2 == Result.TIMEOUT) //timeout
  536. {
  537. //添加具体阀门
  538. foreach (var item in valves)
  539. {
  540. // if (!item.Status)
  541. {
  542. error(String.Format("{0} Can Not Be Open", item.Name));
  543. }
  544. }
  545. throw (new RoutineFaildException());
  546. }
  547. else
  548. throw (new RoutineBreakException());
  549. }
  550. }
  551. public void StopHeater(int id, string name, int time, Action<string> notify, Action<string> error)
  552. {
  553. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  554. {
  555. notify(String.Format("Close {0}", name));
  556. //Stop Heater
  557. string reason = string.Empty;
  558. return true;
  559. }, () =>
  560. {
  561. //Stop Heater
  562. return true;
  563. }, time * 1000);
  564. if (ret.Item1)
  565. {
  566. if (ret.Item2 == Result.FAIL)
  567. {
  568. throw (new RoutineFaildException());
  569. }
  570. else if (ret.Item2 == Result.TIMEOUT) //timeout
  571. {
  572. //添加
  573. error(String.Format("Heater Not Stop"));
  574. throw (new RoutineFaildException());
  575. }
  576. else
  577. throw (new RoutineBreakException());
  578. }
  579. }
  580. public void CheckTemper(int id, string name, double target, int time, Action<string> notify, Action<string> error)
  581. {
  582. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  583. {
  584. notify(name);
  585. return true;
  586. }, () =>
  587. {
  588. //检查是否Cooling
  589. return true;
  590. }, time * 1000);
  591. if (ret.Item1)
  592. {
  593. if (ret.Item2 == Result.FAIL)
  594. {
  595. throw (new RoutineFaildException());
  596. }
  597. else if (ret.Item2 == Result.TIMEOUT) //timeout
  598. {
  599. //
  600. error(String.Format("Cooling Time out"));
  601. throw (new RoutineFaildException());
  602. }
  603. else
  604. throw (new RoutineBreakException());
  605. }
  606. }
  607. public void CheckATM(int id, string name, int time, Action<string> notify, Action<string> error)
  608. {
  609. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  610. {
  611. notify(name);
  612. return true;
  613. }, () =>
  614. {
  615. //检查是否ATM
  616. return DeviceModel.PressureMeterChamber.Value >= 750000;
  617. }, time * 1000);
  618. if (ret.Item1)
  619. {
  620. if (ret.Item2 == Result.FAIL)
  621. {
  622. throw (new RoutineFaildException());
  623. }
  624. else if (ret.Item2 == Result.TIMEOUT) //timeout
  625. {
  626. //
  627. error(String.Format("Vent Time out"));
  628. throw (new RoutineFaildException());
  629. }
  630. else
  631. throw (new RoutineBreakException());
  632. }
  633. }
  634. public void CheckVAC(int id, string name, double target, int time, Action<string> notify, Action<string> error)
  635. {
  636. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  637. {
  638. notify(name);
  639. return true;
  640. }, () =>
  641. {
  642. if (DeviceModel.PressureMeterChamber.Value < target)
  643. {
  644. notify(string.Format(Resources.CommonRoutine_CheckVAC_PumpBelow0, target));
  645. return true;
  646. }
  647. return false;
  648. }, time * 1000);
  649. if (ret.Item1)
  650. {
  651. if (ret.Item2 == Result.FAIL)
  652. {
  653. throw (new RoutineFaildException());
  654. }
  655. else if (ret.Item2 == Result.TIMEOUT) //timeout
  656. {
  657. Warning(String.Format("Can not pump to base pressure {0} in {1} seconds", target, time));
  658. throw (new RoutineFaildException());
  659. }
  660. else
  661. throw (new RoutineBreakException());
  662. }
  663. }
  664. public void CheckCondition(int id, string name, ref bool result, Action<string> notify, Action<string> error, Func<bool> func)
  665. {
  666. Tuple<bool, Result> ret = Check(id, () =>
  667. {
  668. notify(name);
  669. return func();
  670. });
  671. if (ret.Item1)
  672. {
  673. if (ret.Item2 == Result.FAIL)
  674. {
  675. result = false;
  676. }
  677. else
  678. {
  679. result = true;
  680. }
  681. }
  682. }
  683. public void End(int id, string name, Action<string> notify, Action<string> error)
  684. {
  685. Tuple<bool, Result> ret = Execute(id, () =>
  686. {
  687. double duration_min = counter.GetElapseTime() / 1000.0 / 60;
  688. string info = string.Format(Resources.CommonRoutine_End_0FinishedIn1Minitues, Name, duration_min.ToString("0.0"));
  689. notify(info);
  690. EV.PostMessage(Module, EventEnum.ServiceRoutineStopped, Module, Name);
  691. if (bUINotify)
  692. EV.PostPopDialogMessage(EventLevel.Information, Name, String.Format("{0} {1}", Module, info));
  693. return true;
  694. });
  695. }
  696. //延时
  697. public void Delay(int id, string name, double time, Action<string> notify, Action<string> error)
  698. {
  699. Tuple<bool, Result> ret = Delay(id, () =>
  700. {
  701. notify(name);
  702. return true;
  703. }, time * 1000);
  704. if (ret.Item1)
  705. {
  706. if (ret.Item2 == Result.RUN)
  707. {
  708. throw (new RoutineBreakException());
  709. }
  710. }
  711. }
  712. ///等待DI
  713. public void WaitDI(int id, string name, DIAccessor di, bool value, int time, Action<string> notify, Action<string> error)
  714. {
  715. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  716. {
  717. notify(name);
  718. return true;
  719. }, () =>
  720. {
  721. return di.Value == value;
  722. }, time * 1000);
  723. if (ret.Item1)
  724. {
  725. if (ret.Item2 == Result.FAIL)
  726. {
  727. throw (new RoutineFaildException());
  728. }
  729. else if (ret.Item2 == Result.TIMEOUT) //timeout
  730. {
  731. error(String.Format("{0}超时失败,超时时间为{1}秒", name, time));
  732. throw (new RoutineFaildException());
  733. }
  734. else
  735. throw (new RoutineBreakException());
  736. }
  737. }
  738. public void CheckDI(int id, string name, DIAccessor di, bool value, ref bool result, Action<string> notify, Action<string> error)
  739. {
  740. Tuple<bool, Result> ret = Check(id, () =>
  741. {
  742. notify(name);
  743. return di.Value == value;
  744. });
  745. if (ret.Item1)
  746. {
  747. if (ret.Item2 == Result.FAIL)
  748. {
  749. result = false;
  750. }
  751. else
  752. {
  753. result = true;
  754. }
  755. }
  756. }
  757. public void DefautAndCloseFinal()
  758. {
  759. string reason = String.Empty;
  760. Default();
  761. }
  762. public void AlarmEvent()
  763. {
  764. }
  765. protected void Default()
  766. {
  767. string reason = String.Empty;
  768. }
  769. protected void StopRamp()
  770. {
  771. string reason = string.Empty;
  772. if (!DeviceModel.Rf.SetPowerOnOff(false, out reason))
  773. {
  774. LOG.Write(reason);
  775. }
  776. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  777. for (int i = 0; i < mfcs.Length; i++)
  778. {
  779. if (mfcs[i] != null)
  780. mfcs[i].Ramp(0, 0);
  781. }
  782. foreach (IoValve valve in _valvesForPumping)
  783. {
  784. if (valve != null && !valve.TurnValve(false, out reason))
  785. {
  786. LOG.Write(string.Format("can not close valve {0}, {1}", valve.Name, reason));
  787. }
  788. }
  789. }
  790. protected virtual void Notify(string message)
  791. {
  792. EV.PostMessage(Module, EventEnum.ServiceRoutineInfo, Module, Display, message);
  793. }
  794. protected virtual void Warning(string message)
  795. {
  796. EV.PostMessage(Module, EventEnum.DefaultWarning, message);
  797. }
  798. protected virtual void Stop(string reason)
  799. {
  800. StopRamp();
  801. EV.PostPopDialogMessage(EventLevel.Alarm, String.Format("{0} '{1}' stopped", Module, Display),
  802. String.Format("stop reason:{0}", reason));
  803. EV.PostMessage(Module, EventEnum.ServiceRoutineAborted, Module, Display, reason);
  804. }
  805. public void Abort()
  806. {
  807. StopRamp();
  808. }
  809. bool DeviceCyclePump(out string reason)
  810. {
  811. reason = "";
  812. if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(true, out reason))
  813. return false;
  814. if (DeviceModel.ValveProcessGasFinal != null && !DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason))
  815. return false;
  816. if (DeviceModel.ValveChamberPurge != null && !DeviceModel.ValveChamberPurge.TurnValve(false, out reason))
  817. return false;
  818. if (DeviceModel.ValveChamberPurge == null && DeviceModel.ValveChamberVent != null)
  819. {
  820. if (!DeviceModel.ValveChamberVent.TurnValve(false, out reason))
  821. return false;
  822. }
  823. return true;
  824. }
  825. bool DeviceStopCyclePump(out string reason)
  826. {
  827. reason = "";
  828. if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(false, out reason))
  829. return false;
  830. return true;
  831. }
  832. bool DeviceCycleVent(out string reason)
  833. {
  834. reason = "";
  835. if (DeviceModel.ValveChamberPumping != null && !DeviceModel.ValveChamberPumping.TurnValve(false, out reason))
  836. return false;
  837. if (DeviceModel.ValveProcessGasFinal != null && !DeviceModel.ValveProcessGasFinal.TurnValve(true, out reason))
  838. return false;
  839. if (DeviceModel.ValveChamberPurge != null && !DeviceModel.ValveChamberPurge.TurnValve(true, out reason))
  840. return false;
  841. if (DeviceModel.ValveChamberPurge == null)
  842. {
  843. if (DeviceModel.ValveChamberVent != null && !DeviceModel.ValveChamberVent.TurnValve(true, out reason))
  844. return false;
  845. }
  846. return true;
  847. }
  848. bool DeviceStopCycleVent(out string reason)
  849. {
  850. reason = "";
  851. if (DeviceModel.ValveProcessGasFinal != null && !DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason))
  852. return false;
  853. if (DeviceModel.ValveChamberPurge != null && !DeviceModel.ValveChamberPurge.TurnValve(false, out reason))
  854. return false;
  855. if (DeviceModel.ValveChamberPurge == null)
  856. {
  857. if (DeviceModel.ValveChamberVent != null && !DeviceModel.ValveChamberVent.TurnValve(false, out reason))
  858. return false;
  859. }
  860. return true;
  861. }
  862. //
  863. public void CyclePump(int id, string name, int target, int timeLimit, bool isStopPumpOnceDone, Action<string> notify, Action<string> error)
  864. {
  865. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  866. {
  867. notify(String.Format(Resources.CommonRoutine_CyclePump_PumpingPressureTo0MTor, target));
  868. string reason;
  869. if (!DeviceCyclePump(out reason))
  870. {
  871. error(reason);
  872. return false;
  873. }
  874. return true;
  875. }, () =>
  876. {
  877. if (DeviceModel.PressureMeterChamber != null && (DeviceModel.PressureMeterChamber.Value < target))
  878. {
  879. if (isStopPumpOnceDone)
  880. {
  881. string reason;
  882. if (!DeviceStopCyclePump(out reason))
  883. {
  884. error(reason);
  885. return false;
  886. }
  887. }
  888. return true;
  889. }
  890. return false;
  891. }, timeLimit * 1000);
  892. if (ret.Item1)
  893. {
  894. if (ret.Item2 == Result.FAIL)
  895. {
  896. throw (new RoutineFaildException());
  897. }
  898. else if (ret.Item2 == Result.TIMEOUT) //timeout
  899. {
  900. error(String.Format("Can not pump to pressure {0} in time {1}", target, timeLimit));
  901. throw (new RoutineFaildException());
  902. }
  903. else
  904. throw (new RoutineBreakException());
  905. }
  906. }
  907. public void CycleVent(int id, string name, int target, int timeLimit, bool isStopVentOnceDone, Action<string> notify, Action<string> error)
  908. {
  909. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  910. {
  911. notify(String.Format(Resources.CommonRoutine_CycleVent_VentPressureTo0Mtor, target));
  912. string reason;
  913. if (!DeviceCycleVent(out reason))
  914. {
  915. error(reason);
  916. return false;
  917. }
  918. return true;
  919. }, () =>
  920. {
  921. if (DeviceModel.PressureMeterChamber != null && DeviceModel.PressureMeterChamber.Value > target)
  922. {
  923. if (isStopVentOnceDone)
  924. {
  925. string reason;
  926. if (!DeviceStopCycleVent(out reason))
  927. {
  928. error(reason);
  929. return false;
  930. }
  931. }
  932. return true;
  933. }
  934. return false;
  935. }, timeLimit * 1000);
  936. if (ret.Item1)
  937. {
  938. if (ret.Item2 == Result.FAIL)
  939. {
  940. throw (new RoutineFaildException());
  941. }
  942. else if (ret.Item2 == Result.TIMEOUT) //timeout
  943. {
  944. error(String.Format("Can not purge to purge pressure {0} in purge time {1}", target, timeLimit));
  945. if (isStopVentOnceDone)
  946. {
  947. string reason;
  948. if (!DeviceStopCycleVent(out reason))
  949. {
  950. error(reason);
  951. }
  952. }
  953. throw (new RoutineFaildException());
  954. }
  955. else
  956. throw (new RoutineBreakException());
  957. }
  958. }
  959. public void RFPowerOn(int id, string name, int rfOnTime, float alarmRange, float alarmTime, Action<string> notify, Action<string> error)
  960. {
  961. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  962. {
  963. notify(name);
  964. string reason = string.Empty;
  965. if (!DeviceModel.Rf.SetPowerOnOff(true, out reason))
  966. {
  967. error(reason);
  968. return false;
  969. }
  970. return true;
  971. }, () =>
  972. {
  973. if (Elapsed >= rfOnTime)
  974. {
  975. notify(string.Format("RF stop"));
  976. IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5 };
  977. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  978. string reason = string.Empty;
  979. for (int i = 0; i < mfcs.Length && i < valves.Length; i++)
  980. {
  981. if (valves[i] != null)
  982. valves[i].TurnValve(false, out reason);
  983. if (mfcs[i] != null)
  984. mfcs[i].Ramp(0, 0);
  985. }
  986. if (DeviceModel.ValveProcessGasFinal != null)
  987. DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason);
  988. if (!DeviceModel.Rf.SetPowerOnOff(false, out reason))
  989. {
  990. error(reason);
  991. return null;
  992. }
  993. return true;
  994. }
  995. if (Math.Abs(DeviceModel.Rf.RFForwardPower - DeviceModel.Rf.PowerSetPoint) > alarmRange)
  996. {
  997. if (!timerStart)
  998. {
  999. timerStart = true;
  1000. timerAlarm.Start(alarmTime);
  1001. }
  1002. if (ElapsedAlarm > alarmTime)
  1003. {
  1004. timerStart = false;
  1005. timerAlarm.Stop();
  1006. error(string.Format("RF power can not stable within {0} in power alarm time {1}", alarmRange, alarmTime));
  1007. return null;
  1008. }
  1009. }
  1010. else
  1011. {
  1012. timerStart = false;
  1013. timerAlarm.Stop();
  1014. }
  1015. return false;
  1016. }, rfOnTime * 1000);
  1017. if (ret.Item1)
  1018. {
  1019. if (ret.Item2 == Result.FAIL)
  1020. {
  1021. string reason = string.Empty;
  1022. if (!DeviceModel.Rf.SetPowerOnOff(false, out reason))
  1023. {
  1024. error(reason);
  1025. }
  1026. IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5 };
  1027. IoMfc[] mfcs = { DeviceModel.MfcGas1, DeviceModel.MfcGas2, DeviceModel.MfcGas3, DeviceModel.MfcGas4, DeviceModel.MfcGas5 };
  1028. for (int i = 0; i < mfcs.Length && i < valves.Length; i++)
  1029. {
  1030. if (valves[i] != null)
  1031. valves[i].TurnValve(false, out reason);
  1032. if (mfcs[i] != null)
  1033. mfcs[i].Ramp(0, 0);
  1034. }
  1035. if (DeviceModel.ValveProcessGasFinal != null)
  1036. DeviceModel.ValveProcessGasFinal.TurnValve(false, out reason);
  1037. throw (new RoutineFaildException());
  1038. }
  1039. throw (new RoutineBreakException());
  1040. }
  1041. }
  1042. public void RFPowerOff(int id, string name, Action<string> notify, Action<string> error)
  1043. {
  1044. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  1045. {
  1046. notify(name);
  1047. string reason = string.Empty;
  1048. if (!DeviceModel.Rf.SetPowerOnOff(false, out reason))
  1049. {
  1050. error(reason);
  1051. return false;
  1052. }
  1053. return true;
  1054. }, () =>
  1055. {
  1056. return true;
  1057. }, 0);
  1058. if (ret.Item1)
  1059. {
  1060. if (ret.Item2 == Result.FAIL)
  1061. {
  1062. throw (new RoutineFaildException());
  1063. }
  1064. throw (new RoutineBreakException());
  1065. }
  1066. }
  1067. public void CheckRfOff(int id, string name)
  1068. {
  1069. Tuple<bool, Result> ret = Check(id, () =>
  1070. {
  1071. Notify(name);
  1072. return !DeviceModel.Rf.IsRfOn;
  1073. });
  1074. if (ret.Item1)
  1075. {
  1076. if (ret.Item2 == Result.FAIL)
  1077. {
  1078. Stop("RF power is on");
  1079. throw (new RoutineFaildException());
  1080. }
  1081. else
  1082. {
  1083. throw (new RoutineBreakException());
  1084. }
  1085. }
  1086. }
  1087. public void CheckPumpingOn(int id, string name)
  1088. {
  1089. Tuple<bool, Result> ret = Check(id, () =>
  1090. {
  1091. Notify(name);
  1092. return DeviceModel.MainPump.IsRunning && DeviceModel.ValveChamberPumping.Status;
  1093. });
  1094. if (ret.Item1)
  1095. {
  1096. if (ret.Item2 == Result.FAIL)
  1097. {
  1098. Stop("pump valve not open");
  1099. throw (new RoutineFaildException());
  1100. }
  1101. else
  1102. {
  1103. throw (new RoutineBreakException());
  1104. }
  1105. }
  1106. }
  1107. public void CheckGasFlowStopped(int id, string name)
  1108. {
  1109. Tuple<bool, Result> ret = Check(id, () =>
  1110. {
  1111. Notify(name);
  1112. IoValve[] valves = { DeviceModel.ValveMfc1, DeviceModel.ValveMfc2, DeviceModel.ValveMfc3, DeviceModel.ValveMfc4, DeviceModel.ValveMfc5, DeviceModel.ValveProcessGasFinal, };
  1113. return !Array.Exists(valves, v => v != null && v.Status);
  1114. });
  1115. if (ret.Item1)
  1116. {
  1117. if (ret.Item2 == Result.FAIL)
  1118. {
  1119. Stop("Gas flow valves not all closed");
  1120. throw (new RoutineFaildException());
  1121. }
  1122. else
  1123. {
  1124. throw (new RoutineBreakException());
  1125. }
  1126. }
  1127. }
  1128. public void SetRfMatchMode(int stepId, string name, int mode)
  1129. {
  1130. Tuple<bool, Result> ret = ExecuteAndWait(stepId, () =>
  1131. {
  1132. Notify(name);
  1133. string reason = string.Empty;
  1134. if (!DeviceModel.Rf.SetMatchMode(mode, out reason))
  1135. {
  1136. Stop(reason);
  1137. return false;
  1138. }
  1139. return true;
  1140. }, () => true, 0);
  1141. if (ret.Item1)
  1142. {
  1143. if (ret.Item2 == Result.FAIL)
  1144. {
  1145. throw (new RoutineFaildException());
  1146. }
  1147. throw (new RoutineBreakException());
  1148. }
  1149. }
  1150. public void VentToPrecision(int stepId, string name, int timeVent, Action<string> notify, Action<string> error)
  1151. {
  1152. Tuple<bool, Result> ret = Delay(stepId, () =>
  1153. {
  1154. notify(name);
  1155. string reason;
  1156. if (!DeviceModel.ValveChamberPumping.TurnValve(false, out reason))
  1157. {
  1158. error(reason);
  1159. return false;
  1160. }
  1161. if (!DeviceModel.ValveChamberVent.TurnValve(true, out reason))
  1162. {
  1163. error(reason);
  1164. return false;
  1165. }
  1166. return true;
  1167. }, timeVent * 1000);
  1168. if (ret.Item1)
  1169. {
  1170. if (ret.Item2 == Result.FAIL)
  1171. {
  1172. throw (new RoutineFaildException());
  1173. }
  1174. throw (new RoutineBreakException());
  1175. }
  1176. }
  1177. }
  1178. }