SRDEntity.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Fsm;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.RecipeCenter;
  8. using Aitex.Core.Util;
  9. using Aitex.Core.Utilities;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.RecipeCenter;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using CyberX8_Core;
  14. using CyberX8_RT.Devices.AXIS;
  15. using CyberX8_RT.Devices.SRD;
  16. using CyberX8_RT.Modules.Transporter;
  17. using System;
  18. using MECF.Framework.Common.Persistent.SRD;
  19. using MECF.Framework.Common.ToolLayout;
  20. using CyberX8_RT.Modules.Dryer;
  21. using MECF.Framework.Common.Alarm;
  22. using MECF.Framework.Common.CommonData;
  23. using CyberX8_RT.Modules.Loader;
  24. namespace CyberX8_RT.Modules.SRD
  25. {
  26. public class SRDEntity : Entity, IEntity, IModuleEntity
  27. {
  28. #region 常量
  29. private const string AUTO = "Auto";
  30. private const string MANUAL = "Manual";
  31. private const string DISABLED = "Disabled";
  32. private const string ENGINEERING = "Engineering";
  33. private const string PRODUCTION = "Production";
  34. #endregion
  35. #region 内部变量
  36. /// <summary>
  37. /// 是否Homed
  38. /// </summary>
  39. private bool _isHomed;
  40. /// <summary>
  41. /// rotation电机
  42. /// </summary>
  43. private JetAxisBase _rotationAxis;
  44. /// <summary>
  45. /// arm电机
  46. /// </summary>
  47. private JetAxisBase _armAxis;
  48. /// <summary>
  49. /// IsPresenceTesting
  50. /// </summary>
  51. private bool _isPresenceTesting = false;
  52. /// <summary>
  53. /// IsAWCCycling
  54. /// </summary>
  55. private bool _isAWCCycling = false;
  56. /// <summary>
  57. /// 当前Recipe
  58. /// </summary>
  59. private SrdRecipe _currentRecipe = null;
  60. /// <summary>
  61. /// 持久化对象
  62. /// </summary>
  63. private SRDPersistentValue _persistentValue;
  64. /// <summary>
  65. /// run recipe start time
  66. /// </summary>
  67. private DateTime _runRecipeStartTime;
  68. /// <summary>
  69. /// run recipe complete time
  70. /// </summary>
  71. private DateTime _runRecipeCompleteTime;
  72. #endregion
  73. #region Routine
  74. /// <summary>
  75. /// SRD Home
  76. /// </summary>
  77. private SRDHomeRoutine _homeRoutine;
  78. /// <summary>
  79. /// SRD初始化Home Routine
  80. /// </summary>
  81. private SRDInitializeHomeRoutine _initializeHomeRoutine;
  82. /// <summary>
  83. /// SRD SwicthOn
  84. /// </summary>
  85. private SRDSwitchOnRoutine _switchOnRoutine;
  86. /// <summary>
  87. /// SRD SwicthOff
  88. /// </summary>
  89. private SRDSwitchOffRoutine _switchOffRoutine;
  90. /// <summary>
  91. /// SRD Initialize
  92. /// </summary>
  93. private SRDInitializeRoutine _initializeRoutine;
  94. /// <summary>
  95. /// SRD Common Device
  96. /// </summary>
  97. private SrdCommonDevice _srdCommon;
  98. /// <summary>
  99. /// SRD GoToPosition
  100. /// </summary>
  101. private SRDPositionRoutine _positionRoutine;
  102. /// <summary>
  103. /// SRD StartRotation
  104. /// </summary>
  105. private SRDRotationRoutine _rotationRoutine;
  106. /// <summary>
  107. /// SRD PresenceTest
  108. /// </summary>
  109. private SRDPresenceTestRoutine _presenceTestRoutine;
  110. /// <summary>
  111. /// SRD ProcessRecipe
  112. /// </summary>
  113. private SRDProcessRecipeRoutine _processRecipeRoutine;
  114. /// <summary>
  115. /// SRD AWC Cycle
  116. /// </summary>
  117. private SRDAWCCycleRoutine _awcCycleRoutine;
  118. /// <summary>
  119. /// SRD Process Error
  120. /// </summary>
  121. private SRDProcessErrorRoutine _processErrorRoutine;
  122. /// <summary>
  123. /// RecipeCycle
  124. /// </summary>
  125. private int _cycle = 0;
  126. /// <summary>
  127. /// recipe时长
  128. /// </summary>
  129. private int _recipeTime;
  130. #endregion
  131. #region 属性
  132. /// <summary>
  133. /// 模块名称
  134. /// </summary>
  135. public ModuleName Module { get; private set; }
  136. /// <summary>
  137. /// 初始化状态
  138. /// </summary>
  139. public bool IsInit
  140. {
  141. get { return fsm.State == (int)SRDState.Init; }
  142. }
  143. /// <summary>
  144. /// 空闲状态
  145. /// </summary>
  146. public bool IsIdle
  147. {
  148. get
  149. {
  150. return fsm.State == (int)SRDState.Idle;
  151. }
  152. }
  153. /// <summary>
  154. /// 当前状态机状态
  155. /// </summary>
  156. public int State { get { return fsm.State; } }
  157. /// <summary>
  158. /// 是否发生错误
  159. /// </summary>
  160. public bool IsError
  161. {
  162. get { return fsm.State == (int)SRDState.Error; }
  163. }
  164. /// <summary>
  165. /// 是否正在作业
  166. /// </summary>
  167. public bool IsBusy
  168. {
  169. get { return !IsInit && !IsError && !IsIdle; }
  170. }
  171. /// <summary>
  172. /// 是否已Home
  173. /// </summary>
  174. public bool IsHomed
  175. {
  176. get { return _isHomed; }
  177. }
  178. /// <summary>
  179. /// 是否正在用水
  180. /// </summary>
  181. public bool IsUsingWater
  182. {
  183. get { return _processRecipeRoutine.IsUsingWater; }
  184. }
  185. /// <summary>
  186. /// SRD门是否关闭
  187. /// </summary>
  188. public bool IsSrdDoorClosed
  189. {
  190. get { return !_srdCommon.CommonData.DoorOpened && _srdCommon.CommonData.DoorClosed; }
  191. }
  192. /// <summary>
  193. /// SRD真空是否开启
  194. /// </summary>
  195. public bool IsSrdChuckVacuum
  196. {
  197. get { return _srdCommon.CommonData.ChuckVacuum; }
  198. }
  199. /// <summary>
  200. /// 是否禁用
  201. /// </summary>
  202. public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
  203. /// <summary>
  204. /// 自动模式
  205. /// </summary>
  206. public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
  207. /// <summary>
  208. /// 自动模式
  209. /// </summary>
  210. public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
  211. /// <summary>
  212. /// Arm是否SwitchOn
  213. /// </summary>
  214. public bool IsArmSwitchOn
  215. {
  216. get { return _armAxis.IsSwitchOn; }
  217. }
  218. /// <summary>
  219. /// Rotation是否SwitchOn
  220. /// </summary>
  221. public bool IsRotationSwitchOn
  222. {
  223. get { return _rotationAxis.IsSwitchOn; }
  224. }
  225. /// <summary>
  226. /// 已完成的RunRecipeCycle次数
  227. /// </summary>
  228. public int AchievedCycle { get { return _processRecipeRoutine.AchievedCycle; } }
  229. /// <summary>
  230. /// PresenceTest状态
  231. /// </summary>
  232. public bool IsPresenceTesting
  233. {
  234. get { return _isPresenceTesting; }
  235. }
  236. /// <summary>
  237. /// AWCCycle状态
  238. /// </summary>
  239. public bool IsAWCCycling
  240. {
  241. get { return _isAWCCycling; }
  242. }
  243. /// <summary>
  244. /// 当前状态机
  245. /// </summary>
  246. public string CurrentStateMachine
  247. {
  248. get { return GetCurrentStateMachine(); }
  249. }
  250. /// <summary>
  251. /// 是否为工程模式
  252. /// </summary>
  253. public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
  254. /// <summary>
  255. /// 是否为产品模式
  256. /// </summary>
  257. public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
  258. #endregion
  259. /// <summary>
  260. /// 构造函数
  261. /// </summary>
  262. /// <param name="module"></param>
  263. public SRDEntity(ModuleName module)
  264. {
  265. this.Module = module;
  266. _armAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Arm");
  267. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Rotation");
  268. WaferManager.Instance.SubscribeLocation(Module, 1);
  269. InitialFsm();
  270. }
  271. /// <summary>
  272. /// 总初始化
  273. /// </summary>
  274. /// <returns></returns>
  275. protected override bool Init()
  276. {
  277. _srdCommon = DEVICE.GetDevice<SrdCommonDevice>($"{Module}.Common");
  278. InitializeParameter();
  279. InitialDATA();
  280. InitialRoutine();
  281. InitialOperation();
  282. return true;
  283. }
  284. /// <summary>
  285. /// 初始化参数
  286. /// </summary>
  287. private void InitializeParameter()
  288. {
  289. _persistentValue = SRDPersistentManager.Instance.GetModulePersistentValue(Module.ToString());
  290. if (_persistentValue == null)
  291. {
  292. LOG.WriteLog(eEvent.ERR_SRD, Module.ToString(), "Persistent Value Object is not exist");
  293. }
  294. }
  295. /// <summary>
  296. /// 初始化数据
  297. /// </summary>
  298. private void InitialDATA()
  299. {
  300. DATA.Subscribe($"{Module}.FsmState", () => ((SRDState)fsm.State).ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  301. DATA.Subscribe($"{Module}.IsHomed", () => _isHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  302. DATA.Subscribe($"{Module}.IsError", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  303. DATA.Subscribe($"{Module}.SrdDoorClosed", () => IsSrdDoorClosed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  304. DATA.Subscribe($"{Module}.AchievedCycle", () => AchievedCycle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  305. DATA.Subscribe($"{Module}.IsPresenceTesting", () => IsPresenceTesting, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  306. DATA.Subscribe($"{Module}.CurrentStateMachine", () => CurrentStateMachine, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  307. DATA.Subscribe($"{Module}.IsAWCCycling", () => IsAWCCycling, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  308. DATA.Subscribe($"{Module}.CurrentRecipe", () => _currentRecipe != null ? _currentRecipe.Ppid : "", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  309. DATA.Subscribe($"{Module}.TotalTime", () => _recipeTime, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  310. DATA.Subscribe($"{Module}.TimeRemain", () => CalculateTimeRemain(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  311. DATA.Subscribe($"{Module}.OperatingMode", () => _persistentValue != null ? _persistentValue.OperatingMode : "None", SubscriptionAttribute.FLAG.IgnoreSaveDB);
  312. }
  313. /// <summary>
  314. /// 初始化状态机
  315. /// </summary>
  316. private void InitialFsm()
  317. {
  318. fsm = new StateMachine<SRDEntity>(Module.ToString(), (int)SRDState.Init, 20);
  319. fsm.EnableRepeatedMsg(true);
  320. AnyStateTransition(SRDMSG.Error, EnterError, SRDState.Error);
  321. Transition(SRDState.Error, SRDMSG.ResumeError, (param) => { return true; }, SRDState.Init);
  322. //Initialized
  323. AnyStateTransition(SRDMSG.Initialize, InitializeAll, SRDState.Initializing);
  324. Transition(SRDState.Initializing, FSM_MSG.TIMER, InitializeAllTimeout, SRDState.Initialized);
  325. //SwitchOn
  326. Transition(SRDState.Init, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
  327. Transition(SRDState.Idle, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
  328. Transition(SRDState.Error, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
  329. Transition(SRDState.Initialized, SRDMSG.SwitchOn, SwitchOnAll, SRDState.SwitchOning);
  330. Transition(SRDState.SwitchOning, FSM_MSG.TIMER, SwitchOnTimeout, SRDState.Init);
  331. //SwitchOff
  332. Transition(SRDState.Init, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
  333. Transition(SRDState.Idle, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
  334. Transition(SRDState.Error, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
  335. Transition(SRDState.Initialized, SRDMSG.SwitchOff, SwitchOffAll, SRDState.SwitchOffing);
  336. Transition(SRDState.SwitchOffing, FSM_MSG.TIMER, SwitchOffTimeout, SRDState.Init);
  337. // Home
  338. Transition(SRDState.Init, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  339. Transition(SRDState.Initialized, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  340. Transition(SRDState.Error, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  341. Transition(SRDState.Idle, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  342. Transition(SRDState.Abort, SRDMSG.HomeAll, HomeAll, SRDState.Homing);
  343. Transition(SRDState.Homing, FSM_MSG.TIMER, HomingTimeout, SRDState.Idle);
  344. //Initialize Home
  345. Transition(SRDState.Init, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
  346. Transition(SRDState.Error, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
  347. Transition(SRDState.InitializeHoming, FSM_MSG.TIMER, InitializeHomeTimeout, SRDState.Idle);
  348. Transition(SRDState.Abort, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
  349. Transition(SRDState.Idle, SRDMSG.InitializeHome, InitializeHome, SRDState.InitializeHoming);
  350. //Process Recipe
  351. Transition(SRDState.Idle, SRDMSG.ProcessRecipe, ProcessRecipe, SRDState.ProcessReciping);
  352. Transition(SRDState.ProcessReciping, FSM_MSG.TIMER, ProcessRecipeTimeout, SRDState.Idle);
  353. Transition(SRDState.ProcessReciping, SRDMSG.ProcessError, ProcessError, SRDState.ProcessError);
  354. Transition(SRDState.ProcessError, FSM_MSG.TIMER, ProcessErrorMonitor, SRDState.Error);
  355. //GoToSavedPosition
  356. Transition(SRDState.Idle, SRDMSG.GoToSavedPosition, GotoPosition, SRDState.Positioning);
  357. Transition(SRDState.Positioning, FSM_MSG.TIMER, GotoPositionTimeout, SRDState.Idle);
  358. //StartRotation
  359. Transition(SRDState.Idle, SRDMSG.StartRotation, StartRotation, SRDState.Rotating);
  360. Transition(SRDState.Rotating, FSM_MSG.TIMER, RotationTimeout, SRDState.Idle);
  361. //StopRotation
  362. Transition(SRDState.Rotating, SRDMSG.StopRotation, StopRotation, SRDState.Stopping);
  363. Transition(SRDState.Stopping, FSM_MSG.TIMER, StopRotationTimeout, SRDState.Idle);
  364. //Abort
  365. Transition(SRDState.ProcessReciping, SRDMSG.Abort, AbortProcessRecipe, SRDState.Abort);
  366. Transition(SRDState.PresenceTesting, SRDMSG.Abort, AbortPresenceTest, SRDState.Abort);
  367. Transition(SRDState.AWCCycling, SRDMSG.Abort, AbortAWCCycle, SRDState.Abort);
  368. //PresenceTestStart
  369. Transition(SRDState.Idle, SRDMSG.PresenceTestStart, PresenceTest, SRDState.PresenceTesting);
  370. Transition(SRDState.PresenceTesting, FSM_MSG.TIMER, PresenceTestTimeout, SRDState.Idle);
  371. //AWC Cycle
  372. Transition(SRDState.Idle, SRDMSG.AWCCycleStart, AWCCycle, SRDState.AWCCycling);
  373. Transition(SRDState.AWCCycling, FSM_MSG.TIMER, AWCCycleTimeout, SRDState.Idle);
  374. Transition(SRDState.AWCCycling, SRDMSG.HomeAll, HomeAll, SRDState.AWCHoming);
  375. Transition(SRDState.AWCHoming, FSM_MSG.TIMER, HomingTimeout, SRDState.AWCCycling);
  376. //Retry
  377. Transition(SRDState.Error, SRDMSG.Retry, NullFunc, SRDState.Retrying);
  378. Transition(SRDState.Retrying, FSM_MSG.TIMER, SRDRetry, SRDState.Retrying);
  379. Transition(SRDState.Retrying, SRDMSG.ProcessRecipe, RetryRunRecipe, SRDState.ProcessReciping);
  380. //ConfirmComplete
  381. Transition(SRDState.Init, SRDMSG.ConfirmComplete, ClearModuleAlarm, SRDState.Init);
  382. Transition(SRDState.Idle, SRDMSG.ConfirmComplete, ClearModuleAlarm, SRDState.Idle);
  383. Transition(SRDState.Error, SRDMSG.ConfirmComplete, NullFunc, SRDState.ConfirmCompleting);
  384. Transition(SRDState.ConfirmCompleting, FSM_MSG.TIMER, ConfirmComplete, SRDState.ConfirmCompleting);
  385. Transition(SRDState.ConfirmCompleting, SRDMSG.ProcessRecipe, ConfirmProcessRecipe, SRDState.Idle);
  386. //Enter Init
  387. Transition(SRDState.Idle, SRDMSG.Init, NullFunc, SRDState.Init);
  388. EnumLoop<SRDState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
  389. EnumLoop<SRDMSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
  390. }
  391. /// <summary>
  392. /// 初始化Routine
  393. /// </summary>
  394. private void InitialRoutine()
  395. {
  396. _initializeHomeRoutine = new SRDInitializeHomeRoutine(Module.ToString());
  397. _homeRoutine = new SRDHomeRoutine(Module.ToString());
  398. _switchOnRoutine = new SRDSwitchOnRoutine(Module.ToString());
  399. _switchOffRoutine = new SRDSwitchOffRoutine(Module.ToString());
  400. _initializeRoutine = new SRDInitializeRoutine(Module.ToString());
  401. _positionRoutine = new SRDPositionRoutine(Module);
  402. _rotationRoutine = new SRDRotationRoutine(Module, _rotationAxis);
  403. _presenceTestRoutine = new SRDPresenceTestRoutine(Module.ToString());
  404. _processRecipeRoutine = new SRDProcessRecipeRoutine(Module.ToString(), _rotationAxis, _armAxis, _srdCommon);
  405. _awcCycleRoutine = new SRDAWCCycleRoutine(Module);
  406. _processErrorRoutine=new SRDProcessErrorRoutine(Module.ToString());
  407. }
  408. /// <summary>
  409. /// 初始化操作
  410. /// </summary>
  411. private void InitialOperation()
  412. {
  413. OP.Subscribe($"{Module}.HomeAll", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.HomeAll); });
  414. OP.Subscribe($"{Module}.InitializeHome", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.InitializeHome); });
  415. OP.Subscribe($"{Module}.SwitchOnAll", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.SwitchOn); });
  416. OP.Subscribe($"{Module}.SwitchOffAll", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.SwitchOff); });
  417. OP.Subscribe($"{Module}.CycleManualProcessRecipe", (cmd, args) =>
  418. {
  419. SrdRecipe recipe = RecipeFileManager.Instance.LoadGenericityRecipe<SrdRecipe>(args[0].ToString());
  420. if (recipe == null)
  421. {
  422. LOG.WriteLog(eEvent.ERR_SRD, Module.ToString(), $"{args[0]} recipe is null");
  423. return false;
  424. }
  425. object[] objects = new object[args.Length];
  426. objects[0] = recipe;
  427. for (int i = 1; i < args.Length; i++)
  428. {
  429. objects[i] = args[i];
  430. }
  431. return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ProcessRecipe, objects);
  432. });
  433. //OP.Subscribe($"{Module}.Arm.GotoSavedPosition", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.GoToSavedPosition, "Arm", args); });
  434. //OP.Subscribe($"{Module}.Rotation.GotoSavedPosition", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.GoToSavedPosition, "Rotation", args); });
  435. OP.Subscribe($"{Module}.Abort", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Abort); });
  436. OP.Subscribe($"{Module}.StartRotation", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.StartRotation, "Rotation", args); });
  437. OP.Subscribe($"{Module}.StopRotation", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.StopRotation); });
  438. OP.Subscribe($"{Module}.PresenceTestStart", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.PresenceTestStart, args); });
  439. OP.Subscribe($"{Module}.AWCCycle", (cmd, args) => { return CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.AWCCycleStart, args); });
  440. }
  441. /// <summary>
  442. /// Enter Init
  443. /// </summary>
  444. public void EnterInit()
  445. {
  446. if ((SRDState)fsm.State != SRDState.Idle) return;
  447. else
  448. {
  449. CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Init);
  450. }
  451. }
  452. /// <summary>
  453. /// 进入Error状态
  454. /// </summary>
  455. /// <param name="param"></param>
  456. /// <returns></returns>
  457. private bool EnterError(object[] param)
  458. {
  459. _isHomed = false;
  460. return true;
  461. }
  462. #region Initialized
  463. /// <summary>
  464. /// Initialize
  465. /// </summary>
  466. /// <param name="param"></param>
  467. /// <returns></returns>
  468. private bool InitializeAll(object[] param)
  469. {
  470. if (fsm.State == (int)MetalState.Initializing)
  471. {
  472. LOG.WriteLog(eEvent.WARN_SRD, Module.ToString(), "state is Initializing,cannot do initialize");
  473. return false;
  474. }
  475. return _initializeRoutine.Start() == RState.Running;
  476. }
  477. /// <summary>
  478. /// Initialize 监控
  479. /// </summary>
  480. /// <param name="param"></param>
  481. /// <returns></returns>
  482. private bool InitializeAllTimeout(object[] param)
  483. {
  484. RState ret = _initializeRoutine.Monitor();
  485. if (ret == RState.Failed || ret == RState.Timeout)
  486. {
  487. PostMsg(SRDMSG.Error);
  488. return false;
  489. }
  490. bool result = ret == RState.End;
  491. if (result)
  492. {
  493. _isHomed = false;
  494. }
  495. return result;
  496. }
  497. #endregion
  498. #region Switch On
  499. /// <summary>
  500. /// SwitchAll
  501. /// </summary>
  502. /// <param name="param"></param>
  503. /// <returns></returns>
  504. private bool SwitchOnAll(object[] param)
  505. {
  506. return _switchOnRoutine.Start() == RState.Running;
  507. }
  508. private bool SwitchOnTimeout(object[] param)
  509. {
  510. RState ret = _switchOnRoutine.Monitor();
  511. if (ret == RState.Failed || ret == RState.Timeout)
  512. {
  513. PostMsg(SRDMSG.Error);
  514. return false;
  515. }
  516. bool result = ret == RState.End;
  517. if (result)
  518. {
  519. _isHomed = false;
  520. }
  521. return result;
  522. }
  523. #endregion
  524. #region Switch Off
  525. /// <summary>
  526. /// SwitchAll
  527. /// </summary>
  528. /// <param name="param"></param>
  529. /// <returns></returns>
  530. private bool SwitchOffAll(object[] param)
  531. {
  532. return _switchOffRoutine.Start() == RState.Running;
  533. }
  534. private bool SwitchOffTimeout(object[] param)
  535. {
  536. RState ret = _switchOffRoutine.Monitor();
  537. if (ret == RState.Failed || ret == RState.Timeout)
  538. {
  539. PostMsg(SRDMSG.Error);
  540. return false;
  541. }
  542. bool result = ret == RState.End;
  543. if (result)
  544. {
  545. _isHomed = false;
  546. }
  547. return result;
  548. }
  549. #endregion
  550. #region Home
  551. /// <summary>
  552. /// HomeAll
  553. /// </summary>
  554. /// <param name="param"></param>
  555. /// <returns></returns>
  556. private bool HomeAll(object[] param)
  557. {
  558. _isHomed = false;
  559. return _homeRoutine.Start() == RState.Running;
  560. }
  561. /// <summary>
  562. /// Home超时
  563. /// </summary>
  564. /// <param name="param"></param>
  565. /// <returns></returns>
  566. private bool HomingTimeout(object[] param)
  567. {
  568. RState ret = _homeRoutine.Monitor();
  569. if (ret == RState.Failed || ret == RState.Timeout)
  570. {
  571. PostMsg(SRDMSG.Error);
  572. return false;
  573. }
  574. bool result = ret == RState.End;
  575. if (result)
  576. {
  577. _isHomed = true;
  578. }
  579. return result;
  580. }
  581. #endregion
  582. #region Process Recipe
  583. /// <summary>
  584. /// ProcessRecipe
  585. /// </summary>
  586. /// <param name="param"></param>
  587. /// <returns></returns>
  588. private bool ProcessRecipe(object[] param)
  589. {
  590. SrdRecipe recipe= param[0] as SrdRecipe;
  591. if(param.Length >= 2) _cycle = (int)param[1];
  592. bool result = _processRecipeRoutine.Start(param) == RState.Running;
  593. if (result)
  594. {
  595. if (CellItemRecipeTimeManager.Instance.ContainRecipe(recipe.Ppid))
  596. {
  597. _recipeTime = _cycle * CellItemRecipeTimeManager.Instance.GetRecipeTotalTime(recipe.Ppid);
  598. }
  599. else
  600. {
  601. _recipeTime = 0;
  602. }
  603. _currentRecipe = recipe;
  604. _runRecipeStartTime = DateTime.Now;
  605. FaModuleNotifier.Instance.NotifySRDRecipeStart(Module, recipe.Ppid);
  606. }
  607. return result;
  608. }
  609. /// <summary>
  610. /// ProcessRecipe超时
  611. /// </summary>
  612. /// <param name="param"></param>
  613. /// <returns></returns>
  614. private bool ProcessRecipeTimeout(object[] param)
  615. {
  616. RState ret = _processRecipeRoutine.Monitor();
  617. if (ret == RState.Failed || ret == RState.Timeout)
  618. {
  619. PostMsg(SRDMSG.ProcessError);
  620. //记录LotTrack
  621. _runRecipeCompleteTime = DateTime.Now;
  622. _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  623. SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
  624. _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
  625. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  626. {
  627. AlarmList alarmList = new AlarmList(Module.ToString(), ((SRDState)fsm.State).ToString(), (int)SRDMSG.ProcessRecipe,
  628. _processRecipeRoutine.ErrorMsg, _processRecipeRoutine.ErrorStep, (int)AlarmType.Error);
  629. AlarmListManager.Instance.AddAlarm(alarmList);
  630. }
  631. if (_currentRecipe != null)
  632. {
  633. FaModuleNotifier.Instance.NotifySRDRecipeFailed(Module, _currentRecipe.Ppid);
  634. }
  635. return false;
  636. }
  637. bool result = ret == RState.End;
  638. if (result)
  639. {
  640. double elapsedMilliseconds = _processRecipeRoutine.ElapsedMilliseconds;
  641. int recipeTime = (int)Math.Floor(elapsedMilliseconds / _cycle / 1000);
  642. CellItemRecipeTimeManager.Instance.UpdateRecipeTime(_currentRecipe.Ppid, recipeTime);
  643. //记录LotTrack
  644. _runRecipeCompleteTime = DateTime.Now;
  645. _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  646. SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
  647. _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
  648. if (_currentRecipe != null)
  649. {
  650. FaModuleNotifier.Instance.NotifySRDRecipeEnd(Module, _currentRecipe.Ppid);
  651. }
  652. _currentRecipe = null;
  653. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), SRDState.ProcessReciping.ToString());
  654. }
  655. return result;
  656. }
  657. /// <summary>
  658. /// Abort Recipe
  659. /// </summary>
  660. /// <param name="param"></param>
  661. /// <returns></returns>
  662. private bool AbortProcessRecipe(object[] param)
  663. {
  664. _processRecipeRoutine.Abort();
  665. //记录LotTrack
  666. _runRecipeCompleteTime = DateTime.Now;
  667. _processRecipeRoutine.SRDLotTrackHeaderDatas.ProcessTime = (_runRecipeCompleteTime - _runRecipeStartTime).TotalSeconds.ToString("F2");
  668. SRDLotTrackUtil.ExportSRDLotTrack(Module.ToString(), _processRecipeRoutine.SRDLotTrackDatas,
  669. _processRecipeRoutine.SRDLotTrackHeaderDatas, IsAuto);
  670. return true;
  671. }
  672. /// <summary>
  673. /// 计算剩余时间
  674. /// </summary>
  675. /// <returns></returns>
  676. private double CalculateTimeRemain()
  677. {
  678. if (IsBusy)
  679. {
  680. return _recipeTime != 0 ? (_recipeTime - Math.Floor((double)_processRecipeRoutine.ElapsedMilliseconds / 1000)) : 0;
  681. }
  682. else
  683. {
  684. return 0;
  685. }
  686. }
  687. /// <summary>
  688. /// ProcessError
  689. /// </summary>
  690. /// <param name="param"></param>
  691. /// <returns></returns>
  692. private bool ProcessError(object[] param)
  693. {
  694. return _processErrorRoutine.Start(param)==RState.Running;
  695. }
  696. /// <summary>
  697. /// Process Error监控
  698. /// </summary>
  699. /// <param name="param"></param>
  700. /// <returns></returns>
  701. private bool ProcessErrorMonitor(object[] param)
  702. {
  703. RState state = _processErrorRoutine.Monitor();
  704. if (state == RState.End||state==RState.Failed||state==RState.Timeout)
  705. {
  706. return true;
  707. }
  708. return false;
  709. }
  710. /// <summary>
  711. /// Retry RunRecipe
  712. /// </summary>
  713. /// <param name="param"></param>
  714. /// <returns></returns>
  715. private bool RetryRunRecipe(object[] param)
  716. {
  717. int stepIndex = (int)param[0];
  718. bool result = _processRecipeRoutine.Retry(stepIndex) == RState.Running;
  719. if (result)
  720. {
  721. if (_currentRecipe != null)
  722. {
  723. if (CellItemRecipeTimeManager.Instance.ContainRecipe(_currentRecipe.Ppid))
  724. {
  725. _recipeTime = _cycle * CellItemRecipeTimeManager.Instance.GetRecipeTotalTime(_currentRecipe.Ppid);
  726. }
  727. else
  728. {
  729. _recipeTime = 0;
  730. }
  731. _runRecipeStartTime = DateTime.Now;
  732. }
  733. }
  734. return result;
  735. }
  736. /// <summary>
  737. /// 确认ProcessRecipe是否完成
  738. /// </summary>
  739. /// <param name="param"></param>
  740. /// <returns></returns>
  741. private bool ConfirmProcessRecipe(object[] param)
  742. {
  743. int stepIdex = (int)param[0];
  744. bool result = _processRecipeRoutine.CheckCompleteCondition(stepIdex);
  745. if (!result)
  746. {
  747. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  748. {
  749. AlarmList alarmList = new AlarmList(Module.ToString(), ((SRDState)fsm.State).ToString(), (int)SRDMSG.ProcessRecipe,
  750. _processRecipeRoutine.ErrorMsg, _processRecipeRoutine.ErrorStep, (int)AlarmType.Error);
  751. AlarmListManager.Instance.AddAlarm(alarmList);
  752. }
  753. PostMsg(SRDMSG.Error);
  754. }
  755. else
  756. {
  757. if (Singleton<RouteManager>.Instance.IsAutoRunning)
  758. {
  759. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), SRDState.ProcessReciping.ToString());
  760. }
  761. }
  762. return result;
  763. }
  764. #endregion
  765. #region AWC Cycle
  766. /// <summary>
  767. /// AWC Cycle
  768. /// </summary>
  769. /// <returns></returns>
  770. private bool AWCCycle(object[] param)
  771. {
  772. return _awcCycleRoutine.Start(param) == RState.Running;
  773. }
  774. /// <summary>
  775. /// AWC Cycle超时
  776. /// </summary>
  777. /// <param name="param"></param>
  778. /// <returns></returns>
  779. private bool AWCCycleTimeout(object[] param)
  780. {
  781. RState ret = _awcCycleRoutine.Monitor();
  782. if (ret == RState.Failed || ret == RState.Timeout)
  783. {
  784. _isAWCCycling = false;
  785. PostMsg(SRDMSG.Error);
  786. return false;
  787. }
  788. //设置IsPresenceTesting
  789. if (ret == RState.Running)
  790. {
  791. _isAWCCycling = true;
  792. }
  793. else
  794. {
  795. _isAWCCycling = false;
  796. }
  797. return ret == RState.End;
  798. }
  799. /// <summary>
  800. /// Abort AWC Cycle
  801. /// </summary>
  802. /// <param name="param"></param>
  803. /// <returns></returns>
  804. private bool AbortAWCCycle(object[] param)
  805. {
  806. _awcCycleRoutine.Abort();
  807. return true;
  808. }
  809. #endregion
  810. #region InitializeHome
  811. /// <summary>
  812. /// InitializeHome
  813. /// </summary>
  814. /// <param name="param"></param>
  815. /// <returns></returns>
  816. private bool InitializeHome(object[] param)
  817. {
  818. _isHomed = false;
  819. return _initializeHomeRoutine.Start() == RState.Running;
  820. }
  821. /// <summary>
  822. /// InitializeHome超时
  823. /// </summary>
  824. /// <param name="param"></param>
  825. /// <returns></returns>
  826. private bool InitializeHomeTimeout(object[] param)
  827. {
  828. RState ret = _initializeHomeRoutine.Monitor();
  829. if (ret == RState.Failed || ret == RState.Timeout)
  830. {
  831. PostMsg(SRDMSG.Error);
  832. return false;
  833. }
  834. bool result = ret == RState.End;
  835. if (result)
  836. {
  837. _isHomed = true;
  838. }
  839. return result;
  840. }
  841. #endregion
  842. #region RunRecipeRetry
  843. /// <summary>
  844. /// Retry
  845. /// </summary>
  846. /// <param name="param"></param>
  847. /// <returns></returns>
  848. private bool SRDRetry(object[] param)
  849. {
  850. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  851. if (alarmList != null)
  852. {
  853. CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), alarmList.ModuleCmd,
  854. alarmList.ModuleStep);
  855. }
  856. return false;
  857. }
  858. #endregion
  859. #region ConfirmComplete
  860. /// <summary>
  861. /// 确认是否完成
  862. /// </summary>
  863. /// <param name="param"></param>
  864. /// <returns></returns>
  865. private bool ConfirmComplete(object[] param)
  866. {
  867. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  868. if (alarmList != null)
  869. {
  870. if (alarmList.ModuleState == SRDState.ProcessReciping.ToString())
  871. {
  872. CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ProcessRecipe, alarmList.ModuleStep);
  873. }
  874. else
  875. {
  876. PostMsg(SRDState.Error);
  877. }
  878. }
  879. return false;
  880. }
  881. /// <summary>
  882. /// 清除报警
  883. /// </summary>
  884. /// <param name="param"></param>
  885. /// <returns></returns>
  886. private bool ClearModuleAlarm(object[] param)
  887. {
  888. AlarmList alarmList = AlarmListManager.Instance.GetAlarmListByModule(Module.ToString());
  889. if (alarmList != null)
  890. {
  891. AlarmListManager.Instance.CheckModuleAlamAndRemove(Module.ToString(), "");
  892. }
  893. return true;
  894. }
  895. #endregion
  896. public bool Check(int msg, out string reason, params object[] args)
  897. {
  898. reason = "";
  899. return false;
  900. }
  901. public bool CheckAcked(int msg)
  902. {
  903. return false;
  904. }
  905. public int Invoke(string function, params object[] args)
  906. {
  907. switch (function)
  908. {
  909. case "HomeAll":
  910. if (IsIdle)
  911. {
  912. return (int)FSM_MSG.NONE;
  913. }
  914. if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.InitializeHome))
  915. {
  916. return (int)SRDMSG.Initialize;
  917. }
  918. else
  919. {
  920. return (int)FSM_MSG.NONE;
  921. }
  922. case "Retry":
  923. if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.Retry, args))
  924. {
  925. return (int)SRDMSG.Retry;
  926. }
  927. else
  928. {
  929. return (int)FSM_MSG.NONE;
  930. }
  931. case "ConfirmComplete":
  932. if (CheckToPostMessage<SRDState, SRDMSG>(eEvent.ERR_SRD, Module.ToString(), (int)SRDMSG.ConfirmComplete, args))
  933. {
  934. return (int)SRDMSG.ConfirmComplete;
  935. }
  936. else
  937. {
  938. return (int)FSM_MSG.NONE;
  939. }
  940. }
  941. return (int)FSM_MSG.NONE;
  942. }
  943. #region GoToPosition
  944. /// <summary>
  945. /// Go to Position
  946. /// </summary>
  947. /// <param name="param"></param>
  948. /// <returns></returns>
  949. private bool GotoPosition(object[] param)
  950. {
  951. string axis = param[0].ToString();
  952. object[] objs = (object[])param[1];
  953. string position = objs[1].ToString();
  954. var result = CheckGotoPositionPreCondition(axis, position);
  955. if (result.result)
  956. {
  957. return _positionRoutine.Start(result.axis, position) == RState.Running;
  958. }
  959. else
  960. {
  961. return false;
  962. }
  963. }
  964. /// <summary>
  965. /// 检验GotoPosition前置条件
  966. /// </summary>
  967. /// <param name="axis"></param>
  968. /// <param name="position"></param>
  969. /// <returns></returns>
  970. private (bool result, JetAxisBase axis) CheckGotoPositionPreCondition(string axis, string position)
  971. {
  972. switch (axis)
  973. {
  974. case "Rotation":
  975. return (_rotationAxis.CheckGotoPosition(position), _rotationAxis);
  976. case "Arm":
  977. return (_armAxis.CheckGotoPosition(position), _armAxis);
  978. default:
  979. return (false, null);
  980. }
  981. }
  982. /// <summary>
  983. /// GotoPosition超时
  984. /// </summary>
  985. /// <param name="param"></param>
  986. /// <returns></returns>
  987. private bool GotoPositionTimeout(object[] param)
  988. {
  989. RState ret = _positionRoutine.Monitor();
  990. if (ret == RState.Failed || ret == RState.Timeout)
  991. {
  992. return true;
  993. }
  994. return ret == RState.End;
  995. }
  996. #endregion
  997. #region 旋转
  998. /// <summary>
  999. /// 开始旋转
  1000. /// </summary>
  1001. /// <param name="param"></param>
  1002. /// <returns></returns>
  1003. private bool StartRotation(object[] param)
  1004. {
  1005. string axis = param[0].ToString();
  1006. object[] objs = (object[])param[1];
  1007. double time = double.Parse(objs[0].ToString());
  1008. double speed = double.Parse(objs[1].ToString());
  1009. return _rotationRoutine.Start(_rotationAxis, time, speed) == RState.Running;
  1010. }
  1011. /// <summary>
  1012. /// RotationTimeout
  1013. /// </summary>
  1014. /// <param name="param"></param>
  1015. /// <returns></returns>
  1016. private bool RotationTimeout(object[] param)
  1017. {
  1018. RState ret = _rotationRoutine.Monitor();
  1019. if (ret == RState.Failed || ret == RState.Timeout)
  1020. {
  1021. //PostMsg(SRDMSG.Error);
  1022. return true;
  1023. }
  1024. return ret == RState.End;
  1025. }
  1026. /// <summary>
  1027. /// 停止旋转
  1028. /// </summary>
  1029. /// <param name="param"></param>
  1030. /// <returns></returns>
  1031. private bool StopRotation(object[] param)
  1032. {
  1033. _rotationAxis.StopPositionOperation();
  1034. return _rotationAxis.Status == RState.Running;
  1035. }
  1036. /// <summary>
  1037. /// 停止旋转监控
  1038. /// </summary>
  1039. /// <param name="param"></param>
  1040. /// <returns></returns>
  1041. private bool StopRotationTimeout(object[] param)
  1042. {
  1043. RState ret = _rotationAxis.Status;
  1044. if (ret == RState.Failed || ret == RState.Timeout)
  1045. {
  1046. //PostMsg(SRDMSG.Error);
  1047. return true;
  1048. }
  1049. return ret == RState.End;
  1050. }
  1051. #endregion
  1052. #region PresenceTest
  1053. private bool PresenceTest(object[] param)
  1054. {
  1055. _recipeTime = 0;
  1056. return _presenceTestRoutine.Start(param) == RState.Running;
  1057. }
  1058. private bool PresenceTestTimeout(object[] param)
  1059. {
  1060. RState ret = _presenceTestRoutine.Monitor();
  1061. if (ret == RState.Failed || ret == RState.Timeout)
  1062. {
  1063. _isPresenceTesting = false;
  1064. PostMsg(SRDMSG.Error);
  1065. return false;
  1066. }
  1067. //设置IsPresenceTesting
  1068. if (ret == RState.Running)
  1069. {
  1070. _isPresenceTesting = true;
  1071. }
  1072. else
  1073. {
  1074. _isPresenceTesting = false;
  1075. }
  1076. return ret == RState.End;
  1077. }
  1078. /// <summary>
  1079. /// Abort PresenceTest
  1080. /// </summary>
  1081. /// <param name="param"></param>
  1082. /// <returns></returns>
  1083. private bool AbortPresenceTest(object[] param)
  1084. {
  1085. _presenceTestRoutine.Abort();
  1086. return true;
  1087. }
  1088. #endregion
  1089. /// <summary>
  1090. /// 获取当前子状态机
  1091. /// </summary>
  1092. private string GetCurrentStateMachine()
  1093. {
  1094. string state = "";
  1095. switch ((SRDState)fsm.State)
  1096. {
  1097. case SRDState.Init:
  1098. state = "Init";
  1099. break;
  1100. case SRDState.Initializing:
  1101. state = _initializeRoutine.CurrentStateMachine;
  1102. break;
  1103. case SRDState.Homing:
  1104. state = _homeRoutine.CurrentStateMachine;
  1105. break;
  1106. case SRDState.SwitchOning:
  1107. state = _switchOnRoutine.CurrentStateMachine;
  1108. break;
  1109. case SRDState.SwitchOffing:
  1110. state = _switchOffRoutine.CurrentStateMachine;
  1111. break;
  1112. case SRDState.Positioning:
  1113. state = _positionRoutine.CurrentStateMachine;
  1114. break;
  1115. case SRDState.Rotating:
  1116. state = _rotationRoutine.CurrentStateMachine;
  1117. break;
  1118. case SRDState.PresenceTesting:
  1119. state = _presenceTestRoutine.CurrentStateMachine;
  1120. break;
  1121. case SRDState.ProcessReciping:
  1122. state = _processRecipeRoutine.CurrentStateMachine;
  1123. break;
  1124. case SRDState.AWCCycling:
  1125. state = _awcCycleRoutine.CurrentStateMachine;
  1126. break;
  1127. default:
  1128. state = Enum.GetName(typeof(SRDState),fsm.State);
  1129. break;
  1130. }
  1131. return state;
  1132. }
  1133. /// <summary>
  1134. /// 设置IsAWCCycling
  1135. /// </summary>
  1136. /// <param name="flag"></param>
  1137. public void SetIsAWCCycling(bool flag)
  1138. {
  1139. _isAWCCycling = flag;
  1140. }
  1141. }
  1142. public enum SRDMSG
  1143. {
  1144. Initialize,
  1145. InitializeHome,
  1146. ProcessRecipe,
  1147. ResumeError,
  1148. SwitchOn,
  1149. SwitchOff,
  1150. HomeAll,
  1151. Error,
  1152. GoToSavedPosition,
  1153. Abort,
  1154. StartRotation,
  1155. StopRotation,
  1156. PresenceTestStart,
  1157. PresenceTestStop,
  1158. AWCCycleStart,
  1159. Init,
  1160. ProcessError,
  1161. Retry,
  1162. ConfirmComplete
  1163. }
  1164. }