IoSignalTower.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using Aitex.Core.Common.DeviceData;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Device;
  7. using Aitex.Core.RT.Device.Unit;
  8. using Aitex.Core.Util;
  9. using Aitex.Platform;
  10. using Aitex.Triton160.Common;
  11. namespace Aitex.Triton160.RT.Device
  12. {
  13. public enum LightType
  14. {
  15. RED, GREEN, YELLOW, BUZZER
  16. }
  17. public enum LightStatus
  18. {
  19. OFF, ON, BLINK
  20. }
  21. public class IoSignalTower : BaseDevice, IDevice
  22. {
  23. //device
  24. private IoSignalLight red = null;
  25. private IoSignalLight yellow = null;
  26. private IoSignalLight green = null;
  27. private IoSignalLight alarmBuzzer = null;
  28. private bool _buzzerCleared = false;
  29. /// <summary>
  30. /// 用于生成闪烁信号
  31. /// </summary>
  32. private bool binking = false;
  33. /// <summary>
  34. /// 闪烁定时器 (500ms)
  35. /// </summary>
  36. private DeviceTimer timer = new DeviceTimer();
  37. /// <summary>
  38. /// 信号灯状态定义
  39. /// </summary>
  40. public TowerLightStatus Red { get; private set; }
  41. public TowerLightStatus Yellow { get; private set; }
  42. public TowerLightStatus Green { get; private set; }
  43. public TowerLightStatus Buzzer_Alarm { get; private set; }
  44. public bool IsGreenOn => green.Value;
  45. public bool IsYellowOn => yellow.Value;
  46. public bool IsRedOn => red.Value;
  47. public bool IsBuzzerOn = false;
  48. public DeviceTimer _timerBuzzerBlinking = new DeviceTimer();
  49. public IoSignalTower(string module, string name, string display, string deviceID) :
  50. base(module, name, display, deviceID)
  51. {
  52. }
  53. public bool Initialize()
  54. {
  55. red = DeviceModel.SignalTowerRedLight;
  56. yellow = DeviceModel.SignalTowerYellowLight;
  57. green = DeviceModel.SignalTowerGreenLight;
  58. alarmBuzzer = DeviceModel.SignalTowerBuzzer;
  59. Debug.Assert(red != null && yellow != null && green != null && alarmBuzzer != null);
  60. DATA.Subscribe(string.Format("Device.{0}.{1}", ModuleName.System, Name), () =>
  61. {
  62. AITSignalTowerData data = new AITSignalTowerData()
  63. {
  64. DeviceName = Name,
  65. DeviceSchematicId = DeviceID,
  66. DisplayName = Display,
  67. IsBlueLightOn = false,
  68. IsGreenLightOn = IsGreenOn,
  69. IsRedLightOn = IsRedOn,
  70. IsYellowLightOn = IsYellowOn,
  71. };
  72. return data;
  73. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  74. DEVICE.Register(string.Format("{0}.{1}", Name, AITSignalTowerOperation.SwitchOffBuzzer), (out string reason, int time, object[] param) =>
  75. {
  76. reason = "";
  77. PMState state = (PMState)DATA.Poll(ModuleNameString.System, StateData.PMState.ToString());
  78. _buzzerCleared = state == PMState.Error;
  79. alarmBuzzer.Value = false;
  80. return true;
  81. });
  82. return true;
  83. }
  84. public void Terminate()
  85. {
  86. }
  87. /// <summary>
  88. /// 控制各种灯
  89. /// </summary>
  90. /// <param name="light"></param>
  91. /// <param name="st"></param>
  92. public void SetLight(LightType light, LightStatus st)
  93. {
  94. switch (light)
  95. {
  96. case LightType.RED:
  97. red.Value = st == LightStatus.ON ? true : false;
  98. break;
  99. case LightType.GREEN:
  100. green.Value = st == LightStatus.ON ? true : false;
  101. break;
  102. case LightType.YELLOW:
  103. yellow.Value = st == LightStatus.ON ? true : false;
  104. break;
  105. case LightType.BUZZER:
  106. // TODO, buzzer暂时还用老的BuzzerBlinking [4/30/2020 TerryLu]
  107. break;
  108. default:
  109. break;
  110. }
  111. }
  112. //响3声,通知工艺正常结束
  113. public void BuzzerBlinking(double time)
  114. {
  115. IsBuzzerOn = true;
  116. _timerBuzzerBlinking.Start(time);
  117. }
  118. public void BuzzerStop()
  119. {
  120. IsBuzzerOn = false;
  121. _timerBuzzerBlinking.Stop();
  122. }
  123. public void Monitor()
  124. {
  125. Buzzer_Alarm = TowerLightStatus.Off;
  126. if (timer.IsIdle())
  127. timer.Start(500);
  128. if (timer.IsTimeout())
  129. {
  130. timer.Start(500);
  131. binking = !binking;
  132. }
  133. PMState state = (PMState)DATA.Poll(ModuleNameString.System, StateData.PMState.ToString());
  134. List<IoValve> valves = DEVICE.GetDevice<IoValve>();
  135. //pumping valve开,vent purge valve开,Gas valve开,RF开,只要有其中之一处于开的状态,就是绿灯
  136. if (state == PMState.Error)
  137. {
  138. Green = TowerLightStatus.Off;
  139. Red = TowerLightStatus.On;
  140. Yellow = TowerLightStatus.Off;
  141. Buzzer_Alarm = _buzzerCleared ? TowerLightStatus.Off : TowerLightStatus.On;
  142. }
  143. else if (DeviceModel.Rf.IsRfOn || valves.Exists(v => v.Status))
  144. {
  145. Green = TowerLightStatus.On;
  146. Red = TowerLightStatus.Off;
  147. Yellow = TowerLightStatus.Off;
  148. Buzzer_Alarm = TowerLightStatus.Off;
  149. }
  150. else
  151. {
  152. Green = TowerLightStatus.Off;
  153. Red = TowerLightStatus.Off;
  154. Yellow = TowerLightStatus.On;
  155. }
  156. if (!_timerBuzzerBlinking.IsIdle() && !_timerBuzzerBlinking.IsTimeout())
  157. {
  158. Buzzer_Alarm = IsBuzzerOn ? TowerLightStatus.On : TowerLightStatus.Off;
  159. }
  160. else
  161. {
  162. Buzzer_Alarm = TowerLightStatus.Off;
  163. IsBuzzerOn = false;
  164. }
  165. //update tower light status
  166. switch (Red)
  167. {
  168. case TowerLightStatus.On:
  169. red.Value = true;
  170. break;
  171. case TowerLightStatus.Off:
  172. red.Value = false;
  173. break;
  174. case TowerLightStatus.Blinking:
  175. red.Value = binking;
  176. break;
  177. }
  178. switch (Yellow)
  179. {
  180. case TowerLightStatus.On:
  181. yellow.Value = true;
  182. break;
  183. case TowerLightStatus.Off:
  184. yellow.Value = false;
  185. break;
  186. case TowerLightStatus.Blinking:
  187. yellow.Value = binking;
  188. break;
  189. }
  190. switch (Green)
  191. {
  192. case TowerLightStatus.On:
  193. green.Value = true;
  194. break;
  195. case TowerLightStatus.Off:
  196. green.Value = false;
  197. break;
  198. case TowerLightStatus.Blinking:
  199. green.Value = binking;
  200. break;
  201. }
  202. switch (Buzzer_Alarm)
  203. {
  204. case TowerLightStatus.On:
  205. alarmBuzzer.Value = true;
  206. break;
  207. case TowerLightStatus.Off:
  208. alarmBuzzer.Value = false;
  209. break;
  210. case TowerLightStatus.Blinking:
  211. alarmBuzzer.Value = binking;
  212. break;
  213. }
  214. //System.Diagnostics.Trace.WriteLine(DateTime.Now.Minute.ToString() + ":"+DateTime.Now.Second+"."+DateTime.Now.Millisecond+ "," + (alarmBuzzer.Value ? "1" : "0"));
  215. }
  216. /// <summary>
  217. /// 关闭所有灯和蜂鸣器
  218. /// </summary>
  219. public void Reset()
  220. {
  221. red.Value = false;
  222. yellow.Value = false;
  223. green.Value = false;
  224. alarmBuzzer.Value = false;
  225. _buzzerCleared = false;
  226. }
  227. }
  228. }