Mini8Info.cs 3.7 KB

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