using SKMC.Api.Common;
using System;
namespace SKMC.Api.Motion.Model
{
///
/// IO条件, 可作为触发动作的条件, 也可以作为告警状态的条件
///
public class DioCnd
{
private static readonly MotionCacher motionCacher = ObjectFactory.Resolve();
// 条件函数
public Func CndExpress { get; set; }
public MotionIO DataModel { get; set; }
public static DioCnd Make(string code) => new DioCnd
{
Code = code
};
///
/// 创建一个DioCnd
///
///
///
///
public static DioCnd Make(string code, Func cndExpress) => new DioCnd
{
Code = code,
CndExpress = cndExpress
};
///
/// 匹配一个基于MotionIO的条件函数
///
///
///
///
public static bool Match(string code, Func cndExpress) => cndExpress.Invoke(motionCacher.GetMotionDio(code));
public bool Match() => CndExpress.Invoke(DataModel);
public bool Match(Func cndExpress) => cndExpress.Invoke(DataModel);
public void Reset()
{
if (DataModel != null) DataModel.Reset();
}
private string _code;
public string Code
{
get { return _code; }
set
{
_code = value;
DataModel = motionCacher.GetMotionDio(_code);
}
}
}
}