IoThrottleValve.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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.Log;
  8. using Aitex.Core.Util;
  9. using Aitex.Platform;
  10. namespace Aitex.Core.RT.Device.Unit
  11. {
  12. public class IoThrottleValve : BaseDevice, IDevice
  13. {
  14. public struct Context
  15. {
  16. public string tvName;
  17. public string aoPressureModeName;
  18. public string aoPressureSetPointName;
  19. public string aoPositionSetPointName;
  20. public string aiPressureFeedbackName;
  21. public string aiPositionFeedbackName;
  22. public string aiStateName;
  23. };
  24. public PressureCtrlMode PressureMode
  25. {
  26. get
  27. {
  28. if (_aoPressureMode == null)
  29. return PressureCtrlMode.TVPositionCtrl;
  30. return Math.Abs(_aoPressureMode.Value - 2)<0.1 ? PressureCtrlMode.TVPositionCtrl : PressureCtrlMode.TVPressureCtrl;
  31. }
  32. set
  33. {
  34. if (_aoPositionSetPoint == null || _aoPressureSetPoint == null || _aoPressureMode == null)
  35. return;
  36. float setpoint = value == PressureCtrlMode.TVPositionCtrl ? 2 : 1;
  37. if (Math.Abs(_aoPressureMode.Value - setpoint) > 0.01)
  38. {
  39. if (value == PressureCtrlMode.TVPositionCtrl)
  40. {
  41. _aoPositionSetPoint.Value = PositionFeedback;
  42. }
  43. else
  44. {
  45. _aoPressureSetPoint.Value = PressureFeedback;
  46. }
  47. _aoPressureMode.Value = setpoint;
  48. }
  49. }
  50. }
  51. public int State
  52. {
  53. get
  54. {
  55. return _aiState==null ? 1: (int)_aiState.Value;
  56. }
  57. }
  58. [Subscription(AITThrottleValvePropertyName.TVPositionSetPoint)]
  59. public float PositionSetpoint
  60. {
  61. get
  62. {
  63. return _aoPositionSetPoint==null ? 0 : _aoPositionSetPoint.Value;
  64. }
  65. set
  66. {
  67. if (_aoPositionSetPoint == null)
  68. return;
  69. _aoPositionSetPoint.Value = value;
  70. }
  71. }
  72. [Subscription(AITThrottleValvePropertyName.TVPosition)]
  73. public float PositionFeedback
  74. {
  75. get
  76. {
  77. return _aiPositionFeedback==null ? 0 : _aiPositionFeedback.Value;
  78. }
  79. }
  80. [Subscription(AITThrottleValvePropertyName.TVPressureSetPoint)]
  81. public float PressureSetpoint
  82. {
  83. get
  84. {
  85. return _aoPressureSetPoint==null ? 0 : _aoPressureSetPoint.Value;
  86. }
  87. set
  88. {
  89. if (_aoPressureSetPoint == null)
  90. return;
  91. _aoPressureSetPoint.Value = value;
  92. }
  93. }
  94. [Subscription(AITThrottleValvePropertyName.TVPressure)]
  95. public float PressureFeedback
  96. {
  97. get
  98. {
  99. return _aiPressureFeedback== null ? 0 : _aiPressureFeedback.Value;
  100. }
  101. }
  102. public bool IsPumpMode
  103. {
  104. get; set;
  105. }
  106. public bool IsIndependent
  107. {
  108. get; set;
  109. }
  110. public bool IsOffline
  111. {
  112. get
  113. {
  114. return _diOffline != null && _diOffline.RawData;
  115. }
  116. }
  117. private DIAccessor _diOffline;
  118. private AIAccessor _aiPressureFeedback = null;
  119. private AIAccessor _aiPositionFeedback = null;
  120. private AOAccessor _aoPressureSetPoint = null;
  121. private AOAccessor _aoPositionSetPoint = null;
  122. private AOAccessor _aoPressureMode = null;
  123. private AIAccessor _aiState = null;
  124. private R_TRIG _tvStatusAlmTrig = new R_TRIG();
  125. private R_TRIG _trigOffline = new R_TRIG();
  126. public IoThrottleValve(string module, XmlElement node)
  127. {
  128. base.Module = module;
  129. base.Name = node.GetAttribute("id");
  130. base.Display = node.GetAttribute("display");
  131. base.DeviceID = node.GetAttribute("schematicId");
  132. _aiPositionFeedback = ParseAiNode("aiPositionFeedback", node);
  133. _aiPressureFeedback = ParseAiNode("aiPressureFeedback", node);
  134. _aoPositionSetPoint = ParseAoNode("aoPositionSetPoint", node);
  135. _aoPressureSetPoint = ParseAoNode("aoPressureSetPoint", node);
  136. _aiState = ParseAiNode("aiState", node);
  137. _aoPressureMode = ParseAoNode("aoPressureMode", node);
  138. _diOffline = ParseDiNode("diOffline", node);
  139. }
  140. public bool Initialize()
  141. {
  142. DATA.Subscribe(string.Format("Device.{0}.{1}", Module , Name), () =>
  143. {
  144. AITThrottleValveData data = new AITThrottleValveData()
  145. {
  146. DeviceName = Name,
  147. DeviceSchematicId = DeviceID,
  148. DisplayName = Display,
  149. Mode = (int)PressureMode,
  150. PositionFeedback = PositionFeedback,
  151. PositionSetPoint = PositionSetpoint,
  152. PressureFeedback = PressureFeedback,
  153. PressureSetPoint = PressureSetpoint,
  154. State = State,
  155. };
  156. return data;
  157. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  158. PressureMode = PressureCtrlMode.TVPressureCtrl;
  159. DEVICE.Register(String.Format("{0}.{1}", Name, AITThrottleValveOperation.SetMode), (out string reason, int time, object[] param) =>
  160. {
  161. PressureMode = (PressureCtrlMode)Enum.Parse(typeof(PressureCtrlMode), (string)param[0], true);
  162. reason = string.Format("Throttle valve set to {0} mode", PressureMode);
  163. return true;
  164. });
  165. DEVICE.Register(String.Format("{0}.{1}", Name, AITThrottleValveOperation.SetPosition), (out string reason, int time, object[] param) =>
  166. {
  167. double target = Convert.ToDouble((string)param[0]);
  168. if (PressureMode != PressureCtrlMode.TVPositionCtrl)
  169. {
  170. reason = "Throttle valve in pressure mode, can not set position";
  171. return false;
  172. }
  173. PositionSetpoint = (float)target;
  174. reason = string.Format("position set to {0}%", target.ToString("F1"));
  175. return true;
  176. });
  177. DEVICE.Register(String.Format("{0}.{1}", Name, AITThrottleValveOperation.SetPressure), (out string reason, int time, object[] param) =>
  178. {
  179. if (PressureMode == PressureCtrlMode.TVPositionCtrl)
  180. {
  181. reason = "Throttle valve is in positon conrol mode, can not set pressure";
  182. return false;
  183. }
  184. double target = Convert.ToDouble((string)param[0]);
  185. PressureSetpoint = (float)target;
  186. reason = string.Format("pressure set {0} mTorr", target);
  187. return true;
  188. });
  189. return true;
  190. }
  191. public void Terminate()
  192. {
  193. }
  194. public void Monitor()
  195. {
  196. try
  197. {
  198. _tvStatusAlmTrig.CLK = State != 1;
  199. if (_tvStatusAlmTrig.Q)
  200. {
  201. EV.PostMessage(Module, EventEnum.ThrottleValveAbnormal, Module);
  202. }
  203. _trigOffline.CLK = IsOffline;
  204. if (_trigOffline.Q)
  205. {
  206. EV.PostMessage(Module, EventEnum.DefaultAlarm, "Throttle Valve Offline");
  207. }
  208. }
  209. catch (Exception ex)
  210. {
  211. LOG.Write(ex);
  212. throw ex;
  213. }
  214. }
  215. public void GernerateDI()
  216. {
  217. }
  218. public void Reset()
  219. {
  220. _tvStatusAlmTrig.RST = true;
  221. _trigOffline.RST = true;
  222. }
  223. public void SetPositionMode(int position)
  224. {
  225. PressureMode = PressureCtrlMode.TVPositionCtrl;
  226. PositionSetpoint = (float)position;
  227. }
  228. }
  229. }