AxisCnd.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. /// 电机运行条件, 可作为触发动作的条件, 也可以作为告警状态的条件
  9. /// </summary>
  10. public class AxisCnd
  11. {
  12. //static readonly ILogger log = LogFactory.Get(typeof(AxisCnd));
  13. private readonly MotionCacher motionCacher = ObjectFactory.Resolve<MotionCacher>();
  14. public Func<MotionAxis, bool> CndExpress { get; set; }
  15. public MotionAxis DataModel { get; set; }
  16. // Type: Trigger 0, Validate 1
  17. public short Type { get; set; } = 0;
  18. public static AxisCnd Make(string code) => new AxisCnd
  19. {
  20. Code = code
  21. };
  22. public static AxisCnd Make(string code, Func<MotionAxis, bool> cndExpress) => new AxisCnd
  23. {
  24. Code = code,
  25. CndExpress = cndExpress
  26. };
  27. public bool Match() => CndExpress.Invoke(DataModel);
  28. public bool Match(Func<MotionAxis, bool> cndExpress) => cndExpress.Invoke(DataModel);
  29. private string _code;
  30. public string Code
  31. {
  32. get { return _code; }
  33. set
  34. {
  35. _code = value;
  36. DataModel = motionCacher.GetMotionAxis(_code);
  37. }
  38. }
  39. }
  40. }