IoHeater.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.Util;
  9. namespace Aitex.Core.RT.Device.Unit
  10. {
  11. public class IoHeater : BaseDevice, IDevice
  12. {
  13. public double SetPointLimit
  14. {
  15. get
  16. {
  17. if (_aoSetPointLimit != null)
  18. return _aoSetPointLimit.Value;
  19. return 100;
  20. }
  21. }
  22. [Subscription(AITHeaterPropertyName.MonitorTcFeedback)]
  23. public float MonitorTcFeedback
  24. {
  25. get
  26. {
  27. if (_aiMonitorTcFeedback != null)
  28. return _aiMonitorTcFeedback.Value;
  29. return 0;
  30. }
  31. }
  32. [Subscription(AITHeaterPropertyName.ControlTcFeedback)]
  33. public float ControlTcFeedback
  34. {
  35. get
  36. {
  37. if (_aiControlTcFeedback != null)
  38. return _aiControlTcFeedback.Value;
  39. return 0;
  40. }
  41. }
  42. [Subscription(AITHeaterPropertyName.ControlTcSetPoint)]
  43. public float ControlTcSetPoint
  44. {
  45. get
  46. {
  47. if (_aoSetPoint != null)
  48. return _aoSetPoint.Value;
  49. return 0;
  50. }
  51. }
  52. [Subscription(AITHeaterPropertyName.IsMonitorTcBroken)]
  53. public bool IsMonitorTcBroken
  54. {
  55. get
  56. {
  57. if (_diMonitorTcBroken != null)
  58. return _diMonitorTcBroken.Value;
  59. return false;
  60. }
  61. }
  62. [Subscription(AITHeaterPropertyName.IsControlTcBroken)]
  63. public bool IsControlTcBroken
  64. {
  65. get
  66. {
  67. if (_diControlTcBroken != null)
  68. return _diControlTcBroken.Value;
  69. return false;
  70. }
  71. }
  72. [Subscription(AITHeaterPropertyName.IsPowerOnFeedback)]
  73. public bool IsPowerOnFeedback
  74. {
  75. get
  76. {
  77. if (_diPowerOnFeedback != null)
  78. return _diPowerOnFeedback.Value;
  79. if (_doPowerOn != null)
  80. return _doPowerOn.Value;
  81. return false;
  82. }
  83. }
  84. [Subscription(AITHeaterPropertyName.IsPowerOnSetPoint)]
  85. public bool IsPowerOnSetPoint
  86. {
  87. get
  88. {
  89. if (_doPowerOn != null)
  90. return _doPowerOn.Value;
  91. return false;
  92. }
  93. }
  94. public string Unit
  95. {
  96. get; set;
  97. }
  98. /*
  99. doPowerOn="DO_Chamber_heater_power_contactor__coil"
  100. diPowerOnFeedback="DI_Chamber_heater_power_fb"
  101. diControlTcBroken="DI_chamber_wall_control_tc_broken"
  102. diMonitorTcBroken="DI_chamber_wall_monitor_tc_broken"
  103. aoSetPoint="AO_chamber_wall_temp_setpotint"
  104. aiFeedback="AI_Chamber_wall_control_tc_fb"
  105. aoSetPointLimit="AO_chamber_wall_temp_limit_setpotint"
  106. aiMonitor="AI_chamber_wall_monitor_tc_fb"/>
  107. *
  108. */
  109. private DIAccessor _diPowerOnFeedback = null;
  110. private DIAccessor _diControlTcBroken;
  111. private DIAccessor _diMonitorTcBroken;
  112. private DOAccessor _doPowerOn = null;
  113. private AIAccessor _aiControlTcFeedback = null;
  114. private AIAccessor _aiMonitorTcFeedback = null;
  115. private AOAccessor _aoSetPoint = null;
  116. private AOAccessor _aoSetPointLimit = null;
  117. private R_TRIG _trigMonitorTcBroken = new R_TRIG();
  118. private R_TRIG _trigControlTcBroken = new R_TRIG();
  119. public IoHeater(string module, XmlElement node, string ioModule = "")
  120. {
  121. base.Module = module;
  122. base.Name = node.GetAttribute("id");
  123. base.Display = node.GetAttribute("display");
  124. base.DeviceID = node.GetAttribute("schematicId");
  125. Unit = node.GetAttribute("unit");
  126. _diPowerOnFeedback = ParseDiNode("diPowerOnFeedback", node, ioModule);
  127. _diControlTcBroken = ParseDiNode("diControlTcBroken", node, ioModule);
  128. _diMonitorTcBroken = ParseDiNode("diMonitorTcBroken", node, ioModule);
  129. _doPowerOn = ParseDoNode("doPowerOn", node, ioModule);
  130. _aiControlTcFeedback = ParseAiNode("aiFeedback", node, ioModule);
  131. _aiMonitorTcFeedback = ParseAiNode("aiMonitor", node, ioModule);
  132. _aoSetPoint = ParseAoNode("aoSetPoint", node, ioModule);
  133. _aoSetPointLimit = ParseAoNode("aoSetPointLimit", node, ioModule);
  134. }
  135. public void UpdateConfig(double setPointLimit)
  136. {
  137. if (_aoSetPointLimit != null)
  138. _aoSetPointLimit.Value = (short)setPointLimit;
  139. }
  140. public bool Initialize()
  141. {
  142. DATA.Subscribe(string.Format("{0}.{1}.DeviceData", Module , Name), () =>
  143. {
  144. AITHeaterData data = new AITHeaterData()
  145. {
  146. Module = Module,
  147. DeviceName = Name,
  148. DeviceSchematicId = DeviceID,
  149. DisplayName = Display,
  150. FeedBack = ControlTcFeedback,
  151. MonitorTcFeedBack = MonitorTcFeedback,
  152. Scale = SetPointLimit,
  153. SetPoint = ControlTcSetPoint,
  154. IsPowerOn = IsPowerOnFeedback,
  155. IsPowerOnSetPoint = IsPowerOnSetPoint,
  156. IsControlTcBroken = IsControlTcBroken,
  157. IsMonitorTcBroken = IsMonitorTcBroken,
  158. Unit = Unit,
  159. };
  160. return data;
  161. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  162. OP.Subscribe($"{Module}.{Name}.{AITHeaterOperation.SetPowerOnOff}", ( string functionName, object[] param) =>
  163. {
  164. bool isEnable = Convert.ToBoolean((string)param[0]);
  165. if (!_doPowerOn.SetValue(isEnable, out string reason))
  166. {
  167. EV.PostWarningLog(Module, reason);
  168. return false;
  169. }
  170. EV.PostInfoLog(Module, string.Format("Set Heater {0} Power {1}", Name, isEnable ? "On" : "Off"));
  171. return true;
  172. });
  173. OP.Subscribe($"{Module}.{Name}.{AITHeaterOperation.Ramp}", (string functionName, object[] param) =>
  174. {
  175. float setpoint = (float)Convert.ToDouble((string)param[0]);
  176. if (!RampTemp(setpoint)) return false;
  177. return true;
  178. });
  179. DEVICE.Register(String.Format("{0}.{1}", Name, AITHeaterOperation.SetPowerOnOff), (out string reason, int time, object[] param) =>
  180. {
  181. reason = "";
  182. bool isEnable = Convert.ToBoolean((string)param[0]);
  183. bool result = true;
  184. if (_doPowerOn != null)
  185. {
  186. result &= _doPowerOn.SetValue(isEnable, out reason);
  187. }
  188. if (result)
  189. reason = string.Format("Set Heater {0} Power {1}", Name, isEnable ? "On" : "Off");
  190. return result;
  191. });
  192. DEVICE.Register(String.Format("{0}.{1}", Name, AITHeaterOperation.Ramp), (out string reason, int time, object[] param) =>{
  193. float setpoint = (float) Convert.ToDouble( (string) param[0]);
  194. if (setpoint > SetPointLimit || setpoint < 0)
  195. {
  196. reason = string.Format("Heater {0} temperature setpoint {1} is not valid, should be (0, {2})", Display, setpoint, SetPointLimit);
  197. }
  198. if (_aoSetPoint != null)
  199. _aoSetPoint.Value = (short)setpoint;
  200. reason = string.Format("Heater {0} Set to {1}", Display, setpoint);
  201. return true;
  202. });
  203. return true;
  204. }
  205. public bool RampTemp(float setpoint)
  206. {
  207. if (setpoint > SetPointLimit || setpoint < 0)
  208. {
  209. EV.PostWarningLog(Module,
  210. $"Heater {Name} temperature setpoint {setpoint} is not valid, should be (0, {SetPointLimit})");
  211. return false;
  212. }
  213. if (_aoSetPoint != null)
  214. _aoSetPoint.Value = (short) setpoint;
  215. EV.PostInfoLog(Module, string.Format("Heater {0} Set to {1}", Display, setpoint));
  216. return true;
  217. }
  218. public void Stop()
  219. {
  220. if (_aoSetPoint != null)
  221. {
  222. _aoSetPoint.Value = 0;
  223. }
  224. }
  225. public void Terminate()
  226. {
  227. }
  228. public void Monitor()
  229. {
  230. _trigControlTcBroken.CLK = IsControlTcBroken;
  231. if (_trigControlTcBroken.Q)
  232. {
  233. EV.PostMessage(Module, EventEnum.DefaultAlarm, string.Format("{0}, found control TC broken", Display));
  234. }
  235. _trigMonitorTcBroken.CLK = IsMonitorTcBroken;
  236. if (_trigMonitorTcBroken.Q)
  237. {
  238. EV.PostMessage(Module, EventEnum.DefaultAlarm, string.Format("{0}, found monitor TC broken", Display));
  239. }
  240. }
  241. public void Reset()
  242. {
  243. _trigControlTcBroken.RST = true;
  244. _trigMonitorTcBroken.RST = true;
  245. }
  246. }
  247. }