RecipeToleranceChecker.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using Aitex.Core.RT.Log;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Venus_Core;
  9. namespace Aitex.Core.RT.Tolerance
  10. {
  11. public class RecipeToleranceChecker
  12. {
  13. Stopwatch _stopwatch;
  14. List<ToleranceObject> _toleranceObjects;
  15. string _Module;
  16. public RecipeToleranceChecker(string module)
  17. {
  18. _stopwatch = new Stopwatch();
  19. _Module = module;
  20. }
  21. public void Start( List<ToleranceObject> toleranceObjects)
  22. {
  23. _stopwatch.Restart();
  24. _toleranceObjects = toleranceObjects;
  25. }
  26. public void Monitor(params double[] feedBacks)
  27. {
  28. if (_toleranceObjects == null)
  29. {
  30. return;
  31. }
  32. for (int i = 0; i < _toleranceObjects.Count; i++)
  33. {
  34. if (_stopwatch.ElapsedMilliseconds > _toleranceObjects[i].DelayTime)
  35. {
  36. if ((feedBacks[i] < _toleranceObjects[i].WarningMin || feedBacks[i] > _toleranceObjects[i].WarningMax) && _toleranceObjects[i].WarningFlag == false)
  37. {
  38. _toleranceObjects[i].WarningFlag = true;
  39. LOG.Write(eEvent.WARN_PM_TOLERANCE, _Module, $"{_toleranceObjects[i].Name}:Currnt Value:{feedBacks[i]},Over Range {_toleranceObjects[i].WarningMin}-{_toleranceObjects[i].WarningMax}");
  40. }
  41. if ((feedBacks[i] < _toleranceObjects[i].AlarmMin || feedBacks[i] > _toleranceObjects[i].AlarmMax) && _toleranceObjects[i].AlarmFlag == false && _toleranceObjects[i].WarningFlag == true)
  42. {
  43. _toleranceObjects[i].AlarmFlag = true;
  44. LOG.Write(eEvent.ERR_PM_TOLERANCE, _Module, $"{_toleranceObjects[i].Name}:Currnt Value:{feedBacks[i]},Over Range {_toleranceObjects[i].AlarmMin}-{_toleranceObjects[i].AlarmMax}");
  45. }
  46. }
  47. }
  48. }
  49. public void End()
  50. {
  51. _stopwatch.Stop();
  52. }
  53. }
  54. public class ToleranceObject
  55. {
  56. public string Name { get; set; }
  57. public int SetPoint { get; set; }
  58. public int WarningScale { get; set; }
  59. public int AlarmScale { get; set; }
  60. public bool WarningFlag { get; set; }
  61. public bool AlarmFlag { get; set; }
  62. public int DelayTime { get; set; }
  63. public int WarningMax { get; set; }
  64. public int WarningMin { get; set; }
  65. public int AlarmMax { get; set; }
  66. public int AlarmMin { get; set; }
  67. public ToleranceObject(string name, int setPoint, int warningScale, int alarmScale, int delayTime, ToleranceMode toleranceMode)
  68. {
  69. Name = name;
  70. SetPoint = setPoint;
  71. DelayTime = delayTime;
  72. if (toleranceMode == ToleranceMode.Percent)
  73. {
  74. WarningScale = SetPoint * warningScale / 100;
  75. AlarmScale = SetPoint * alarmScale / 100;
  76. }
  77. else
  78. {
  79. WarningScale = warningScale;
  80. AlarmScale = alarmScale;
  81. }
  82. WarningMax = setPoint + WarningScale;
  83. WarningMin = setPoint - WarningScale;
  84. AlarmMax = setPoint + AlarmScale;
  85. AlarmMin = setPoint - AlarmScale;
  86. }
  87. }
  88. }