PufCalibrateRoutine.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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
  47. //.Run(PufCalibrateStep.VacuumOff, VacuumAOff, _timeOut)
  48. .Run(PufCalibrateStep.SaveConfig, SaveConfig, NullFun, _timeOut)
  49. .End(PufCalibrateStep.End,NullFun);
  50. return Runner.Status;
  51. }
  52. private bool VacuumAOff()
  53. {
  54. return _vacuum.VacuumAOff();
  55. }
  56. private bool SaveConfig()
  57. {
  58. _distanceSensor.SaveConfig(_offset1, _offset2);
  59. return true;
  60. }
  61. public RState Start(params object[] objs)
  62. {
  63. if(objs == null || objs.Length == 0)
  64. {
  65. return RState.Failed;
  66. }
  67. _offset1 = STANDARD - (double)objs[1];
  68. _offset2=STANDARD- (double)objs[2];
  69. Runner.Start(Module, Name);
  70. return RState.Running;
  71. }
  72. }
  73. }