123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.RecipeCenter;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using CyberX8_Core;
- using CyberX8_RT.Devices.LinMot;
- using CyberX8_RT.Devices.Prewet;
- using MECF.Framework.Common.Alarm;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.CommonData.Prewet;
- using MECF.Framework.Common.Persistent.Dryer;
- using MECF.Framework.Common.Persistent.Prewet;
- using MECF.Framework.Common.Persistent.Temperature;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.Routine;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using static CyberX8_RT.Modules.Prewet.PrewetKeepWetStateMachine;
- namespace CyberX8_RT.Modules.Prewet
- {
- public class PrewetProcessRoutine : RoutineBase, IRoutine
- {
- private enum ProcessStep
- {
- Process_Start,
- Process_StartScanning,
- Process_WaitPumpOnEnd,
- Process_WaitFirstScanComplete,
- Process_WaitScanComplete,
- Process_Complete,
- End
- }
- #region 内部变量
- /// <summary>
- /// prewet设备
- /// </summary>
- private PrewetDevice _prewetDevice;
- /// <summary>
- /// linmot axis
- /// </summary>
- private LinMotAxis _linMotAxis;
- /// <summary>
- /// Prewet recipe
- /// </summary>
- private PwtRecipe _recipe;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public PrewetProcessRoutine(string module, LinMotAxis linMotAxis) : base(module)
- {
- this._linMotAxis = linMotAxis;
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- _linMotAxis.StopOperation("", null);
- _prewetDevice.PumpDisableOperation("pump disable", null);
- Runner.Stop("Manual Abort");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(ProcessStep.Process_Start, NullFun, _delay_1ms)
- .Run(ProcessStep.Process_StartScanning, ProcessStartScan, _delay_1ms)
- .WaitWithStopCondition(ProcessStep.Process_WaitPumpOnEnd, WaitProcessEndStatus, CheckProcessFailedStatus, _delay_60s)
- .Run(ProcessStep.Process_WaitFirstScanComplete, StartScan, _delay_1ms)
- .WaitWithStopCondition(ProcessStep.Process_WaitScanComplete, WaitScanComplete, CheckScanStopEnd)
- .Run(ProcessStep.Process_Complete, ProcessComplete, CheckPumpValveClose,_delay_3s)
- .End(ProcessStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
-
- /// <summary>
- /// Process Start Scan
- /// </summary>
- /// <returns></returns>
- private bool ProcessStartScan()
- {
- bool result = _linMotAxis.ResetOperation("", false);
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_PREWET, Module, "reset linmot error");
- return false;
- }
- _prewetDevice.PrewetPumpData.PumpSpeedAuto = true;
- //更新Pump status状态
- string statusContent = _prewetDevice.PrewetPumpData.PumpStatus ? "On" : "Off";
- _prewetDevice.PrewetPumpData.PumpModel = "Auto";
- _prewetDevice.PrewetPumpData.PumpStatusContent = $"{_prewetDevice.PrewetPumpData.PumpModel}: {statusContent}";
- result = _prewetDevice.PumpSpeed();
- if (!result)
- {
- LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump speed error");
- return false;
- }
- bool pumpEnableResult = _prewetDevice.PumpEnableOperation("", null);
- if (!pumpEnableResult)
- {
- LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump enable error");
- return false;
- }
- return true;
- }
- /// <summary>
- /// 等待结束状态
- /// </summary>
- /// <returns></returns>
- private bool WaitProcessEndStatus()
- {
- if (_prewetDevice.Status == RState.End && _linMotAxis.Status == RState.End)
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 检验错误状态
- /// </summary>
- /// <returns></returns>
- private bool CheckProcessFailedStatus()
- {
- if (_prewetDevice.Status == RState.Failed)
- {
- LOG.WriteLog(eEvent.ERR_PREWET, Module, "prewet device status is error");
- return true;
- }
- if (_linMotAxis.Status == RState.Failed)
- {
- LOG.WriteLog(eEvent.ERR_PREWET, Module, "linmot status is error");
- return true;
- }
- return false;
- }
- /// <summary>
- /// 自动调速
- /// </summary>
- private bool StartAdjustSpeed()
- {
- _prewetDevice.IsStartAutoSpeed = true;
- return true;
- }
- /// <summary>
- /// 开始Scan
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool StartScan()
- {
- if (!_linMotAxis.IsHomed)
- {
- LOG.WriteLog(eEvent.ERR_PREWET, Module, "limot is not ready");
- return false;
- }
- if (!_prewetDevice.PrewetPumpData.PumpStatus)
- {
- LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump status if off");
- return false;
- }
- bool result = _linMotAxis.StartPosition("", new object[] { _recipe.NumberOfScans });
- if (!result)
- {
- _prewetDevice.PumpDisableOperation("pump disable", null);
- LOG.WriteLog(eEvent.ERR_PREWET, Module, "linmot start scan error");
- return false;
- }
- return result;
- }
- /// <summary>
- /// 等待Scan结束
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool WaitScanComplete()
- {
- //linmot完成一次scan
- if (_linMotAxis.Status == RState.End)
- {
- return true;
- }
-
- return false;
- }
- /// <summary>
- /// 检验Prewet停止状态
- /// </summary>
- /// <returns></returns>
- private bool CheckScanStopEnd()
- {
- if (_linMotAxis.Status == RState.Failed||_linMotAxis.Status==RState.Timeout)
- {
- _prewetDevice.PumpDisable();
- return true;
- }
- if (_prewetDevice.PrewetPumpData.PumpPressureData.IsError)
- {
- _linMotAxis.StopOperation("",null);
- _prewetDevice.PumpDisableOperation("pump disable", null);
- LOG.WriteLog(eEvent.ERR_PREWET, Module, $"pump pressure status {_prewetDevice.PrewetPumpData.PumpPressureData.Value} is in error");
- return true;
- }
- if (_prewetDevice.PrewetPumpData.PumpFlowData.IsWarning)
- {
- string str = $"pump flow status {_prewetDevice.PrewetPumpData.PumpFlowData.Value} is in warning";
- if (AlarmListManager.Instance.AddWarn(Module, "PumpFlow", str))
- {
- LOG.WriteLog(eEvent.WARN_PREWET, Module, str);
- }
- }
- if (_prewetDevice.PrewetPumpData.PumpFlowData.IsError)
- {
- LOG.WriteLog(eEvent.ERR_PREWET, Module, $"pump flow status {_prewetDevice.PrewetPumpData.PumpFlowData.Value} is in error");
- _linMotAxis.StopOperation("", null);
- _prewetDevice.PumpDisableOperation("pump disable", null);
- return true;
- }
- if (_prewetDevice.PrewetPumpData.PumpPressureData.IsWarning)
- {
- string str = $"pump pressure status is { _prewetDevice.PrewetPumpData.PumpPressureData.Value } in warning";
- if (AlarmListManager.Instance.AddWarn(Module, "Pump Pressure", str))
- {
- LOG.WriteLog(eEvent.WARN_PREWET, Module, str);
- }
- }
- return false;
- }
- /// <summary>
- /// Process scan完成
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ProcessComplete()
- {
- //bool result = _prewetDevice.PumpValveClose();
- //if (!result)
- //{
- // LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump valve close");
- // return false;
- //}
- //result = _prewetDevice.PumpDisable();
- //if (!result)
- //{
- // LOG.WriteLog(eEvent.ERR_PREWET, Module, "pump enable close");
- // return false;
- //}
- bool result = _prewetDevice.PumpDisableOperation("pump disable",null);
- return result;
- }
- private bool CheckPumpValveClose()
- {
- bool result = !_prewetDevice.PrewetPumpData.PumpValve;
- return result;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- //清除lotTrack数据
- _prewetDevice = DEVICE.GetDevice<PrewetDevice>(Module);
- _recipe = objs[0] as PwtRecipe;
- if (_recipe == null)
- {
- LOG.WriteLog(eEvent.ERR_PREWET, Module, "recipe is null");
- return RState.Failed;
- }
-
- return Runner.Start(Module, "Start Process Recipe");
- }
- }
- }
|