|
@@ -1,7 +1,13 @@
|
|
|
-using Aitex.Core.RT.Fsm;
|
|
|
+using Aitex.Core.RT.Device;
|
|
|
+using Aitex.Core.RT.Fsm;
|
|
|
using Aitex.Core.RT.Log;
|
|
|
+using Aitex.Core.Utilities;
|
|
|
using MECF.Framework.Common.Equipment;
|
|
|
+using MECF.Framework.Common.Persistent.Reservoirs;
|
|
|
+using MECF.Framework.Common.Persistent.VpwMain;
|
|
|
+using MECF.Framework.Common.ToolLayout;
|
|
|
using PunkHPX8_Core;
|
|
|
+using PunkHPX8_RT.Devices.VpwCell;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -18,59 +24,87 @@ namespace PunkHPX8_RT.Modules.VpwMain
|
|
|
Home
|
|
|
}
|
|
|
|
|
|
+ #region 常量
|
|
|
+ private const string STRATUS = "Stratus";
|
|
|
+ private const string AUTO = "Auto";
|
|
|
+ private const string MANUAL = "Manual";
|
|
|
+ private const string DISABLED = "Disabled";
|
|
|
+ private const string ENGINEERING = "Engineering";
|
|
|
+ private const string PRODUCTION = "Production";
|
|
|
+ #endregion
|
|
|
+
|
|
|
#region 内部变量
|
|
|
+ /// <summary>
|
|
|
+ /// 持久化数值
|
|
|
+ /// </summary>
|
|
|
+ private VpwMainPersistentValue _persistentValue;
|
|
|
+ /// <summary>
|
|
|
+ /// VPW cell集合
|
|
|
+ /// </summary>
|
|
|
+ private List<VpwCellDevice> _vpwCellDevices = new List<VpwCellDevice>();
|
|
|
+ /// <summary>
|
|
|
+ /// Home Routine
|
|
|
+ /// </summary>
|
|
|
+ private VPWHomeRoutine _homeRoutine;
|
|
|
#endregion
|
|
|
|
|
|
#region 属性
|
|
|
public ModuleName Module { get; private set; }
|
|
|
/// <summary>
|
|
|
- /// 初始化状态
|
|
|
+ /// 是否Init
|
|
|
/// </summary>
|
|
|
public bool IsInit
|
|
|
{
|
|
|
- get { return false; }
|
|
|
+ get { return fsm.State == (int)VPWMainState.Init; }
|
|
|
}
|
|
|
-
|
|
|
/// <summary>
|
|
|
- /// 空闲状态
|
|
|
+ /// 是否Idle
|
|
|
/// </summary>
|
|
|
public bool IsIdle
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- return true;
|
|
|
+ return fsm.State == (int)VPWMainState.Idle;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// 是否发生错误
|
|
|
+ /// 是否错误
|
|
|
/// </summary>
|
|
|
public bool IsError
|
|
|
{
|
|
|
- get { return false; }
|
|
|
+ get { return fsm.State == (int)VPWMainState.Error; }
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// 是否正在作业
|
|
|
+ /// 正在忙碌
|
|
|
/// </summary>
|
|
|
public bool IsBusy
|
|
|
{
|
|
|
- get { return false; }
|
|
|
+ get { return fsm.State == (int)VPWMainState.Initializing; }
|
|
|
}
|
|
|
|
|
|
- public bool IsAuto { get; } = true;
|
|
|
+ /// <summary>
|
|
|
+ /// 是否禁用
|
|
|
+ /// </summary>
|
|
|
+ public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 是否为工程模式
|
|
|
+ /// 自动模式
|
|
|
/// </summary>
|
|
|
- public bool IsEngineering { get; } = false;
|
|
|
+ public bool IsAuto { get { return _persistentValue != null && _persistentValue.OperatingMode == AUTO; } }
|
|
|
/// <summary>
|
|
|
- /// 是否为产品模式
|
|
|
+ /// 自动模式
|
|
|
/// </summary>
|
|
|
- public bool IsProduction { get; } = true;
|
|
|
+ public bool IsManual { get { return _persistentValue != null && _persistentValue.OperatingMode == MANUAL; } }
|
|
|
/// <summary>
|
|
|
- /// 是否禁用
|
|
|
+ /// 是否为工程模式
|
|
|
/// </summary>
|
|
|
- public bool IsDisable { get; internal set; } = false;
|
|
|
+ public bool IsEngineering { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == ENGINEERING; } }
|
|
|
+ /// <summary>
|
|
|
+ /// 是否为产品模式
|
|
|
+ /// </summary>
|
|
|
+ public bool IsProduction { get { return _persistentValue != null && _persistentValue.RecipeOperatingMode == PRODUCTION; } }
|
|
|
#endregion
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 构造函数
|
|
|
/// </summary>
|
|
@@ -79,6 +113,104 @@ namespace PunkHPX8_RT.Modules.VpwMain
|
|
|
{
|
|
|
this.Module = module;
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ protected override bool Init()
|
|
|
+ {
|
|
|
+ InitialFsm();
|
|
|
+ InitializeParameter();
|
|
|
+ InitializeRoutine();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ /// 初始化状态机
|
|
|
+ /// </summary>
|
|
|
+ private void InitialFsm()
|
|
|
+ {
|
|
|
+ fsm = new StateMachine<VpwMainEntity>(Module.ToString(), (int)VPWMainState.Init, 100);
|
|
|
+ fsm.EnableRepeatedMsg(true);
|
|
|
+
|
|
|
+ AnyStateTransition(VPWMainState.Error, NullFunc, VPWMainState.Error);
|
|
|
+ //Initialized
|
|
|
+ Transition(VPWMainState.Error, VPWMainMsg.Initialize, InitializeAll, VPWMainState.Initializing);
|
|
|
+ Transition(VPWMainState.Init, VPWMainMsg.Initialize, InitializeAll, VPWMainState.Initializing);
|
|
|
+ Transition(VPWMainState.Idle, VPWMainMsg.Initialize, InitializeAll, VPWMainState.Initializing);
|
|
|
+ Transition(VPWMainState.Initializing, FSM_MSG.TIMER, InitializeAllMonitor, VPWMainState.Idle);
|
|
|
+
|
|
|
+ //直接进入Idle
|
|
|
+ Transition(VPWMainState.Initialized, FSM_MSG.TIMER, NullFunc, VPWMainState.Idle);
|
|
|
+ //Enter Init
|
|
|
+ Transition(VPWMainState.Idle, VPWMainMsg.Init, NullFunc, VPWMainState.Init);
|
|
|
+
|
|
|
+ EnumLoop<VPWMainState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
|
|
|
+
|
|
|
+ EnumLoop<VPWMainMsg>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化参数
|
|
|
+ /// </summary>
|
|
|
+ private void InitializeParameter()
|
|
|
+ {
|
|
|
+ _persistentValue = VpwMainPersistentManager.Instance.GetPersistentValue(Module.ToString());
|
|
|
+ if (_persistentValue == null)
|
|
|
+ {
|
|
|
+ LOG.WriteLog(eEvent.ERR_VPWMAIN, Module.ToString(), "Persistent Value Object is not exist");
|
|
|
+ }
|
|
|
+ _vpwCellDevices.Clear();
|
|
|
+ VpwMainItem vpwMainItem = VpwMainItemManager.Instance.GetItem(Module.ToString());
|
|
|
+ if (vpwMainItem == null || vpwMainItem.VpwCells == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ foreach(var item in vpwMainItem.VpwCells)
|
|
|
+ {
|
|
|
+ VpwCellDevice cellDevice = DEVICE.GetDevice<VpwCellDevice>(item.ModuleName);
|
|
|
+ _vpwCellDevices.Add(cellDevice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化Routine
|
|
|
+ /// </summary>
|
|
|
+ private void InitializeRoutine()
|
|
|
+ {
|
|
|
+ _homeRoutine = new VPWHomeRoutine(Module.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+ #region InitializeAll
|
|
|
+ /// <summary>
|
|
|
+ /// Initialize
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="param"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private bool InitializeAll(object[] param)
|
|
|
+ {
|
|
|
+ if (_vpwCellDevices == null || _vpwCellDevices.Count == 0)
|
|
|
+ {
|
|
|
+ LOG.WriteLog(eEvent.ERR_VPWMAIN, Module.ToString(), "cell device is empty");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return _homeRoutine.Start(_vpwCellDevices) == RState.Running;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// Initialize 监控
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="param"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private bool InitializeAllMonitor(object[] param)
|
|
|
+ {
|
|
|
+ RState ret = _homeRoutine.Monitor();
|
|
|
+ if (ret == RState.Failed || ret == RState.Timeout)
|
|
|
+ {
|
|
|
+ PostMsg(VPWMainMsg.Error);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret == RState.End;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
public bool Check(int msg, out string reason, params object[] args)
|
|
|
{
|
|
|
reason = "";
|
|
@@ -95,11 +227,7 @@ namespace PunkHPX8_RT.Modules.VpwMain
|
|
|
/// </summary>
|
|
|
public void EnterInit()
|
|
|
{
|
|
|
- //if ((VpwMainState)fsm.State != PrewetState.Idle) return;
|
|
|
- //else
|
|
|
- //{
|
|
|
- // CheckToPostMessage<PrewetState, PrewetMsg>(eEvent.ERR_PREWET, Module.ToString(), (int)PrewetMsg.Init);
|
|
|
- //}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public int Invoke(string function, params object[] args)
|