Sic04/FrameworkLocal/RTEquipmentLibrary/Core/BaseRoutineWithDeviceLocker.cs

65 lines
1.9 KiB
C#

// /************************************************************************
// * @file BaseRoutineWithDeviceLocker.cs
// * @author Su Liang
// * @date 2022/11/18
// *
// * @copyright &copy 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 = "";
var ret = _lockerPump2?.TryLock(Module, out reason, timeoutMs);
if (ret.HasValue == false || ret == DeviceLocker.Results.Ok ||
ret == DeviceLocker.Results.IHaveLocker) // 不需要锁定、已锁定成功、或已占有该锁
return;
// 无法锁定设备。
throw new Exception($"unable to lock {_lockerPump2.LockerName} by {Module}, {reason}");
}
public void UnlockPump2()
{
var reason = "";
var ret = _lockerPump2?.TryUnlock(Module, out reason);
if (ret.HasValue == false || ret == DeviceLocker.Results.Ok) // 不需要锁定、解锁成功
return;
EV.PostWarningLog(Module, $"Unable to unlock pump2, {reason}");
}
public void ResetLockerPump2()
{
_lockerPump2?.Reset();
}
public virtual void Abort()
{
UnlockPump2();
}
}
}