123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Persistent.Reservoirs;
- using MECF.Framework.Common.ToolLayout;
- using PunkHPX8_Core;
- using PunkHPX8_RT.Devices.LinMot;
- using PunkHPX8_RT.Devices.PowerSupplier;
- using PunkHPX8_RT.Modules;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PunkHPX8_RT.Devices.PlatingCell
- {
- public class PlatingCellDevice : BaseDevice, IDevice
- {
- #region 常量
- private const string PERSISTENT_VALUE = "PersistentValue";
- private const string AUTO = "Auto";
- private const string MANUAL = "Manual";
- private const string STRATUS = "Stratus";
- private const string DISABLED = "Disabled";
- #endregion
- #region 内部变量
- /// <summary>
- /// 操作当前状态
- /// </summary>
- protected RState _status;
- /// <summary>
- /// 持久化数据
- /// </summary>
- protected PlatingCellPersistentValue _persistentValue;
- /// <summary>
- /// A面PowerSupplier
- /// </summary>
- protected CellPowerSupplier _sideAPowerSupplier;
- /// <summary>
- /// B面PowerSupplier
- /// </summary>
- protected CellPowerSupplier _sideBPowerSupplier;
- /// <summary>
- /// Linmot
- /// </summary>
- protected LinMotAxis _linmotAxis;
- /// <summary>
- /// PlatingCell项
- /// </summary>
- private PlatingCellItem _platingCellItem;
- #endregion
- #region 属性
- /// <summary>
- /// 状态
- /// </summary>
- public RState Status { get { return _status; } }
- /// <summary>
- /// 是否禁用
- /// </summary>
- public bool IsDisable { get { return _persistentValue == null || _persistentValue.OperatingMode == DISABLED; } }
-
- /// <summary>
- /// 操作模式
- /// </summary>
- public string OperationMode { get { return _persistentValue.OperatingMode; } }
- /// <summary>
- /// 工程模式
- /// </summary>
- public string EngineerMode { get { return _persistentValue.RecipeOperatingMode; } }
- /// <summary>
- /// A面PowerSupplier
- /// </summary>
- public CellPowerSupplier SideAPowerSupplier { get { return _sideAPowerSupplier; } }
- /// <summary>
- /// B面PowerSupplier
- /// </summary>
- public CellPowerSupplier SideBPowerSupplier { get { return _sideBPowerSupplier; } }
- /// <summary>
- /// 是否为Auto
- /// </summary>
- public bool IsAuto { get { return _persistentValue != null ? _persistentValue.OperatingMode == AUTO : false; } }
- /// <summary>
- /// 是否为Auto
- /// </summary>
- public bool IsManual { get { return _persistentValue != null ? _persistentValue.OperatingMode == MANUAL : false; } }
- /// <summary>
- /// linmot motor on
- /// </summary>
- public bool IsLinmotMotorOn { get { return _linmotAxis != null ? _linmotAxis.IsMotorOn : false; } }
- /// <summary>
- /// Linmot当前位置
- /// </summary>
- public double LinmotPosition { get { return _linmotAxis != null ? _linmotAxis.CurrentPosition : 0; } }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="moduleName"></param>
- public PlatingCellDevice(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
- {
- }
- /// <summary>
- /// 初始化
- /// </summary>
- /// <returns></returns>
- public virtual bool Initialize()
- {
- InitializeParameter();
- SubscribeData();
- InitializeOperation();
- return true;
- }
- /// <summary>
- /// 定时器执行
- /// </summary>
- public virtual bool OnTimer(int interval)
- {
- return true;
- }
- /// <summary>
- /// 初始化参数
- /// </summary>
- private void InitializeParameter()
- {
- _persistentValue = PlatingCellPersistentManager.Instance.GetPlatingCellPersistentValue(Module);
- if (_persistentValue == null)
- {
- LOG.WriteLog(eEvent.ERR_RESERVOIR, Module, "Persistent Value Object is not exist");
- }
- _platingCellItem = PlatingCellItemManager.Instance.GetPlatingCellItem(Module);
- if (_platingCellItem != null)
- {
- _sideAPowerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_platingCellItem.PlatingPowerSupplyAID);
- _sideBPowerSupplier = DEVICE.GetDevice<CellPowerSupplier>(_platingCellItem.PlatingPowerSupplyBID);
- _linmotAxis = DEVICE.GetDevice<LinMotAxis>(_platingCellItem.LinmotID);
- }
- }
- /// <summary>
- /// 订阅数据
- /// </summary>
- private void SubscribeData()
- {
- DATA.Subscribe($"{Module}.{PERSISTENT_VALUE}", () => _persistentValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplierData", () => _sideAPowerSupplier.PowerSupplierData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplierData", () => _sideBPowerSupplier.PowerSupplierData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplier.ID", () => _sideAPowerSupplier.Module, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplier.IsConnected", () => _sideAPowerSupplier.IsConnected, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplier.Voltage", () => _sideAPowerSupplier.PowerSupplierData.Voltage, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplier.Current", () => _sideAPowerSupplier.PowerSupplierData.Current, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplier.SetPoint", () => _sideAPowerSupplier.PowerSupplierData.SetPoint, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplier.RunModel", () => _sideAPowerSupplier.PowerSupplierData.PowerRunModelContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplier.PowerControl", () => _sideAPowerSupplier.PowerSupplierData.PowerControlContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplier.PowerStatus", () => _sideAPowerSupplier.PowerSupplierData.PowerStatusContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideAPowerSupplier.Enable", () => _sideBPowerSupplier.PowerSupplierData.Enabled, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplier.ID", () => _sideBPowerSupplier.Module, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplier.IsConnected", () => _sideAPowerSupplier.IsConnected, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplier.Voltage", () => _sideBPowerSupplier.PowerSupplierData.Voltage, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplier.Current", () => _sideBPowerSupplier.PowerSupplierData.Current, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplier.SetPoint", () => _sideBPowerSupplier.PowerSupplierData.SetPoint, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplier.RunModel", () => _sideBPowerSupplier.PowerSupplierData.PowerRunModelContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplier.PowerControl", () => _sideBPowerSupplier.PowerSupplierData.PowerControlContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplier.PowerStatus", () => _sideBPowerSupplier.PowerSupplierData.PowerStatusContent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.SideBPowerSupplier.Enable", () => _sideBPowerSupplier.PowerSupplierData.Enabled, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.Linmot.ID", () => _linmotAxis.Module, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.Linmot.IsMotorOn", () => _linmotAxis.IsMotorOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.Linmot.IsError", () => _linmotAxis.IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.Linmot.IsSwitchOn", () => _linmotAxis.IsSwitchOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.Linmot.CurveSpeed", () => _linmotAxis.CurveSpeed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.Linmot.ErrorCode", () => _linmotAxis.ErrorCode, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- DATA.Subscribe($"{Module}.Linmot.CurrentPosition", () => _linmotAxis.CurrentPosition, SubscriptionAttribute.FLAG.IgnoreSaveDB);
- }
- /// <summary>
- /// 初始化操作
- /// </summary>
- protected virtual void InitializeOperation()
- {
- OP.Subscribe($"{Module}.DisabledAction", DisabledOperation);
- OP.Subscribe($"{Module}.ManualAction", ManualOperation);
- OP.Subscribe($"{Module}.AutoAction", AutoOperation);
- OP.Subscribe($"{Module}.EngineeringModeAction", EngineeringModeOperation);
- OP.Subscribe($"{Module}.ProductionModeAction", ProductionModeOperation);
- OP.Subscribe($"{Module}.SetPlatingCellWaferSize", (cmd, args) => { return SetPlatingCellWaferSize(cmd, args); });
- }
- /// <summary>
- /// 开始Curve
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- public bool StartCurveMotion(int speed)
- {
- if (_linmotAxis != null)
- {
- return _linmotAxis.StartCurve(speed);
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
- return false;
- }
- }
- /// <summary>
- /// 开始Curve
- /// </summary>
- /// <param name="speed"></param>
- /// <returns></returns>
- public bool ChangeCurveSpeedMotion(int speed)
- {
- if (_linmotAxis != null)
- {
- return _linmotAxis.ChangeCurveSpeed(speed);
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
- return false;
- }
- }
- /// <summary>
- /// ResetLinmot
- /// </summary>
- /// <returns></returns>
- public bool ResetLinmot()
- {
- if (_linmotAxis != null)
- {
- return _linmotAxis.ResetOperation("", false);
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
- return false;
- }
- }
- /// <summary>
- /// 检验Linmot Routine状态是否为结束状态
- /// </summary>
- /// <returns></returns>
- public bool CheckLinmotRoutineEnd()
- {
- if (_linmotAxis != null)
- {
- return _linmotAxis.Status == RState.End;
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
- return false;
- }
- }
- /// <summary>
- /// 检验Linmot Routine状态是否为错误状态
- /// </summary>
- /// <returns></returns>
- public bool CheckLinmotRoutineError()
- {
- if (_linmotAxis != null)
- {
- return _linmotAxis.Status == RState.Failed || _linmotAxis.Status == RState.Timeout;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 停止Linmot
- /// </summary>
- /// <returns></returns>
- public bool StopLinmot()
- {
- if (_linmotAxis != null)
- {
- return _linmotAxis.StopOperation("", null);
- }
- else
- {
- LOG.WriteLog(eEvent.ERR_METAL, Module, "linmot is null");
- return false;
- }
- }
- #region Operation
- /// <summary>
- /// DisabledAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- public bool DisabledOperation(string cmd, object[] args)
- {
- //string currentOperation = "Disabled";
- //MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(Module);
- //if (metalEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
- //{
- // string preOperation = _persistentValue.OperatingMode;
- // if (metalEntity.IsBusy)
- // {
- // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is Busy, can't switch to Disabled mode");
- // return false;
- // }
- // if (SchedulerMetalTimeManager.Instance.Contained(Module))
- // {
- // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is in scheduler, can't switch to Disabled mode");
- // return false;
- // }
- // metalEntity.EnterInit();
- // _persistentValue.OperatingMode = currentOperation;
- // LOG.WriteLog(eEvent.INFO_METAL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
- //}
- //MetalPersistentManager.Instance.UpdatePersistentValue(Module);
- return true;
- }
- /// <summary>
- /// ManualAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- public bool ManualOperation(string cmd, object[] args)
- {
- //string currentOperation = "Manual";
- //MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(Module);
- //if (metalEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
- //{
- // string preOperation = _persistentValue.OperatingMode;
- // if (metalEntity.IsBusy)
- // {
- // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is Busy, can't switch to Manual mode");
- // return false;
- // }
- // if (SchedulerMetalTimeManager.Instance.Contained(Module))
- // {
- // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is in scheduler, can't switch to Manual mode");
- // return false;
- // }
- // metalEntity.EnterInit();
- // _persistentValue.OperatingMode = currentOperation;
- // LOG.WriteLog(eEvent.INFO_METAL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
- //}
- //MetalPersistentManager.Instance.UpdatePersistentValue(Module);
- return true;
- }
- /// <summary>
- /// AutoAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- public bool AutoOperation(string cmd, object[] args)
- {
- //string currentOperation = "Auto";
- //MetalEntity metalEntity = Singleton<RouteManager>.Instance.GetModule<MetalEntity>(Module);
- //if (metalEntity != null && _persistentValue != null && _persistentValue.OperatingMode != currentOperation)
- //{
- // string preOperation = _persistentValue.OperatingMode;
- // if (metalEntity.IsBusy)
- // {
- // LOG.WriteLog(eEvent.ERR_METAL, Module, $"{Module} is Busy, can't switch to Auto mode");
- // return false;
- // }
- // metalEntity.EnterInit();
- // _persistentValue.OperatingMode = currentOperation;
- // LOG.WriteLog(eEvent.INFO_METAL, Module, $"Operating mode is switched from {preOperation} to {currentOperation}");
- //}
- //MetalPersistentManager.Instance.UpdatePersistentValue(Module);
- return true;
- }
- /// <summary>
- /// EngineeringModeAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool EngineeringModeOperation(string cmd, object[] args)
- {
- string currentRecipeOperation = "Engineering";
- if (_persistentValue != null)
- {
- _persistentValue.RecipeOperatingMode = currentRecipeOperation;
- }
- PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
- return true;
- }
- /// <summary>
- /// ProductionAction
- /// </summary>
- /// <param name="cmd"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- private bool ProductionModeOperation(string cmd, object[] args)
- {
- string currentRecipeOperation = "Production";
- if (_persistentValue != null)
- {
- _persistentValue.RecipeOperatingMode = currentRecipeOperation;
- }
- PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
- return true;
- }
- private bool SetPlatingCellWaferSize(string cmd, object[] args)
- {
- string metalWaferSize = args[0] as string;
- if (_persistentValue != null)
- {
- _persistentValue.PlatingCellWaferSize = int.Parse(metalWaferSize);
- }
- PlatingCellPersistentManager.Instance.UpdatePersistentValue(Module);
- return true;
- }
- #endregion
-
- public virtual void Monitor()
- {
- }
- public virtual void Reset()
- {
- }
- public virtual void Terminate()
- {
- }
- }
- }
|