PrewetKeepWetRoutine.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using CyberX8_Core;
  5. using CyberX8_RT.Devices.LinMot;
  6. using CyberX8_RT.Devices.Prewet;
  7. using MECF.Framework.Common.Alarm;
  8. using MECF.Framework.Common.CommonData.Prewet;
  9. using MECF.Framework.Common.Routine;
  10. using System;
  11. using System.Collections.Generic;
  12. namespace CyberX8_RT.Modules.Prewet
  13. {
  14. public class PrewetKeepWetRoutine : RoutineBase, IRoutine
  15. {
  16. private const int LOTTRACK_TIME = 1000;
  17. private enum KeepwetStep
  18. {
  19. Idle_KeepwetPrepare,
  20. Idle_KeepwetPrepareWait,
  21. Idle_KeepWetStart,
  22. Idle_KeepWetScan,
  23. Idle_KeepWetPause,
  24. End
  25. }
  26. #region 内部变量
  27. /// <summary>
  28. /// prewet设备
  29. /// </summary>
  30. private PrewetDevice _prewetDevice;
  31. /// <summary>
  32. /// linmot axis
  33. /// </summary>
  34. private LinMotAxis _linMotAxis;
  35. /// <summary>
  36. /// Lottrack time
  37. /// </summary>
  38. private DateTime _lotTackTime = DateTime.Now;
  39. /// <summary>
  40. /// LotTrack数据
  41. /// </summary>
  42. private List<PrewetLotTrackData> _datas = new List<PrewetLotTrackData>();
  43. /// <summary>
  44. /// LotTrack数据
  45. /// </summary>
  46. public List<PrewetLotTrackData> PrewetLotTrackDatas { get { return _datas; } }
  47. #endregion
  48. /// <summary>
  49. /// 构造函数
  50. /// </summary>
  51. /// <param name="module"></param>
  52. public PrewetKeepWetRoutine(string module,LinMotAxis linMotAxis) : base(module)
  53. {
  54. _linMotAxis= linMotAxis;
  55. }
  56. /// <summary>
  57. /// 中止
  58. /// </summary>
  59. public void Abort()
  60. {
  61. _linMotAxis.StopOperation("", null);
  62. if (_prewetDevice != null)
  63. {
  64. _prewetDevice.PumpValveClose();
  65. }
  66. Runner.Stop("Manual Abort");
  67. }
  68. /// <summary>
  69. /// 监控
  70. /// </summary>
  71. /// <returns></returns>
  72. public RState Monitor()
  73. {
  74. LottrackRecord();
  75. Runner.Run(KeepwetStep.Idle_KeepwetPrepare, ResetLinmot, _delay_1ms)
  76. .WaitWithStopCondition(KeepwetStep.Idle_KeepwetPrepareWait, CheckResetLinmotEndStatus, CheckResetLinmotStopStatus)
  77. .Run(KeepwetStep.Idle_KeepWetStart, ExecuteWetScan, _delay_1s)
  78. .WaitWithStopCondition(KeepwetStep.Idle_KeepWetScan,CheckLinmotScanEndStatus,CheckLinmotScanStopStatus)
  79. .Run(KeepwetStep.Idle_KeepWetPause, KeepWetComplete, _delay_1ms)
  80. .End(KeepwetStep.End, NullFun, _delay_1ms);
  81. return Runner.Status;
  82. }
  83. /// <summary>
  84. /// Reset Linmot
  85. /// </summary>
  86. /// <param name="param"></param>
  87. /// <returns></returns>
  88. private bool ResetLinmot()
  89. {
  90. bool result = _linMotAxis.ResetOperation("", false);
  91. if (!result)
  92. {
  93. return false;
  94. }
  95. return true;
  96. }
  97. /// <summary>
  98. /// 检验Reset Linmot状态
  99. /// </summary>
  100. /// <param name="param"></param>
  101. /// <returns></returns>
  102. private bool CheckResetLinmotEndStatus()
  103. {
  104. return _linMotAxis.Status == RState.End;
  105. }
  106. /// <summary>
  107. /// 检验Reset Linmot停止状态
  108. /// </summary>
  109. /// <returns></returns>
  110. private bool CheckResetLinmotStopStatus()
  111. {
  112. if(_linMotAxis.Status == RState.Failed || _linMotAxis.Status == RState.Timeout)
  113. {
  114. AddLotTrackData();
  115. return true;
  116. }
  117. return false;
  118. }
  119. /// <summary>
  120. /// execute Keep Wet Scan
  121. /// </summary>
  122. /// <param name="param"></param>
  123. /// <returns></returns>
  124. private bool ExecuteWetScan()
  125. {
  126. bool pumpValveResult = _prewetDevice.PumpValveOpen();
  127. if (!pumpValveResult)
  128. {
  129. LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump valve open error");
  130. return false;
  131. }
  132. //bool pumpEnableResult = _prewetDevice.PumpEnableOperation("", null);
  133. //bool pumpEnableResult = _prewetDevice.PumpEnable();
  134. //if (!pumpEnableResult)
  135. //{
  136. // LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump enable error");
  137. // return false;
  138. //}
  139. bool result = _linMotAxis.StartPosition("", new object[] { 1 });
  140. if (!result)
  141. {
  142. return false;
  143. }
  144. return true;
  145. }
  146. /// <summary>
  147. /// 检验Linomot扫描结束状态
  148. /// </summary>
  149. /// <returns></returns>
  150. private bool CheckLinmotScanEndStatus()
  151. {
  152. return _linMotAxis.Status == RState.End;
  153. }
  154. /// <summary>
  155. /// 检验Linmot Scan停止状态
  156. /// </summary>
  157. /// <returns></returns>
  158. private bool CheckLinmotScanStopStatus()
  159. {
  160. bool result=_linMotAxis.Status==RState.Failed||_linMotAxis.Status==RState.Timeout;
  161. if(!result)
  162. {
  163. //Pressure
  164. if (_prewetDevice.PrewetPumpData.PumpPressureData.IsError)
  165. {
  166. _linMotAxis.StopOperation("", null);
  167. _prewetDevice.PumpValveClose();
  168. LOG.WriteLog(eEvent.ERR_PREWET, Module, $"Pump pressure {_prewetDevice.PrewetPumpData.PumpPressureData.Value} is in error");
  169. return true;
  170. }
  171. else if (_prewetDevice.PrewetPumpData.PumpPressureData.IsWarning)
  172. {
  173. string str = $"Pump pressure {_prewetDevice.PrewetPumpData.PumpPressureData.Value} is in warning";
  174. if (AlarmListManager.Instance.AddWarn(Module, "Pump Pressure", str))
  175. {
  176. LOG.WriteLog(eEvent.WARN_PREWET, Module, str);
  177. }
  178. }
  179. //Flow
  180. if (_prewetDevice.PrewetPumpData.PumpFlowData.IsError)
  181. {
  182. LOG.WriteLog(eEvent.ERR_PREWET, Module, $"Pump flow {_prewetDevice.PrewetPumpData.PumpFlowData.Value} is in error");
  183. _linMotAxis.StopOperation("", null);
  184. _prewetDevice.PumpValveClose();
  185. return true;
  186. }
  187. else if (_prewetDevice.PrewetPumpData.PumpFlowData.IsWarning)
  188. {
  189. string str = $"Pump flow {_prewetDevice.PrewetPumpData.PumpFlowData.Value} is in warning";
  190. if (AlarmListManager.Instance.AddWarn(Module, "Pump Flow", str))
  191. {
  192. LOG.WriteLog(eEvent.WARN_PREWET, Module, str);
  193. }
  194. }
  195. return false;
  196. }
  197. else
  198. {
  199. AddLotTrackData();
  200. _prewetDevice.PumpValveClose();
  201. return true;
  202. }
  203. }
  204. /// <summary>
  205. /// Wait execute WetScan
  206. /// </summary>
  207. /// <param name="param"></param>
  208. /// <returns></returns>
  209. private bool WaitExecuteWetScan(object param)
  210. {
  211. //linmot完成一次scan
  212. if (_linMotAxis.Status == RState.End)
  213. {
  214. return true;
  215. }
  216. return false;
  217. }
  218. /// <summary>
  219. /// Keep wet scan完成
  220. /// </summary>
  221. /// <param name="param"></param>
  222. /// <returns></returns>
  223. private bool KeepWetComplete()
  224. {
  225. bool result = _prewetDevice.PumpValveClose();
  226. if (!result)
  227. {
  228. LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump valve close error");
  229. return false;
  230. }
  231. result = _linMotAxis.SwitchOff();
  232. if (!result)
  233. {
  234. LOG.WriteLog(eEvent.ERR_PREWET, Module, "linmot disable error");
  235. return false;
  236. }
  237. return true;
  238. }
  239. /// <summary>
  240. /// 启动
  241. /// </summary>
  242. /// <param name="objs"></param>
  243. /// <returns></returns>
  244. public RState Start(params object[] objs)
  245. {
  246. _prewetDevice = DEVICE.GetDevice<PrewetDevice>(Module);
  247. _datas.Clear();
  248. _lotTackTime = DateTime.Now;
  249. return Runner.Start(Module, "Start Keepwet");
  250. }
  251. /// <summary>
  252. /// 记录Lottrack
  253. /// </summary>
  254. private void LottrackRecord()
  255. {
  256. //记录Lottrack
  257. if (DateTime.Now.Subtract(_lotTackTime).TotalMilliseconds >= LOTTRACK_TIME)
  258. {
  259. AddLotTrackData();
  260. _lotTackTime = DateTime.Now;
  261. }
  262. }
  263. /// <summary>
  264. /// 获取Lot Track数据
  265. /// </summary>
  266. /// <returns></returns>
  267. private void AddLotTrackData()
  268. {
  269. PrewetLotTrackData data = new PrewetLotTrackData();
  270. data.TimeStamp = DateTime.Now;
  271. data.StateMachine = Runner.CurrentStep.ToString();
  272. data.Pressure = _prewetDevice.PrewetPumpData.PumpPressureData.Value;
  273. data.Flow = _prewetDevice.PrewetPumpData.PumpFlowData.Value;
  274. data.PumpMode = _prewetDevice.PrewetPumpData.PumpModel;
  275. data.PressureTarget = _prewetDevice.PrewetPumpData.PressureTarget;
  276. data.CurrentScan = _linMotAxis.ScanCount;
  277. data.ScanOn = _linMotAxis.IsMotorOn;
  278. data.ValveState = _prewetDevice.PrewetPumpData.PumpValve;
  279. data.PumpSpeed = _prewetDevice.LastPumpSpeed;
  280. data.PumpControlCurrent = _prewetDevice.PrewetPumpData.PumpCurrent;
  281. _datas.Add(data);
  282. }
  283. }
  284. }