DioCnd.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using SKMC.Api.Common;
  2. using SKMC.Api.Motion;
  3. using SKMC.Api.Motion.Model;
  4. using System;
  5. namespace SKMC.Api.Process.Model
  6. {
  7. /// <summary>
  8. /// IO条件, 可作为触发动作的条件, 也可以作为告警状态的条件
  9. /// </summary>
  10. public class DioCnd
  11. {
  12. private static readonly MotionCacher motionCacher = ObjectFactory.Resolve<MotionCacher>();
  13. // 条件函数
  14. public Func<MotionIO, bool> CndExpress { get; set; }
  15. public MotionIO DataModel { get; set; }
  16. public static DioCnd Make(string code) => new DioCnd
  17. {
  18. Code = code
  19. };
  20. /// <summary>
  21. /// 创建一个DioCnd
  22. /// </summary>
  23. /// <param name="code"></param>
  24. /// <param name="cndExpress"></param>
  25. /// <returns></returns>
  26. public static DioCnd Make(string code, Func<MotionIO, bool> cndExpress) => new DioCnd
  27. {
  28. Code = code,
  29. CndExpress = cndExpress
  30. };
  31. /// <summary>
  32. /// 匹配一个基于MotionIO的条件函数
  33. /// </summary>
  34. /// <param name="code"></param>
  35. /// <param name="cndExpress"></param>
  36. /// <returns></returns>
  37. public static bool Match(string code, Func<MotionIO, bool> cndExpress) => cndExpress.Invoke(motionCacher.GetMotionDio(code));
  38. public bool Match() => CndExpress.Invoke(DataModel);
  39. public bool Match(Func<MotionIO, bool> cndExpress) => cndExpress.Invoke(DataModel);
  40. public void Reset()
  41. {
  42. if (DataModel != null) DataModel.Reset();
  43. }
  44. private string _code;
  45. public string Code
  46. {
  47. get { return _code; }
  48. set
  49. {
  50. _code = value;
  51. DataModel = motionCacher.GetMotionDio(_code);
  52. }
  53. }
  54. }
  55. }