using Aitex.Core.RT.Device; using Aitex.Core.RT.Log; using Aitex.Core.RT.Routine; using Aitex.Core.RT.SCCore; using MECF.Framework.Common.Beckhoff.ModuleIO; using MECF.Framework.Common.CommonData.PlatingCell; using MECF.Framework.Common.IOCore; using MECF.Framework.Common.Routine; using PunkHPX8_Core; using PunkHPX8_RT.Devices.SRD; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace PunkHPX8_RT.Devices.PlatingCell { public class ClamShellCloseRoutine : RoutineBase, IRoutine { private enum ClamshellClose { ClamShellClose, End } #region 常量 private const string CLAMSHELL_CLOSE = "ClamShellClose"; #endregion #region 内部变量 private bool _close; private PlatingCellDevice _device; private int _openSensor = 55; private int _closeSensor = 5; private int _sensorCheckTime = 1000; #endregion /// /// 构造函数 /// /// public ClamShellCloseRoutine(string module):base(module) { } public void Abort() { Runner.Stop("Manual Abort"); } public RState Monitor() { Runner.Run(ClamshellClose.ClamShellClose, ClamShellClose, CheckClamShellClose, _sensorCheckTime) .End(ClamshellClose.End, NullFun, 100); return Runner.Status; } private bool ClamShellClose() { string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{CLAMSHELL_CLOSE}"); return IOModuleManager.Instance.WriteIoValue(ioName, _close); } private bool CheckClamShellClose() { if (_close) { if (_device.PlatingCellDeviceData.ClamShellDistance <= _closeSensor) { LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, $"ClamShell is Closed"); //_device.PlatingCellDeviceData.ClamShellClosed = true; //_device.PlatingCellDeviceData.ClamShellOpened = false; return true; } else { return false; } } else { if (_device.PlatingCellDeviceData.ClamShellDistance > _openSensor) { LOG.WriteLog(eEvent.INFO_PLATINGCELL, Module, $"ClamShell is Opened"); //_device.PlatingCellDeviceData.ClamShellClosed = false; //_device.PlatingCellDeviceData.ClamShellOpened = true; return true; } else { return false; } } } public RState Start(params object[] objs) { _close = (bool)objs[0]; _device = DEVICE.GetDevice($"{Module}"); _openSensor = SC.GetValue("PlatingCell.ClamShellOpenDistanceThreshold"); _closeSensor = SC.GetValue("PlatingCell.ClamShellCloseDistanceThreshold"); _sensorCheckTime = SC.GetValue("PlatingCell.ClamShellOpenCheckDelay"); if (_close) { return Runner.Start(Module, "ClamShell Close"); } else { return Runner.Start(Module, "ClamShell Open"); } } } }