Mini8Info.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. namespace HistoryView.Data;
  2. public partial class Mini8Info(IEnableDeviceNotify? enableDevice) : ObservableObject
  3. {
  4. [ObservableProperty]
  5. private byte _index;
  6. [ObservableProperty]
  7. private string? _Name;
  8. [ObservableProperty]
  9. private string? _Address;
  10. [ObservableProperty]
  11. private int _Port;
  12. [ObservableProperty]
  13. private bool _Enable;
  14. [ObservableProperty]
  15. private Mini8Status _Status;
  16. [ObservableProperty]
  17. private bool _IsConnected;
  18. partial void OnEnableChanging(bool value)
  19. {
  20. enableDevice?.EnableDevice(this.Index, value);
  21. }
  22. }
  23. public interface IEnableDeviceNotify
  24. {
  25. void EnableDevice(byte mini8Index, bool isEnable);
  26. }
  27. public delegate void PVChanged(float pv, DateTime changeTime);
  28. public partial class Channel : ObservableObject
  29. {
  30. partial void OnPVChanged(float value)
  31. {
  32. if (this.Inhibit == Inhibit.Disable)
  33. {
  34. this.Status = ChannelSuatus.Normal;
  35. return;
  36. }
  37. if (this.ChannelMode==ChannelMode.UnUsed)
  38. {
  39. this.Status = ChannelSuatus.Normal;
  40. return;
  41. }
  42. if (this.SensorBreakAlarm == TcBorken.Error)
  43. {
  44. this.Status = ChannelSuatus.Error;
  45. return;
  46. }
  47. DateTime time = DateTime.Now;
  48. PVRingBuffer.Insert(value);
  49. DateTimeRingBuffer.Insert(time);
  50. this.OnPVChangedEvent?.Invoke(value, time);
  51. if (this.ChannelMode == ChannelMode.Monitor)
  52. {
  53. this.Status = ChannelSuatus.Normal;
  54. return;
  55. }
  56. if (!value.InRange(Floor, Caps))
  57. {
  58. this.Status = ChannelSuatus.Error;
  59. return;
  60. }
  61. if (!value.InRange(FloorWarning, CapsWarning))
  62. {
  63. this.Status = ChannelSuatus.Warning;
  64. return;
  65. }
  66. this.Status = ChannelSuatus.Normal;
  67. }
  68. public byte Mini8Index { get; set; }
  69. public byte ChannelIndex { get; set; }
  70. public event PVChanged? OnPVChangedEvent;
  71. public readonly RingBuffer<float> PVRingBuffer = new(120);
  72. public readonly RingBuffer<DateTime> DateTimeRingBuffer = new(120);
  73. [ObservableProperty]
  74. private string? _Name;
  75. [ObservableProperty]
  76. private float _Caps;
  77. [ObservableProperty]
  78. private float _Floor;
  79. [ObservableProperty]
  80. private float _CapsWarning;
  81. [ObservableProperty]
  82. private float _FloorWarning;
  83. [ObservableProperty]
  84. private ChannelSuatus _Status;
  85. [ObservableProperty]
  86. private ChannelMode _ChannelMode;
  87. [ObservableProperty]
  88. private float _PV;
  89. [ObservableProperty]
  90. private float _WorkingOutput;
  91. [ObservableProperty]
  92. private AutoTuneStatus _AutoTuneStatus;
  93. [ObservableProperty]
  94. private float _AutoTune_P;
  95. [ObservableProperty]
  96. private float _AutoTune_I;
  97. [ObservableProperty]
  98. private float _AutoTune_D;
  99. [ObservableProperty]
  100. private TcBorken _SensorBreakAlarm;
  101. [ObservableProperty]
  102. private float _SetPoint;
  103. [ObservableProperty]
  104. private ActiveTuneSet _ActiveTuneSet;
  105. [ObservableProperty]
  106. private float _Running_P;
  107. [ObservableProperty]
  108. private float _Running_I;
  109. [ObservableProperty]
  110. private float _Running_D;
  111. [ObservableProperty]
  112. private Inhibit _Inhibit;
  113. [ObservableProperty]
  114. private float _SetpointUpRate;
  115. [ObservableProperty]
  116. private float _SetpointDownRate;
  117. }
  118. public enum Mini8Status
  119. {
  120. Unknow,
  121. Normal,
  122. Error,
  123. Warning,
  124. LostConnection,
  125. Disabled
  126. }
  127. public enum ChannelSuatus
  128. {
  129. Normal,
  130. Error,
  131. Warning,
  132. }