SETMEntity.cs 24 KB

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