SafetyNewAllOnRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.Util;
  5. using CyberX8_Core;
  6. using CyberX8_RT.Modules;
  7. using CyberX8_RT.Modules.Loader;
  8. using CyberX8_RT.Modules.PUF;
  9. using CyberX8_RT.Modules.SRD;
  10. using CyberX8_RT.Modules.Transporter;
  11. using MECF.Framework.Common.Beckhoff.ModuleIO;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.Routine;
  14. using MECF.Framework.Common.Utilities;
  15. using System.Runtime.InteropServices;
  16. namespace CyberX8_RT.Devices.Safety
  17. {
  18. internal class SafetyNewAllOnRoutine : RoutineBase, IRoutine
  19. {
  20. private enum SafetyAllOnStep
  21. {
  22. Ready,
  23. SwitchOnProcessTransporter,
  24. WaitSwitchOnProcessTransporter,
  25. SwitchOnLoaderTransporter,
  26. WaitSwitchOnLoaderTransporter,
  27. SwitchOnLoader,
  28. WaitSwitchOnLoader,
  29. SwitchOnPuf1,
  30. WaitSwitchOnPuf1,
  31. SwitchOnPuf2,
  32. WaitSwitchOnPuf2,
  33. SwitchOnSRD1,
  34. WaitSwitchOnSRD1,
  35. SwitchOnSRD2,
  36. WaitSwitchOnSRD2,
  37. End
  38. }
  39. #region 内部变量
  40. private SafetyDevice _device;
  41. private TransporterSwitchOnRoutine _loaderTransporterSwitchOnRoutine;
  42. private TransporterSwitchOnRoutine _processTransporterSwitchOnRoutine;
  43. private LoaderSwitchAllOnRoutine _loaderSwitchAllOnRoutine;
  44. private PufSwitchOnRoutine _puf1SwitchOnRoutine;
  45. private PufSwitchOnRoutine _puf2SwitchOnRoutine;
  46. private SRDSwitchOnRoutine _srd1SwitchOnRoutine;
  47. private SRDSwitchOnRoutine _srd2SwitchOnRoutine;
  48. #endregion
  49. /// <summary>
  50. /// 构造函数
  51. /// </summary>
  52. /// <param name="module"></param>
  53. public SafetyNewAllOnRoutine(string module) : base(module)
  54. {
  55. }
  56. /// <summary>
  57. /// 中止
  58. /// </summary>
  59. public void Abort()
  60. {
  61. Runner.Stop($"Safety All On Abort");
  62. }
  63. /// <summary>
  64. /// 监控
  65. /// </summary>
  66. /// <returns></returns>
  67. public RState Monitor()
  68. {
  69. Runner
  70. .RunIf(SafetyAllOnStep.SwitchOnProcessTransporter,ModuleHelper.IsInstalled(ModuleName.Transporter1),SwitchOnProcessTransporter, _delay_1ms)
  71. .WaitWithStopCondition(SafetyAllOnStep.WaitSwitchOnProcessTransporter, CheckSwitchOnProcessTransporterComplete, CheckSwitchOnProcessTransporterError)
  72. .RunIf(SafetyAllOnStep.SwitchOnLoaderTransporter,ModuleHelper.IsInstalled(ModuleName.Transporter2), SwitchOnLoaderTransporter, _delay_1ms)
  73. .WaitWithStopCondition(SafetyAllOnStep.WaitSwitchOnLoaderTransporter, CheckSwitchOnLoaderTransporterComplete, CheckSwitchOnLoaderTransporterError)
  74. .RunIf(SafetyAllOnStep.SwitchOnPuf1,ModuleHelper.IsInstalled(ModuleName.PUF1), SwitchOnPuf1, _delay_1ms)
  75. .WaitWithStopCondition(SafetyAllOnStep.WaitSwitchOnPuf1, CheckSwitchOnPuf1Complete, CheckSwitchOnPuf1Error)
  76. .RunIf(SafetyAllOnStep.SwitchOnPuf2,ModuleHelper.IsInstalled(ModuleName.PUF2), SwitchOnPuf2, _delay_1ms)
  77. .WaitWithStopCondition(SafetyAllOnStep.WaitSwitchOnPuf2, CheckSwitchOnPuf2Complete, CheckSwitchOnPuf2Error)
  78. .RunIf(SafetyAllOnStep.SwitchOnLoader,ModuleHelper.IsInstalled(ModuleName.Loader1), SwitchOnLoader, _delay_1ms)
  79. .WaitWithStopCondition(SafetyAllOnStep.WaitSwitchOnLoader, CheckSwitchOnLoaderComplete, CheckSwitchOnLoaderError)
  80. .RunIf(SafetyAllOnStep.SwitchOnSRD1, ModuleHelper.IsInstalled(ModuleName.SRD1), SwitchOnSRD1, _delay_1ms)
  81. .WaitWithStopCondition(SafetyAllOnStep.WaitSwitchOnSRD1, CheckSwitchOnSRD1Complete, CheckSwitchOnSRD1Error)
  82. .RunIf(SafetyAllOnStep.SwitchOnSRD2, ModuleHelper.IsInstalled(ModuleName.SRD2), SwitchOnSRD2, _delay_1ms)
  83. .WaitWithStopCondition(SafetyAllOnStep.WaitSwitchOnSRD2, CheckSwitchOnSRD2Complete, CheckSwitchOnSRD2Error)
  84. .End(SafetyAllOnStep.End, NullFun, _delay_1ms);
  85. return Runner.Status;
  86. }
  87. #region ProcessTransporter
  88. /// <summary>
  89. /// Switch on ProcessTransporter Motors
  90. /// </summary>
  91. /// <returns></returns>
  92. private bool SwitchOnProcessTransporter()
  93. {
  94. return _processTransporterSwitchOnRoutine.Start()==RState.Running;
  95. }
  96. /// <summary>
  97. /// 检查ProcessTransporter Motors switchon是否完成
  98. /// </summary>
  99. /// <returns></returns>
  100. private bool CheckSwitchOnProcessTransporterComplete()
  101. {
  102. if (!ModuleHelper.IsInstalled(ModuleName.Transporter1))
  103. {
  104. return true;
  105. }
  106. return CommonFunction.CheckRoutineEndState(_processTransporterSwitchOnRoutine);
  107. }
  108. /// <summary>
  109. /// 检查ProcessTransporter Motors switchon是否出错
  110. /// </summary>
  111. /// <returns></returns>
  112. private bool CheckSwitchOnProcessTransporterError()
  113. {
  114. if (!ModuleHelper.IsInstalled(ModuleName.Transporter1))
  115. {
  116. return false;
  117. }
  118. return CommonFunction.CheckRoutineStopState(_processTransporterSwitchOnRoutine);
  119. }
  120. #endregion
  121. #region LoaderTransporter
  122. /// <summary>
  123. /// Switch on LoaderTransporter Motors
  124. /// </summary>
  125. /// <returns></returns>
  126. private bool SwitchOnLoaderTransporter()
  127. {
  128. return _loaderTransporterSwitchOnRoutine.Start() == RState.Running;
  129. }
  130. /// <summary>
  131. /// 检查LoaderTransporter Motors switchon是否完成
  132. /// </summary>
  133. /// <returns></returns>
  134. private bool CheckSwitchOnLoaderTransporterComplete()
  135. {
  136. if (!ModuleHelper.IsInstalled(ModuleName.Transporter2))
  137. {
  138. return true;
  139. }
  140. return CommonFunction.CheckRoutineEndState(_loaderTransporterSwitchOnRoutine);
  141. }
  142. /// <summary>
  143. /// 检查LoaderTransporter Motors switchon是否出错
  144. /// </summary>
  145. /// <returns></returns>
  146. private bool CheckSwitchOnLoaderTransporterError()
  147. {
  148. if (!ModuleHelper.IsInstalled(ModuleName.Transporter2))
  149. {
  150. return false;
  151. }
  152. return CommonFunction.CheckRoutineStopState(_loaderTransporterSwitchOnRoutine);
  153. }
  154. #endregion
  155. #region Puf1
  156. /// <summary>
  157. /// Switch on Puf1 Motors
  158. /// </summary>
  159. /// <returns></returns>
  160. private bool SwitchOnPuf1()
  161. {
  162. return _puf1SwitchOnRoutine.Start()==RState.Running;
  163. }
  164. /// <summary>
  165. /// 检查Puf1 Motors switchon是否完成
  166. /// </summary>
  167. /// <returns></returns>
  168. private bool CheckSwitchOnPuf1Complete()
  169. {
  170. if (!ModuleHelper.IsInstalled(ModuleName.PUF1))
  171. {
  172. return true;
  173. }
  174. return CommonFunction.CheckRoutineEndState(_puf1SwitchOnRoutine);
  175. }
  176. /// <summary>
  177. /// 检查Puf1 Motors switchon是否出错
  178. /// </summary>
  179. /// <returns></returns>
  180. private bool CheckSwitchOnPuf1Error()
  181. {
  182. if (!ModuleHelper.IsInstalled(ModuleName.PUF1))
  183. {
  184. return false;
  185. }
  186. return CommonFunction.CheckRoutineStopState(_puf1SwitchOnRoutine);
  187. }
  188. #endregion
  189. #region Puf2
  190. /// <summary>
  191. /// Switch on Puf2 Motors
  192. /// </summary>
  193. /// <returns></returns>
  194. private bool SwitchOnPuf2()
  195. {
  196. return _puf2SwitchOnRoutine.Start()==RState.Running;
  197. }
  198. /// <summary>
  199. /// 检查Puf1 Motors switchon是否完成
  200. /// </summary>
  201. /// <returns></returns>
  202. private bool CheckSwitchOnPuf2Complete()
  203. {
  204. if (!ModuleHelper.IsInstalled(ModuleName.PUF2))
  205. {
  206. return true;
  207. }
  208. return CommonFunction.CheckRoutineEndState(_puf2SwitchOnRoutine);
  209. }
  210. /// <summary>
  211. /// 检查Puf2 Motors switchon是否出错
  212. /// </summary>
  213. /// <returns></returns>
  214. private bool CheckSwitchOnPuf2Error()
  215. {
  216. if (!ModuleHelper.IsInstalled(ModuleName.Transporter1))
  217. {
  218. return false;
  219. }
  220. return CommonFunction.CheckRoutineStopState(_puf2SwitchOnRoutine);
  221. }
  222. #endregion
  223. #region Loader
  224. /// <summary>
  225. /// Switch on Loader Motors
  226. /// </summary>
  227. /// <returns></returns>
  228. private bool SwitchOnLoader()
  229. {
  230. return _loaderSwitchAllOnRoutine.Start() == RState.Running;
  231. }
  232. /// <summary>
  233. /// 检查Loader Motors switchon是否完成
  234. /// </summary>
  235. /// <returns></returns>
  236. private bool CheckSwitchOnLoaderComplete()
  237. {
  238. if (!ModuleHelper.IsInstalled(ModuleName.Loader1))
  239. {
  240. return true;
  241. }
  242. return CommonFunction.CheckRoutineEndState(_loaderSwitchAllOnRoutine);
  243. }
  244. /// <summary>
  245. /// 检查Loader Motors switchon是否出错
  246. /// </summary>
  247. /// <returns></returns>
  248. private bool CheckSwitchOnLoaderError()
  249. {
  250. if (!ModuleHelper.IsInstalled(ModuleName.Transporter1))
  251. {
  252. return false;
  253. }
  254. return CommonFunction.CheckRoutineEndState(_loaderSwitchAllOnRoutine);
  255. }
  256. #endregion
  257. #region SRD1
  258. /// <summary>
  259. /// Switch on SRD1 Motors
  260. /// </summary>
  261. /// <returns></returns>
  262. private bool SwitchOnSRD1()
  263. {
  264. return _srd1SwitchOnRoutine.Start() == RState.Running;
  265. }
  266. /// <summary>
  267. /// 检查SRD1 Motors switchon是否完成
  268. /// </summary>
  269. /// <returns></returns>
  270. private bool CheckSwitchOnSRD1Complete()
  271. {
  272. if (!ModuleHelper.IsInstalled(ModuleName.SRD1))
  273. {
  274. return true;
  275. }
  276. return CommonFunction.CheckRoutineEndState(_srd1SwitchOnRoutine);
  277. }
  278. /// <summary>
  279. /// 检查SRD1 Motors switchon是否出错
  280. /// </summary>
  281. /// <returns></returns>
  282. private bool CheckSwitchOnSRD1Error()
  283. {
  284. if (!ModuleHelper.IsInstalled(ModuleName.SRD1))
  285. {
  286. return false;
  287. }
  288. return CommonFunction.CheckRoutineStopState(_srd1SwitchOnRoutine);
  289. }
  290. #endregion
  291. #region SRD2
  292. /// <summary>
  293. /// Switch on SRD2 Motors
  294. /// </summary>
  295. /// <returns></returns>
  296. private bool SwitchOnSRD2()
  297. {
  298. return _srd2SwitchOnRoutine.Start()==RState.Running;
  299. }
  300. /// <summary>
  301. /// 检查SRD2 Motors switchon是否完成
  302. /// </summary>
  303. /// <returns></returns>
  304. private bool CheckSwitchOnSRD2Complete()
  305. {
  306. if (!ModuleHelper.IsInstalled(ModuleName.SRD2))
  307. {
  308. return true;
  309. }
  310. return CommonFunction.CheckRoutineEndState(_srd2SwitchOnRoutine);
  311. }
  312. /// <summary>
  313. /// 检查SRD2 Motors switchon是否出错
  314. /// </summary>
  315. /// <returns></returns>
  316. private bool CheckSwitchOnSRD2Error()
  317. {
  318. if (!ModuleHelper.IsInstalled(ModuleName.SRD2))
  319. {
  320. return true;
  321. }
  322. return CommonFunction.CheckRoutineStopState(_srd2SwitchOnRoutine);
  323. }
  324. #endregion
  325. /// <summary>
  326. /// 启动
  327. /// </summary>
  328. /// <param name="objs"></param>
  329. /// <returns></returns>
  330. public RState Start(params object[] objs)
  331. {
  332. _loaderTransporterSwitchOnRoutine = new TransporterSwitchOnRoutine(ModuleName.Transporter2.ToString());
  333. _processTransporterSwitchOnRoutine = new TransporterSwitchOnRoutine(ModuleName.Transporter1.ToString());
  334. _loaderSwitchAllOnRoutine = new LoaderSwitchAllOnRoutine(ModuleName.Loader1.ToString());
  335. _puf1SwitchOnRoutine = new PufSwitchOnRoutine(ModuleName.PUF1);
  336. _puf2SwitchOnRoutine = new PufSwitchOnRoutine(ModuleName.PUF2);
  337. _srd1SwitchOnRoutine = new SRDSwitchOnRoutine(ModuleName.SRD1.ToString());
  338. _srd2SwitchOnRoutine = new SRDSwitchOnRoutine(ModuleName.SRD2.ToString());
  339. _device = DEVICE.GetDevice<SafetyDevice>(Module);
  340. return Runner.Start(Module, $"Safety All On");
  341. }
  342. }
  343. }