SETMEntity.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Diagnostics;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using Venus_Core;
  19. using Venus_RT.Devices;
  20. using Venus_RT.Devices.PreAligner;
  21. using Venus_RT.Devices.TM;
  22. using Venus_RT.Devices.VCE;
  23. using Venus_RT.Modules.PMs;
  24. using static Mono.Security.X509.X520;
  25. namespace Venus_RT.Modules.TM.VenusEntity
  26. {
  27. public class SETMEntity : Entity, IModuleEntity
  28. {
  29. public enum STATE
  30. {
  31. Unknown,
  32. Init,
  33. Initializing,
  34. InitializingRB,
  35. Idle,
  36. Error,
  37. Pumping,
  38. Venting,
  39. Purging,
  40. Leakchecking,
  41. Picking,
  42. Placing,
  43. Swaping,
  44. PMPicking,
  45. PMPlacing,
  46. PMSwaping,
  47. Aligning,
  48. Mapping,
  49. Extending,
  50. Retracting,
  51. Swapping,
  52. Gotoing,
  53. ControllingPressure,
  54. }
  55. public enum MSG
  56. {
  57. Home,
  58. RobotHome,
  59. Online,
  60. Offline,
  61. Pump,
  62. Vent,
  63. Purge,
  64. CyclePurge,
  65. LeakCheck,
  66. Pick,
  67. Place,
  68. Swap,
  69. DoublePick,
  70. DoublePlace,
  71. DoubleSwap,
  72. PMPick,
  73. PMPlace,
  74. PMSwap,
  75. Extend,
  76. Retract,
  77. TMCycle,
  78. ControlPressure,
  79. Error,
  80. Abort,
  81. AbortControlPressure,
  82. Align,
  83. CreateJob,
  84. StartJob,
  85. Goto,
  86. }
  87. #region 公开变量
  88. public bool IsIdle
  89. {
  90. get { return fsm.State == (int)STATE.Idle; }
  91. }
  92. public bool IsError
  93. {
  94. get { return fsm.State == (int)STATE.Error; }
  95. }
  96. public bool IsInit
  97. {
  98. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  99. }
  100. public bool IsBusy
  101. {
  102. get { return !IsInit && !IsError && !IsIdle; }
  103. }
  104. /// <summary>
  105. /// VCE部分的内容从变量转化为查询方法
  106. /// </summary>
  107. public bool VCEIsATM(ModuleName VCEName)
  108. {
  109. switch (_module)
  110. {
  111. case ModuleName.SETM:
  112. return _tm.IsVCEATM;
  113. case ModuleName.DETM:
  114. return VCEName == ModuleName.VCEA ? _tm.IsVCEAATM: _tm.IsVCEBATM;
  115. default:
  116. return false;
  117. }
  118. }
  119. public bool TMIsATM => _tm.IsTMATM;
  120. public bool TMIsVAC => _tm.IsTMVAC;
  121. public bool VCEIsVAC(ModuleName VCEName)
  122. {
  123. switch (_module)
  124. {
  125. case ModuleName.SETM:
  126. return _tm.IsVCEVAC;
  127. case ModuleName.DETM:
  128. return VCEName == ModuleName.VCEA ? _tm.IsVCEAVAC : _tm.IsVCEBVAC;
  129. default:
  130. return false;
  131. }
  132. }
  133. public bool IsPMASlitDoorClosed => _tm.PMASlitDoorClosed;
  134. public bool IsPMBSlitDoorClosed => _tm.PMBSlitDoorClosed;
  135. public bool IsPMCSlitDoorClosed => _tm.PMCSlitDoorClosed;
  136. public bool IsPMDSlitDoorClosed => _tm.PMDSlitDoorClosed;
  137. public bool IsVCESlitDoorClosed(ModuleName VCEName)
  138. {
  139. switch (_module)
  140. {
  141. case ModuleName.SETM:
  142. return _tm.VCESlitDoorClosed;
  143. case ModuleName.DETM:
  144. return VCEName == ModuleName.VCEA ? _tm.VCEASlitDoorClosed : _tm.VCEBSlitDoorClosed;
  145. default:
  146. return false;
  147. }
  148. }
  149. public bool IsPMASlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMA);
  150. public bool IsPMBSlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMB);
  151. public bool IsPMCSlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMC);
  152. public bool IsPMDSlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMD);
  153. public bool IsVCESlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.VCE1);
  154. public double VCEPressure(ModuleName VCEName)
  155. {
  156. switch (_module)
  157. {
  158. case ModuleName.SETM:
  159. return _tm.VCEPressure;
  160. case ModuleName.DETM:
  161. return VCEName == ModuleName.SETM ? _tm.VCEAPressure: _tm.VCEBPressure;
  162. default:
  163. return 0;
  164. }
  165. }
  166. public RState RobotStatus
  167. {
  168. get
  169. {
  170. if (_robot.Status != RState.Running)
  171. {
  172. if (_robotWatch.ElapsedMilliseconds < 100)
  173. return RState.Running;
  174. else
  175. return _robot.Status;
  176. }
  177. else
  178. return RState.Running;
  179. }
  180. }
  181. private bool _IsOnline;
  182. public bool IsOnline => _IsOnline;
  183. //public bool IsTMVac => _tm.IsTMVac;
  184. //public bool IsTMATM => _tm.IsTMATM;
  185. #endregion
  186. #region 私有变量
  187. private readonly TMBase _tm;
  188. private readonly ITransferRobot _robot;
  189. private readonly IPreAlign _vpa;
  190. private readonly SEMFHomeRoutine _homeRoutine;
  191. private readonly SEMFPickRoutine _pickRoutine;
  192. private readonly SEMFPlaceRoutine _placeRoutine;
  193. private readonly SEMFVentRoutine _ventRoutine;
  194. private readonly SEMFPumpRoutine _pumpRoutine;
  195. private readonly SEMFPMPickRoutine _pickpmRoutine;
  196. private readonly SEMFPMPlaceRoutine _placepmRoutine;
  197. private readonly SEMFSwapRoutine _swaproutine;
  198. private readonly SEMFPMSwapRoutine _pmswaproutine;
  199. private readonly SEMFPMRetractRoutine _pmRetractRoutine;
  200. private readonly SEMFPMExtendRoutine _pmExtendRoutine;
  201. //private readonly
  202. //private bool startControlPressureFlag = true;
  203. //private bool stopControlPressureFlag = false;
  204. private Stopwatch _robotWatch = new Stopwatch();
  205. //private R_TRIG _robotIdleTrigger = new R_TRIG();
  206. //private int _controlPressureCheckPoint = 100;
  207. //private int _controlPressureSetPoint = 90;
  208. //private int _controlFlowSetPoint = 90;
  209. private ModuleName _module;
  210. #endregion
  211. public SETMEntity(ModuleName module)
  212. {
  213. _module = module;
  214. if (module == ModuleName.SETM)
  215. _tm = DEVICE.GetDevice<HongHuTM>(module.ToString());
  216. if (module == ModuleName.DETM)
  217. _tm = DEVICE.GetDevice<HongHuDETM>(module.ToString());
  218. if (ModuleHelper.IsInstalled(ModuleName.TMRobot))
  219. _robot = new HongHuVR();
  220. _vpa = new HongHuVPA(ModuleName.VPA);
  221. _robotWatch = new Stopwatch();
  222. _homeRoutine = new SEMFHomeRoutine(_tm,_robot, _vpa, module);
  223. _pickRoutine = new SEMFPickRoutine(_tm,_robot, _vpa, module);
  224. _placeRoutine = new SEMFPlaceRoutine(_tm, _robot, _vpa, module);
  225. _pumpRoutine = new SEMFPumpRoutine(_tm, module);
  226. _ventRoutine = new SEMFVentRoutine(_tm, module);
  227. _pickpmRoutine = new SEMFPMPickRoutine(_tm, _robot, module);
  228. _placepmRoutine = new SEMFPMPlaceRoutine(_tm, _robot, module);
  229. _swaproutine = new SEMFSwapRoutine(_tm, _robot, module);
  230. _pmswaproutine = new SEMFPMSwapRoutine(_tm, _robot, module);
  231. _pmExtendRoutine = new SEMFPMExtendRoutine(_tm, _robot, _vpa, module);
  232. _pmRetractRoutine = new SEMFPMRetractRoutine(_tm, _robot, _vpa, module);
  233. InitFsmMap();
  234. }
  235. protected override bool Init()
  236. {
  237. DATA.Subscribe($"{_module}.FsmState", () => ((STATE)fsm.State).ToString());
  238. DATA.Subscribe($"{_module}.RobotMoveAction", () => _robot.TMRobotMoveInfo, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  239. DATA.Subscribe($"{_module}.RobotMoveAction.ArmTarget", () => _robot.TMRobotMoveInfo.ArmTarget.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  240. DATA.Subscribe($"{_module}.RobotMoveAction.BladeTarget", () => _robot.TMRobotMoveInfo.BladeTarget, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  241. DATA.Subscribe($"{_module}.RobotMoveAction.RobotAction", () => _robot.TMRobotMoveInfo.Action.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  242. DATA.Subscribe($"{_module}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  243. DATA.Subscribe($"{_module}.IsOffline", () => !IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  244. OP.Subscribe($"{_module}.Goto", (cmd, args) => RobotGoto(args));
  245. OP.Subscribe($"{_module}.Home", (cmd, args) => { PostMsg(MSG.Home, args); return true; });
  246. OP.Subscribe($"{_module}.Abort", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  247. OP.Subscribe($"{_module}.Pick", (cmd, args) => { PostMsg(MSG.Pick, args); return true; });
  248. OP.Subscribe($"{_module}.Place", (cmd, args) => { PostMsg(MSG.Place, args); return true; });
  249. OP.Subscribe($"{_module}.Extend", (cmd, args) => { PostMsg(MSG.Extend, args); return true; });
  250. OP.Subscribe($"{_module}.Retract", (cmd, args) => { PostMsg(MSG.Retract, args); return true; });
  251. OP.Subscribe($"{_module}.PMPick", (cmd, args) => { PostMsg(MSG.PMPick, args); return true; });
  252. OP.Subscribe($"{_module}.PMPlace", (cmd, args) => { PostMsg(MSG.PMPlace, args); return true; });
  253. OP.Subscribe($"{_module}.PumpDown", (cmd, args) => { PostMsg(MSG.Pump); return true; });
  254. OP.Subscribe($"{_module}.Vent", (cmd, args) => { PostMsg(MSG.Vent); return true; });
  255. OP.Subscribe($"{_module}.SetOnline", (cmd, args) =>
  256. {
  257. if (IsIdle)
  258. _IsOnline = true;
  259. else
  260. LOG.Write(eEvent.WARN_TM,_module,"cannot Set Online as TM is not idle");
  261. return true;
  262. });
  263. OP.Subscribe($"{_module}.SetOffline", (cmd, args) =>
  264. {
  265. _IsOnline = false;
  266. return true;
  267. });
  268. return true;
  269. }
  270. private void InitFsmMap()
  271. {
  272. fsm = new StateMachine<SETMEntity>($"{_module}", (int)STATE.Init, 50);
  273. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  274. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  275. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  276. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  277. //Home
  278. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomeTimeout, STATE.Idle);
  279. Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Init);
  280. //Pick
  281. Transition(STATE.Idle, MSG.Pick, fnStartPick, STATE.Picking);
  282. Transition(STATE.Picking, FSM_MSG.TIMER, fnPickTimeout, STATE.Idle);
  283. Transition(STATE.Picking, MSG.Abort, fnAbortPick, STATE.Idle);
  284. //Place
  285. Transition(STATE.Idle, MSG.Place, fnStartPlace, STATE.Placing);
  286. Transition(STATE.Placing, FSM_MSG.TIMER, fnPlaceTimeout, STATE.Idle);
  287. Transition(STATE.Placing, MSG.Abort, fnAbortPlace, STATE.Idle);
  288. //Pump
  289. Transition(STATE.Idle, MSG.Pump, fnStartPump, STATE.Pumping);
  290. Transition(STATE.Pumping, FSM_MSG.TIMER, fnPumpTimeout, STATE.Idle);
  291. Transition(STATE.Pumping, MSG.Abort, fnAbortPump, STATE.Idle);
  292. //Vent
  293. Transition(STATE.Idle, MSG.Vent, fnStartVent, STATE.Venting);
  294. Transition(STATE.Venting, FSM_MSG.TIMER, fnVentTimeout, STATE.Idle);
  295. Transition(STATE.Venting, MSG.Abort, fnAbortVent, STATE.Idle);
  296. //PMPick
  297. Transition(STATE.Idle, MSG.PMPick, fnStartPMPick, STATE.PMPicking);
  298. Transition(STATE.PMPicking, FSM_MSG.TIMER, fnPMPickTimeout, STATE.Idle);
  299. Transition(STATE.PMPicking, MSG.Abort, fnAbortPMPick, STATE.Idle);
  300. //PMPlace
  301. Transition(STATE.Idle, MSG.PMPlace, fnStartPMPlace, STATE.PMPlacing);
  302. Transition(STATE.PMPlacing, FSM_MSG.TIMER, fnPMPlaceTimeout, STATE.Idle);
  303. Transition(STATE.PMPlacing, MSG.Abort, fnAbortPMPlace, STATE.Idle);
  304. //PA align
  305. Transition(STATE.Idle, MSG.Align, fnStartAlign, STATE.Aligning);
  306. Transition(STATE.Aligning, FSM_MSG.TIMER, fnAlignTimeout, STATE.Idle);
  307. Transition(STATE.Aligning, MSG.Abort, fnAbortAlign, STATE.Idle);
  308. //Swap
  309. Transition(STATE.Idle, MSG.Swap, fnStartSwap, STATE.Swapping);
  310. Transition(STATE.Swapping, FSM_MSG.TIMER, fnSwapTimeout, STATE.Idle);
  311. Transition(STATE.Swapping, MSG.Abort, fnAbortSwap, STATE.Idle);
  312. //PM Swap
  313. Transition(STATE.Idle, MSG.PMSwap, fnStartPMSwap, STATE.PMSwaping);
  314. Transition(STATE.PMSwaping, FSM_MSG.TIMER, fnPMSwapTimeout, STATE.Idle);
  315. Transition(STATE.PMSwaping, MSG.Abort, fnAbortPMSwap, STATE.Idle);
  316. //Extend
  317. Transition(STATE.Idle, MSG.Extend, FnStartExtend, STATE.Extending);
  318. Transition(STATE.Extending, FSM_MSG.TIMER, FnExtend, STATE.Idle);
  319. Transition(STATE.Extending, MSG.Abort, FnAbortExtend, STATE.Idle);
  320. //Retract
  321. Transition(STATE.Idle, MSG.Retract, FnStartRetract, STATE.Retracting);
  322. Transition(STATE.Retracting, FSM_MSG.TIMER, FnRetract, STATE.Idle);
  323. Transition(STATE.Retracting, MSG.Abort, FnAbortRetract, STATE.Idle);
  324. //Control Pressure
  325. AnyStateTransition(FSM_MSG.TIMER, ControlPressureTimer_Elapsed, FSM_STATE.SAME);
  326. Running = true;
  327. }
  328. private bool RobotGoto(object[] param)
  329. {
  330. return _robot.Goto((ModuleName)param[0], (int)param[1], (Hand)param[2]);
  331. }
  332. private bool FnStartExtend(object[] param)
  333. {
  334. return _pmExtendRoutine.Start(param) == RState.Running;
  335. }
  336. private bool FnExtend(object[] param)
  337. {
  338. RState ret = _pmExtendRoutine.Monitor();
  339. if (ret == RState.Failed || ret == RState.Timeout)
  340. {
  341. PostMsg(MSG.Error);
  342. return false;
  343. }
  344. return ret == RState.End;
  345. }
  346. private bool FnAbortExtend(object[] param)
  347. {
  348. _pmExtendRoutine.Abort();
  349. return true;
  350. }
  351. private bool FnStartRetract(object[] param)
  352. {
  353. return _pmRetractRoutine.Start(param) == RState.Running;
  354. }
  355. private bool FnRetract(object[] param)
  356. {
  357. RState ret = _pmRetractRoutine.Monitor();
  358. if (ret == RState.Failed || ret == RState.Timeout)
  359. {
  360. PostMsg(MSG.Error);
  361. return false;
  362. }
  363. return ret == RState.End;
  364. }
  365. private bool FnAbortRetract(object[] param)
  366. {
  367. _pmRetractRoutine.Abort();
  368. return true;
  369. }
  370. private bool fnAbortPMSwap(object[] param)
  371. {
  372. _pmswaproutine.Abort();
  373. return true;
  374. }
  375. private bool fnPMSwapTimeout(object[] param)
  376. {
  377. RState ret = _pmswaproutine.Monitor();
  378. if (ret == RState.Failed || ret == RState.Timeout)
  379. {
  380. PostMsg(MSG.Error);
  381. return false;
  382. }
  383. return ret == RState.End;
  384. }
  385. private bool fnStartPMSwap(object[] param)
  386. {
  387. return _pmswaproutine.Start(param) == RState.Running;
  388. }
  389. private bool fnAbortSwap(object[] param)
  390. {
  391. _swaproutine.Abort();
  392. return true;
  393. }
  394. private bool fnSwapTimeout(object[] param)
  395. {
  396. RState ret = _swaproutine.Monitor();
  397. if (ret == RState.Failed || ret == RState.Timeout)
  398. {
  399. PostMsg(MSG.Error);
  400. return false;
  401. }
  402. return ret == RState.End;
  403. }
  404. private bool fnStartSwap(object[] param)
  405. {
  406. return _swaproutine.Start(param) == RState.Running;
  407. }
  408. private bool fnStartAlign(object[] param)
  409. {
  410. if (float.TryParse(param[0].ToString(), out float angle))
  411. {
  412. return _vpa.Align();
  413. }
  414. else
  415. {
  416. LOG.Write(eEvent.ERR_TM,ModuleName.VPA,$"wrong angle, value is {param[0]}.");
  417. return false;
  418. }
  419. }
  420. private bool fnAlignTimeout(object[] param)
  421. {
  422. if (_vpa.Status == RState.End)
  423. {
  424. return true;
  425. }
  426. else if (_vpa.Status != RState.Running)
  427. {
  428. LOG.Write(eEvent.ERR_TM, ModuleName.VPA, $"PreAligner align failed: {_vpa.Status}");
  429. return true;
  430. }
  431. return false;
  432. }
  433. private bool fnAbortAlign(object[] param)
  434. {
  435. return true;
  436. }
  437. private bool fnAbortPMPlace(object[] param)
  438. {
  439. _placepmRoutine.Abort();
  440. return true;
  441. }
  442. private bool fnPMPlaceTimeout(object[] param)
  443. {
  444. RState ret = _placepmRoutine.Monitor();
  445. if (ret == RState.Failed || ret == RState.Timeout)
  446. {
  447. PostMsg(MSG.Error);
  448. return false;
  449. }
  450. return ret == RState.End;
  451. }
  452. private bool fnStartPMPlace(object[] param)
  453. {
  454. return _placepmRoutine.Start(param) == RState.Running;
  455. }
  456. private bool fnAbortPMPick(object[] param)
  457. {
  458. _pickpmRoutine.Abort();
  459. return true;
  460. }
  461. private bool fnPMPickTimeout(object[] param)
  462. {
  463. RState ret = _pickpmRoutine.Monitor();
  464. if (ret == RState.Failed || ret == RState.Timeout)
  465. {
  466. PostMsg(MSG.Error);
  467. return false;
  468. }
  469. return ret == RState.End;
  470. }
  471. private bool fnStartPMPick(object[] param)
  472. {
  473. return _pickpmRoutine.Start(param) == RState.Running;
  474. }
  475. private bool fnAbortVent(object[] param)
  476. {
  477. _ventRoutine.Abort();
  478. return true;
  479. }
  480. private bool fnVentTimeout(object[] param)
  481. {
  482. RState ret = _ventRoutine.Monitor();
  483. if (ret == RState.Failed || ret == RState.Timeout)
  484. {
  485. _ventRoutine.Abort();
  486. PostMsg(MSG.Error);
  487. return false;
  488. }
  489. return ret == RState.End;
  490. }
  491. private bool fnStartVent(object[] param)
  492. {
  493. return _ventRoutine.Start(param) == RState.Running;
  494. }
  495. private bool fnAbortPump(object[] param)
  496. {
  497. _pumpRoutine.Abort();
  498. return true;
  499. }
  500. private bool fnPumpTimeout(object[] param)
  501. {
  502. RState ret = _pumpRoutine.Monitor();
  503. if (ret == RState.Failed || ret == RState.Timeout)
  504. {
  505. _pumpRoutine.Abort();
  506. PostMsg(MSG.Error);
  507. return false;
  508. }
  509. return ret == RState.End;
  510. }
  511. private bool fnStartPump(object[] param)
  512. {
  513. return _pumpRoutine.Start(param) == RState.Running;
  514. }
  515. private bool fnAbortPlace(object[] param)
  516. {
  517. return true;
  518. }
  519. private bool fnPlaceTimeout(object[] param)
  520. {
  521. RState ret = _placeRoutine.Monitor();
  522. if (ret == RState.Failed || ret == RState.Timeout)
  523. {
  524. PostMsg(MSG.Error);
  525. return false;
  526. }
  527. return ret == RState.End;
  528. }
  529. private bool fnStartPlace(object[] param)
  530. {
  531. return _placeRoutine.Start(param) == RState.Running;
  532. }
  533. private bool fnAbortPick(object[] param)
  534. {
  535. _pickRoutine.Abort();
  536. return true;
  537. }
  538. private bool fnStartPick(object[] param)
  539. {
  540. return _pickRoutine.Start(param) == RState.Running;
  541. }
  542. private bool fnPickTimeout(object[] param)
  543. {
  544. RState ret = _pickRoutine.Monitor();
  545. if (ret == RState.Failed || ret == RState.Timeout)
  546. {
  547. PostMsg(MSG.Error);
  548. return false;
  549. }
  550. return ret == RState.End;
  551. }
  552. private bool fnAbortHome(object[] param)
  553. {
  554. _homeRoutine.Abort();
  555. return true;
  556. }
  557. private bool fnHome(object[] param)
  558. {
  559. if (fsm.State == (int)STATE.Init && param.Length > 0)//带参home
  560. {
  561. return false;
  562. }
  563. else
  564. return _homeRoutine.Start(param) == RState.Running;
  565. }
  566. private bool fnHomeTimeout(object[] param)
  567. {
  568. RState ret = _homeRoutine.Monitor();
  569. if (ret == RState.Failed || ret == RState.Timeout)
  570. {
  571. PostMsg(MSG.Error);
  572. return false;
  573. }
  574. return ret == RState.End;
  575. }
  576. private bool fnOffline(object[] param)
  577. {
  578. //IsOnline = false;
  579. //return true;
  580. throw new NotImplementedException();
  581. }
  582. private bool fnOnline(object[] param)
  583. {
  584. //IsOnline = true;
  585. //return true;
  586. throw new NotImplementedException();
  587. }
  588. private bool fnError(object[] param)
  589. {
  590. return true;
  591. }
  592. private bool ControlPressureTimer_Elapsed(object[] param)
  593. {
  594. if (RouteManager.IsATMMode)
  595. return true;
  596. if (IsOnline && _tm.PumpingState == PumpState.Idle)
  597. {
  598. if (SC.GetValue<bool>($"{_module}.PressureControl.ControlWriteMode"))
  599. {
  600. SC.SetItemValue($"{_module}.PressureControl.ControlWriteMode", false);
  601. }
  602. }
  603. else
  604. {
  605. if (!SC.GetValue<bool>($"{_module}.PressureControl.ControlWriteMode"))
  606. {
  607. SC.SetItemValue($"{_module}.PressureControl.ControlWriteMode", true);
  608. }
  609. }
  610. return true;
  611. }
  612. public bool Check(int msg, out string reason, params object[] args)
  613. {
  614. reason = "";
  615. return true;
  616. }
  617. public bool CheckAcked(int msg)
  618. {
  619. return fsm.CheckExecuted(msg);
  620. }
  621. public bool CheckToPostMessage(int msg, params object[] args)
  622. {
  623. if (!fsm.FindTransition(fsm.State, msg))
  624. {
  625. LOG.Write(eEvent.WARN_FSM_WARN, _module, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  626. return false;
  627. }
  628. Running = true;
  629. fsm.PostMsg(msg, args);
  630. return true;
  631. }
  632. public int Invoke(string function, params object[] args)
  633. {
  634. switch (function)
  635. {
  636. case "Home":
  637. CheckToPostMessage((int)MSG.Home);
  638. return (int)MSG.Home;
  639. }
  640. return (int)FSM_MSG.NONE;
  641. }
  642. }
  643. }