IoHeater.cs 8.3 KB

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