SRDEntity.cs 49 KB

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