AxisCnd.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using SKMC.Api.Core;
  2. using SKMC.Api.Common.Logger;
  3. using System;
  4. namespace SKMC.Api.Motion.Model
  5. {
  6. /// <summary>
  7. /// 电机运行条件, 可作为触发动作的条件, 也可以作为告警状态的条件
  8. /// </summary>
  9. public class AxisCnd
  10. {
  11. protected static readonly ILogger log = LogFactory.Get();
  12. private readonly MotionCacher motionCacher = ObjectFactory.Resolve<MotionCacher>();
  13. public Func<MotionAxis, bool> CndExpress { get; set; }
  14. public MotionAxis DataModel { get; set; }
  15. // Type: Trigger 0, Validate 1
  16. public short Type { get; set; } = 0;
  17. public static AxisCnd Make(string code) => new AxisCnd
  18. {
  19. Code = code
  20. };
  21. public static AxisCnd Make(string code, Func<MotionAxis, bool> cndExpress) => new AxisCnd
  22. {
  23. Code = code,
  24. CndExpress = cndExpress
  25. };
  26. public bool Match() => CndExpress.Invoke(DataModel);
  27. public bool Match(Func<MotionAxis, bool> cndExpress) => cndExpress.Invoke(DataModel);
  28. private string _code;
  29. public string Code
  30. {
  31. get { return _code; }
  32. set
  33. {
  34. _code = value;
  35. DataModel = motionCacher.GetMotionAxis(_code);
  36. }
  37. }
  38. }
  39. }