// /************************************************************************ // * @file BaseRoutineWithDeviceLocker.cs // * @author Su Liang // * @date 2022/11/18 // * // * @copyright © Sicentury Inc. // * // * @brief // * // * @details // * // * // * *****************************************************************************/ using System; using Aitex.Core.RT.Event; using Aitex.Core.RT.Routine; using Sicentury.Core; namespace MECF.Framework.RT.EquipmentLibrary.Core { public class BaseRoutineWithDeviceLocker : ModuleRoutine { private readonly DeviceLocker _lockerPump2; public BaseRoutineWithDeviceLocker() { _lockerPump2 = DeviceLockerManager.Instance.GetLocker(DeviceLockerManager.LockerNames.Pump2); } public void LockPump2(out string reason, int timeoutMs = Int32.MaxValue) { reason = ""; EV.PostInfoLog(Module, $"[{Module}] is locking the Pump2"); var ret = _lockerPump2?.TryLock(Module, out reason, timeoutMs); if (ret.HasValue == false || ret == DeviceLocker.Results.Ok || ret == DeviceLocker.Results.IHaveLocker) // 不需要锁定、已锁定成功、或已占有该锁 { EV.PostInfoLog(Module, $"[{Module}] locked the Pump2, Result: {ret}"); return; } // 无法锁定设备。 EV.PostWarningLog(Module, $"[{Module}] was unable to lock Pump2, {reason}"); throw new Exception($"unable to lock {_lockerPump2.LockerName} by {Module}, {reason}"); } public void UnlockPump2() { EV.PostInfoLog(Module, $"[{Module}] is unlocking the Pump2"); var reason = ""; var ret = _lockerPump2?.TryUnlock(Module, out reason); if (ret.HasValue == false || ret == DeviceLocker.Results.Ok) // 不需要锁定、解锁成功 { EV.PostInfoLog(Module, $"[{Module}] unlock the Pump2, Result: {ret}"); return; } EV.PostWarningLog(Module, $"[{Module}] was unable to unlock pump2, {reason}"); } public void ResetLockerPump2() { EV.PostInfoLog(Module, $"{Module} reset the locker of Pump2"); _lockerPump2?.Reset(); } public virtual void Abort() { UnlockPump2(); } } }