| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 | using Aitex.Core.RT.Device;using Aitex.Core.RT.Fsm;using Aitex.Core.RT.Log;using Aitex.Core.Utilities;using MECF.Framework.Common.RecipeCenter;using CyberX8_Core;using CyberX8_RT.Devices.LinMot;using CyberX8_RT.Devices.Prewet;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Markup;using MECF.Framework.Common.CommonData.Prewet;using static CyberX8_RT.Modules.Prewet.PrewetKeepWetStateMachine;namespace CyberX8_RT.Modules.Prewet{    public class PrewetProcessStateMachine : Entity, IEntity    {        #region 内部变量        /// <summary>        /// 模块名称        /// </summary>        private string _module;        /// <summary>        /// prewet设备        /// </summary>        private PrewetDevice _prewetDevice;        /// <summary>        /// linmot axis        /// </summary>        private LinMotAxis _linMotAxis;        /// <summary>        /// Prewet recipe        /// </summary>        private PwtRecipe _recipe;        #endregion        #region 属性        /// <summary>        /// 状态        /// </summary>        public string State { get { return ((PrewetProcessState)fsm.State).ToString(); } }        #endregion        /// <summary>        /// 构造函数        /// </summary>        /// <param name="module"></param>        public PrewetProcessStateMachine(string module,LinMotAxis linMotAxis)         {             _module = module;            _prewetDevice = DEVICE.GetDevice<PrewetDevice>(module);            _linMotAxis = linMotAxis;            this.fsm = new StateMachine($"{module}_ProcessStateMachine", (int)PrewetProcessState.Idle, 10);            fsm.EnableRepeatedMsg(true);            AnyStateTransition(PrewetProcessMsg.Error, EnterError, PrewetProcessState.Error);            Transition(PrewetProcessState.Error, PrewetProcessState.Process_Start, EnterProcessStartStatus, PrewetProcessState.Process_Start);            Transition(PrewetProcessState.Idle, PrewetProcessMsg.ProcessStart, EnterProcessStartStatus, PrewetProcessState.Process_Start);            Transition(PrewetProcessState.Process_Start,FSM_MSG.TIMER, NullFunc, PrewetProcessState.Process_StartScanning);            Transition(PrewetProcessState.Process_StartScanning,FSM_MSG.TIMER, ProcessStartScan, WaitProcessStartStatus, PrewetProcessState.Process_WaitFirstScanComplete);            Transition(PrewetProcessState.Process_WaitFirstScanComplete, FSM_MSG.TIMER, StartScan, PrewetProcessState.Process_WaitScanComplete);            Transition(PrewetProcessState.Process_WaitScanComplete, FSM_MSG.TIMER, WaitScanComplete, PrewetProcessState.Process_Complete);            Transition(PrewetProcessState.Process_Complete, FSM_MSG.TIMER, ProcessComplete, PrewetProcessState.Idle);            EnumLoop<PrewetProcessState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });            EnumLoop<PrewetProcessMsg>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });        }        /// <summary>        /// 进入启动状态        /// </summary>        /// <param name="param"></param>        private bool EnterProcessStartStatus(object param)        {            object[] objects = param as object[];            PwtRecipe pwtRecipe = (PwtRecipe)objects[0];            if(pwtRecipe == null)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "recipe is null error");                PostMsg(PrewetProcessMsg.Error);                return false;            }            _recipe = pwtRecipe;            return true;        }        /// <summary>        /// 进入Error状态        /// </summary>        /// <param name="param"></param>        /// <returns></returns>        private bool EnterError(object param)        {            if(_linMotAxis.Status==RState.Running)            {                _linMotAxis.AbortCurrentRoutine();            }            if(_prewetDevice.Status==RState.Running)            {                _prewetDevice.AbortCurrentRoutine();            }            return true;        }        #region process         /// <summary>        /// Process Start Scan        /// </summary>        /// <returns></returns>        private bool ProcessStartScan(object param)        {            bool result = _linMotAxis.ResetOperation("", false);            if (!result)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "reset linmot error");                PostMsg(PrewetProcessMsg.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");                PostMsg(PrewetProcessMsg.Error);                return false;            }            bool pumpEnableResult = _prewetDevice.PumpEnableOperation("", null);            if (!pumpEnableResult)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "pump enable error");                PostMsg(PrewetProcessMsg.Error);                return false;            }            return true;        }        /// <summary>        /// 等待start process状态        /// </summary>        /// <returns></returns>        private bool WaitProcessStartStatus(object param)        {            if(_prewetDevice.Status==RState.Failed)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "prewet device status is error");                PostMsg(PrewetProcessMsg.Error);                return false;            }            if (_linMotAxis.Status == RState.Failed)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "linmot status is error");                PostMsg(PrewetProcessMsg.Error);                return false;            }            if (_prewetDevice.Status == RState.End && _linMotAxis.Status == RState.End)            {                return true;            }            return false;        }        /// <summary>        /// 开始Scan        /// </summary>        /// <param name="param"></param>        /// <returns></returns>        private bool StartScan(object param)        {            if (!_linMotAxis.IsHomed)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "limot is not ready");                PostMsg(PrewetProcessMsg.Error);                return false;            }            if(!_prewetDevice.PrewetPumpData.PumpStatus)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "pump status if off");                PostMsg(PrewetProcessMsg.Error);                return false;            }            bool result = _linMotAxis.StartPosition("", new object[] { _recipe.NumberOfScans });            if(!result)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "linmot start scan error");                PostMsg(PrewetProcessMsg.Error);                return false;            }            return true;        }        /// <summary>        /// 等待Scan结束        /// </summary>        /// <param name="param"></param>        /// <returns></returns>        private bool WaitScanComplete(object param)        {            if (_prewetDevice.PrewetPumpData.PumpFlowData.IsWarning)            {                LOG.WriteLog(eEvent.WARN_PREWET, _module, $"pump flow status {_prewetDevice.PrewetPumpData.PumpFlowData.Value}  is in warning");            }            if (_prewetDevice.PrewetPumpData.PumpFlowData.IsError)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, $"pump flow status {_prewetDevice.PrewetPumpData.PumpFlowData.Value} is in error");                PostMsg(PrewetProcessMsg.Error);                return false;            }            if (_prewetDevice.PrewetPumpData.PumpPressureData.IsWarning)            {                LOG.WriteLog(eEvent.WARN_PREWET, _module, $"pump pressure status is {_prewetDevice.PrewetPumpData.PumpPressureData.Value} in warning");            }            if (_prewetDevice.PrewetPumpData.PumpPressureData.IsError)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, $"pump pressure status {_prewetDevice.PrewetPumpData.PumpPressureData.Value} is in error");                PostMsg(PrewetProcessMsg.Error);                return false;            }            //linmot完成一次scan            if (_linMotAxis.Status == RState.End)            {                return true;            }            if (_linMotAxis.Status == RState.Failed)            {                PostMsg(PrewetProcessMsg.Error);                return false;            }            return false;        }        /// <summary>        /// Process scan完成        /// </summary>        /// <param name="param"></param>        /// <returns></returns>        private bool ProcessComplete(object param)        {            bool result = _prewetDevice.PumpDisableOperation("pump disable", null);            if (!result)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "pump disable error");                PostMsg(PrewetKeepWetMsg.Error);                return false;            }            result = _linMotAxis.SwitchOff();            if (!result)            {                LOG.WriteLog(eEvent.ERR_PREWET, _module, "linmot disable error");                PostMsg(PrewetProcessMsg.Error);                return false;            }            return true;        }        #endregion        public bool Check(int msg, out string reason, params object[] args)        {            reason = "";            return true;        }        public enum PrewetProcessState        {            Error,            Idle,            Process_Start,            Process_StartScanning,            Process_WaitFirstScanComplete,            Process_WaitScanComplete,            Process_Complete        }        public enum PrewetProcessMsg        {            Error,            ProcessStart        }    }}
 |