IoThrottleValve2.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.IOCore;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.Utilities;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Xml;
  11. namespace Aitex.Core.RT.Device.Unit
  12. {
  13. public class IoThrottleValve2 : BaseDevice, IDevice
  14. {
  15. public PressureCtrlMode PressureMode
  16. {
  17. get
  18. {
  19. if (_aoPressureMode != null)
  20. {
  21. foreach (var ioMode in _ctrlModeIoValue)
  22. {
  23. if (_isFloatAioType)
  24. {
  25. if ((int)_aoPressureMode.FloatValue == ioMode.Value)
  26. {
  27. return ioMode.Key;
  28. }
  29. }
  30. else
  31. {
  32. if (_aoPressureMode.Value == ioMode.Value)
  33. {
  34. return ioMode.Key;
  35. }
  36. }
  37. }
  38. return PressureCtrlMode.Undefined;
  39. }
  40. return PressureCtrlMode.Undefined;
  41. }
  42. set
  43. {
  44. if (_isFloatAioType)
  45. _aoPressureMode.FloatValue = _ctrlModeIoValue[value];
  46. else
  47. {
  48. _aoPressureMode.Value = (short)_ctrlModeIoValue[value];
  49. }
  50. }
  51. }
  52. public float PositionSetpoint
  53. {
  54. get
  55. {
  56. return _aoPositionSetPoint == null ? 0 : (_isFloatAioType? _aoPositionSetPoint.FloatValue: _aoPositionSetPoint.Value);
  57. }
  58. set
  59. {
  60. if (_isFloatAioType)
  61. {
  62. _aoPositionSetPoint.FloatValue = value;
  63. }
  64. else
  65. {
  66. _aoPositionSetPoint.Value = (short)value;
  67. }
  68. }
  69. }
  70. public float PositionFeedback
  71. {
  72. get
  73. {
  74. return _aiPositionFeedback == null ? 0 : (_isFloatAioType ? _aiPositionFeedback.FloatValue: _aiPositionFeedback.Value);
  75. }
  76. }
  77. public float PressureSetpoint
  78. {
  79. get
  80. {
  81. return _aoPressureSetPoint == null ? 0 : (_isFloatAioType ? _aoPressureSetPoint.FloatValue:_aoPressureSetPoint.Value);
  82. }
  83. set
  84. {
  85. if (_isFloatAioType)
  86. {
  87. _aoPressureSetPoint.FloatValue = value;
  88. }
  89. else
  90. {
  91. _aoPressureSetPoint.Value = (short)value;
  92. }
  93. }
  94. }
  95. public float PressureFeedback
  96. {
  97. get
  98. {
  99. return _aiPressureFeedback == null ? 0 : (_isFloatAioType ? _aiPressureFeedback.FloatValue:_aiPressureFeedback.Value);
  100. }
  101. }
  102. private AITThrottleValveData DeviceData
  103. {
  104. get
  105. {
  106. AITThrottleValveData data = new AITThrottleValveData()
  107. {
  108. Module = Module,
  109. DeviceName = Name,
  110. DeviceSchematicId = DeviceID,
  111. DisplayName = Display,
  112. Mode = (int)PressureMode,
  113. PositionFeedback = PositionFeedback,
  114. PositionSetPoint = PositionSetpoint,
  115. PressureFeedback = PressureFeedback,
  116. PressureSetPoint = PressureSetpoint,
  117. MaxValuePosition = 100,
  118. MaxValuePressure = _unitPressure == "Torr" ? 760 : 760000,
  119. UnitPressure = _unitPressure,
  120. };
  121. return data;
  122. }
  123. }
  124. private AOAccessor _aoPressureMode = null;
  125. private AIAccessor _aiPositionFeedback = null;
  126. private AOAccessor _aoPositionSetPoint = null;
  127. private AIAccessor _aiPressureFeedback = null;
  128. private AOAccessor _aoPressureSetPoint = null;
  129. private string _unitPressure;
  130. private Dictionary<PressureCtrlMode, int> _ctrlModeIoValue = new Dictionary<PressureCtrlMode, int>();
  131. private bool _isFloatAioType = false;
  132. public IoThrottleValve2(string module, XmlElement node, string ioModule = "")
  133. {
  134. var attrModule = node.GetAttribute("module");
  135. base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
  136. base.Name = node.GetAttribute("id");
  137. base.Display = node.GetAttribute("display");
  138. base.DeviceID = node.GetAttribute("schematicId");
  139. _unitPressure = node.GetAttribute("unit");
  140. _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
  141. _aoPressureMode = ParseAoNode("aoPressureMode", node, ioModule);
  142. _aiPositionFeedback = ParseAiNode("aiPositionFeedback", node, ioModule);
  143. _aoPositionSetPoint = ParseAoNode("aoPositionSetPoint", node, ioModule);
  144. _aiPressureFeedback = ParseAiNode("aiPressureFeedback", node, ioModule);
  145. _aoPressureSetPoint = ParseAoNode("aoPressureSetPoint", node, ioModule);
  146. EnumLoop<PressureCtrlMode>.ForEach(x => _ctrlModeIoValue[x] = -1);
  147. if (!string.IsNullOrEmpty(node.GetAttribute("modeValuePressure")))
  148. {
  149. _ctrlModeIoValue[PressureCtrlMode.TVPressureCtrl] = int.Parse(node.GetAttribute("modeValuePressure"));
  150. }
  151. if (!string.IsNullOrEmpty(node.GetAttribute("modeValuePosition")))
  152. {
  153. _ctrlModeIoValue[PressureCtrlMode.TVPositionCtrl] = int.Parse(node.GetAttribute("modeValuePosition"));
  154. }
  155. if (!string.IsNullOrEmpty(node.GetAttribute("modeValueOpen")))
  156. {
  157. _ctrlModeIoValue[PressureCtrlMode.TVOpen] = int.Parse(node.GetAttribute("modeValueOpen"));
  158. }
  159. if (!string.IsNullOrEmpty(node.GetAttribute("modeValueClose")))
  160. {
  161. _ctrlModeIoValue[PressureCtrlMode.TVClose] = int.Parse(node.GetAttribute("modeValueClose"));
  162. }
  163. }
  164. public bool Initialize()
  165. {
  166. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  167. DATA.Subscribe($"{Module}.{Name}.PositionSetPoint", () => PositionSetpoint);
  168. DATA.Subscribe($"{Module}.{Name}.PositionFeedback", () => PositionFeedback);
  169. DATA.Subscribe($"{Module}.{Name}.PressureSetPoint", () => PressureSetpoint);
  170. DATA.Subscribe($"{Module}.{Name}.PressureFeedback", () => PressureFeedback);
  171. DATA.Subscribe($"{Module}.{Name}.Mode", () => PressureMode);
  172. OP.Subscribe($"{Module}.{Name}.{AITThrottleValveOperation.SetMode}", SetMode);
  173. OP.Subscribe($"{Module}.{Name}.{AITThrottleValveOperation.SetPosition}", SetPosition);
  174. OP.Subscribe($"{Module}.{Name}.{AITThrottleValveOperation.SetPressure}", SetPressure);
  175. return true;
  176. }
  177. public bool SetMode(PressureCtrlMode mode, out string reason)
  178. {
  179. PressureMode = mode;
  180. reason = $"{Display} set to {mode}";
  181. EV.PostInfoLog(Module, reason);
  182. return true;
  183. }
  184. private bool SetMode(out string reason, int time, object[] param)
  185. {
  186. return SetMode((PressureCtrlMode)Enum.Parse(typeof(PressureCtrlMode), (string)param[0], true),
  187. out reason);
  188. }
  189. public bool SetPosition(float position, out string reason)
  190. {
  191. PositionSetpoint = position;
  192. reason = $"{Display} position set to {position}";
  193. EV.PostInfoLog(Module, reason);
  194. return true;
  195. }
  196. private bool SetPosition(out string reason, int time, object[] param)
  197. {
  198. return SetPosition(Convert.ToSingle(param[0].ToString()), out reason);
  199. }
  200. private bool SetPressure(out string reason, int time, object[] param)
  201. {
  202. return SetPressure(Convert.ToSingle(param[0].ToString()), out reason);
  203. }
  204. public bool SetPressure(float pressure, out string reason)
  205. {
  206. PressureSetpoint = pressure;
  207. reason = $"{Display} pressure set to {pressure} {_unitPressure}";
  208. EV.PostInfoLog(Module, reason);
  209. return true;
  210. }
  211. public void Terminate()
  212. {
  213. }
  214. public void Monitor()
  215. {
  216. try
  217. {
  218. }
  219. catch (Exception ex)
  220. {
  221. LOG.Write(ex);
  222. }
  223. }
  224. public void Reset()
  225. {
  226. }
  227. }
  228. }