PufCalibrateRoutine.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using MECF.Framework.Common.Equipment;
  6. using CyberX8_Core;
  7. using CyberX8_RT.Devices.PUF;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace CyberX8_RT.Modules.PUF
  14. {
  15. public class PufCalibrateRoutine : ModuleRoutineBase, IRoutine
  16. {
  17. #region 常量
  18. private const string CHUCKA_RELEASE = "ChuckARelease";
  19. private const double STANDARD = 100;
  20. #endregion
  21. private enum PufCalibrateStep
  22. {
  23. VacuumOff,
  24. SaveConfig,
  25. End
  26. }
  27. #region 内部变量
  28. private PufVacuum _vacuum;
  29. private PufDistanceSensor _distanceSensor;
  30. private int _timeOut = 6000;
  31. private double _offset1;
  32. private double _offset2;
  33. #endregion
  34. public PufCalibrateRoutine(ModuleName module) : base(module)
  35. {
  36. _vacuum = DEVICE.GetDevice<PufVacuum>($"{module.ToString()}.Vacuum");
  37. _distanceSensor = DEVICE.GetDevice<PufDistanceSensor>($"{module.ToString()}.DistanceSensor");
  38. Name = "Vacuum";
  39. }
  40. public void Abort()
  41. {
  42. Runner.Stop("Manual Abort");
  43. }
  44. public RState Monitor()
  45. {
  46. Runner.Run(PufCalibrateStep.VacuumOff, VacuumAOff, _timeOut)
  47. .Run(PufCalibrateStep.SaveConfig, SaveConfig, NullFun, _timeOut)
  48. .End(PufCalibrateStep.End,NullFun);
  49. return Runner.Status;
  50. }
  51. private bool VacuumAOff()
  52. {
  53. return _vacuum.VacuumAOff();
  54. }
  55. private bool SaveConfig()
  56. {
  57. _distanceSensor.SaveConfig(_offset1, _offset2);
  58. return true;
  59. }
  60. public RState Start(params object[] objs)
  61. {
  62. if(objs == null || objs.Length == 0)
  63. {
  64. return RState.Failed;
  65. }
  66. _offset1 = STANDARD - (double)objs[1];
  67. _offset2=STANDARD- (double)objs[2];
  68. Runner.Start(Module, Name);
  69. return RState.Running;
  70. }
  71. }
  72. }