| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using SKMC.Api.Common;
- using SKMC.Api.Motion;
- using SKMC.Api.Motion.Model;
- using System;
- namespace SKMC.Api.Process.Model
- {
- /// <summary>
- /// IO条件, 可作为触发动作的条件, 也可以作为告警状态的条件
- /// </summary>
- public class DioCnd
- {
- private static readonly MotionCacher motionCacher = ObjectFactory.Resolve<MotionCacher>();
- // 条件函数
- public Func<MotionIO, bool> CndExpress { get; set; }
- public MotionIO DataModel { get; set; }
- public static DioCnd Make(string code) => new DioCnd
- {
- Code = code
- };
- /// <summary>
- /// 创建一个DioCnd
- /// </summary>
- /// <param name="code"></param>
- /// <param name="cndExpress"></param>
- /// <returns></returns>
- public static DioCnd Make(string code, Func<MotionIO, bool> cndExpress) => new DioCnd
- {
- Code = code,
- CndExpress = cndExpress
- };
- /// <summary>
- /// 匹配一个基于MotionIO的条件函数
- /// </summary>
- /// <param name="code"></param>
- /// <param name="cndExpress"></param>
- /// <returns></returns>
- public static bool Match(string code, Func<MotionIO, bool> cndExpress) => cndExpress.Invoke(motionCacher.GetMotionDio(code));
- public bool Match() => CndExpress.Invoke(DataModel);
- public bool Match(Func<MotionIO, bool> 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);
- }
- }
- }
- }
|