IoMFM.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.IOCore;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.RT.Tolerance;
  10. using Aitex.Core.Util;
  11. using Aitex.Core.Utilities;
  12. using MECF.Framework.Common.Event;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MFCs;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Xml;
  17. namespace FurnaceRT.Equipments.PMs.Devices
  18. {
  19. public class IoMFM : BaseDevice, IDevice
  20. {
  21. public string Unit
  22. {
  23. get; set;
  24. }
  25. public double Scale
  26. {
  27. get
  28. {
  29. if (_scN2Scale == null)
  30. return 0;
  31. return _scN2Scale.DoubleValue;
  32. }
  33. }
  34. public double FeedBack
  35. {
  36. get
  37. {
  38. if (_aiFlow != null)
  39. {
  40. return _isFloatAioType ? _aiFlow.FloatValue : _aiFlow.Value;
  41. }
  42. return 0;
  43. }
  44. }
  45. public double Setpoint
  46. {
  47. get
  48. {
  49. if (_aoFlow != null)
  50. {
  51. return _isFloatAioType ? _aoFlow.FloatValue : _aoFlow.Value;
  52. }
  53. return _setpoint;
  54. }
  55. }
  56. public bool EnableAlarm
  57. {
  58. get
  59. {
  60. if (_scEnableAlarm != null)
  61. return _scEnableAlarm.BoolValue;
  62. return false;
  63. }
  64. }
  65. private AITWaterFlowMeterData DeviceData
  66. {
  67. get
  68. {
  69. AITWaterFlowMeterData data = new AITWaterFlowMeterData()
  70. {
  71. DeviceName = Name,
  72. DeviceSchematicId = DeviceID,
  73. DisplayName = DisplayName,
  74. FeedBack = FeedBack < 0 ? 0 : FeedBack,
  75. SetPoint = Setpoint < 0 ? 0 : Setpoint,
  76. AlarmWatchTable = AlarmWatchTable,
  77. Unit = Unit,
  78. Scale = Scale,
  79. UniqueName = $"{Module}.{Name}",
  80. };
  81. return data;
  82. }
  83. }
  84. public string DisplayName
  85. {
  86. get
  87. {
  88. if (_scGasName != null)
  89. return _scGasName.StringValue;
  90. return Display;
  91. }
  92. }
  93. public string AlarmWatchTable
  94. {
  95. get;
  96. set;
  97. }
  98. private float _setpoint;
  99. private double _phyScale;
  100. private ToleranceChecker _toleranceCheckerWarning = new ToleranceChecker();
  101. private ToleranceChecker _toleranceCheckerAlarm = new ToleranceChecker();
  102. private AIAccessor _aiFlow;
  103. private AOAccessor _aoFlow;
  104. private AIAccessor _aiCheck;
  105. protected SCConfigItem _scGasName;
  106. private SCConfigItem _scN2Scale;
  107. private SCConfigItem _scEnableAlarm;
  108. //tolerance check
  109. private float _alarmJudgmentRange;
  110. private float _warningJudgmentRange;
  111. private float _alarmJudgmentTime;
  112. private float _warningJudgmentTime;
  113. private float _toleranceJudgmentDelayTime;
  114. private DeviceTimer _toleranceJudgmentDelayTimer = new DeviceTimer();
  115. private int _toleranceAlarmEventId;
  116. private int _toleranceWarningEventId;
  117. public AlarmEventItem AlarmToleranceWarning { get; set; }
  118. public AlarmEventItem AlarmToleranceAlarm { get; set; }
  119. private bool _isFloatAioType = false;
  120. public IoMFM(string module, XmlElement node, string ioModule = "")
  121. {
  122. Unit = node.GetAttribute("unit");
  123. base.Module = string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  124. base.Name = node.GetAttribute("id");
  125. base.Display = node.GetAttribute("display");
  126. base.DeviceID = node.GetAttribute("schematicId");
  127. int.TryParse(node.GetAttribute("toleranceAlarmEventId"), out _toleranceAlarmEventId);
  128. int.TryParse(node.GetAttribute("toleranceWarningEventId"), out _toleranceWarningEventId);
  129. _aiFlow = ParseAiNode("aiFlow", node, ioModule);
  130. _aoFlow = ParseAoNode("aoFlow", node, ioModule);
  131. _isFloatAioType = !string.IsNullOrEmpty(node.GetAttribute("aioType")) && (node.GetAttribute("aioType") == "float");
  132. string scBasePath = node.GetAttribute("scBasePath");
  133. if (string.IsNullOrEmpty(scBasePath))
  134. scBasePath = $"{Module}.{Name}";
  135. else
  136. {
  137. scBasePath = scBasePath.Replace("{module}", Module);
  138. }
  139. _scGasName = SC.GetConfigItem($"{scBasePath}.{Name}.Name");
  140. _scN2Scale = ParseScNode("scN2Scale", node, ioModule, $"{scBasePath}.{Name}.N2Scale");
  141. _scEnableAlarm = ParseScNode("scEnableAlarm", node, ioModule, $"{scBasePath}.{Name}.EnableAlarm");
  142. if (SC.ContainsItem($"{scBasePath}.{Name}.FlowUnit"))
  143. Unit = SC.GetStringValue($"{scBasePath}.{Name}.FlowUnit");
  144. }
  145. public bool Initialize()
  146. {
  147. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  148. DATA.Subscribe($"{Module}.{Name}.Feedback", () => FeedBack);
  149. DATA.Subscribe($"{Module}.{Name}._setpoint", () => Setpoint);
  150. OP.Subscribe($"{Module}.{Name}.SetParameters", SetParameters);
  151. OP.Subscribe($"{Module}.{Name}.SetMfmValue", SetMfmValue);
  152. //_phyScale = SC.GetValue<double>($"{Module}.MFM.{Name}.PhyScale");
  153. //AlarmToleranceWarning = SubscribeAlarm($"{Module}.{Name}.ToleranceWarning", "", ResetWarningChecker, EventLevel.Warning);
  154. //AlarmToleranceAlarm = SubscribeAlarm($"{Module}.{Name}.ToleranceAlarm", "", ResetAlarmChecker);
  155. //AlarmToleranceWarning.Id = _toleranceWarningEventId;
  156. //AlarmToleranceAlarm.Id = _toleranceAlarmEventId;
  157. return true;
  158. }
  159. public void Monitor()
  160. {
  161. MonitorTolerance();
  162. }
  163. public bool ResetWarningChecker()
  164. {
  165. _toleranceCheckerWarning?.Reset(_warningJudgmentTime);
  166. return true;
  167. }
  168. public bool ResetAlarmChecker()
  169. {
  170. _toleranceCheckerAlarm?.Reset(_alarmJudgmentTime);
  171. return true;
  172. }
  173. public void Reset()
  174. {
  175. //AlarmToleranceWarning.Reset();
  176. //AlarmToleranceAlarm.Reset();
  177. }
  178. public void Terminate()
  179. {
  180. }
  181. private bool SetParameters(out string reason, int time, object[] param)
  182. {
  183. reason = string.Empty;
  184. var paras = param[0].ToString().Split(';');//flow;alarmTable
  185. if (System.Text.RegularExpressions.Regex.Match(paras[0].ToString(), @"[a-zA-Z]").Success)
  186. {
  187. var table = paras[0].ToString().Split(':')[0];
  188. if (SC.ContainsItem($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}"))
  189. _setpoint = (float)SC.GetValue<double>($"{Module}.RecipeEditParameter.FlowSetting.{Name}.{table}");
  190. }
  191. else
  192. {
  193. float.TryParse(param[0].ToString(), out _setpoint);
  194. _setpoint = (float)Converter.Logic2Phy(_setpoint, 0, Scale, 0, _phyScale);
  195. }
  196. if (paras.Length >= 2)
  197. {
  198. var alarmWatchTable = paras[1].ToString();
  199. if (SC.ContainsItem($"{Module}.RecipeEditParameter.AlarmWatchTable.FlowAlarmWatch.Table{alarmWatchTable}.DelayTime"))
  200. {
  201. var scPath = $"{Module}.RecipeEditParameter.AlarmWatchTable.PressureAlarmWatch.Table{alarmWatchTable}";
  202. _toleranceJudgmentDelayTime = (float)SC.GetValue<double>($"{scPath}.DelayTime");
  203. _alarmJudgmentRange = (float)SC.GetValue<double>($"{scPath}.AlarmJudgment");
  204. _warningJudgmentRange = (float)SC.GetValue<double>($"{scPath}.WarningJudgment");
  205. _alarmJudgmentTime = (float)SC.GetValue<double>($"{scPath}.AlarmJudgmentTime");
  206. _warningJudgmentTime = (float)SC.GetValue<double>($"{scPath}.WarningJudgmentTime");
  207. _toleranceJudgmentDelayTimer.Start(0);
  208. }
  209. else
  210. {
  211. _toleranceJudgmentDelayTime = 0;
  212. _alarmJudgmentRange = 0;
  213. _warningJudgmentRange = 0;
  214. _alarmJudgmentTime = 0;
  215. _warningJudgmentTime = 0;
  216. _toleranceJudgmentDelayTimer.Stop();
  217. }
  218. ResetWarningChecker();
  219. ResetAlarmChecker();
  220. }
  221. return true;
  222. }
  223. private bool SetMfmValue(out string reason, int time, object[] param)
  224. {
  225. reason = string.Empty;
  226. var paras = param[0].ToString().Split(';'); // setpoint;alarmWatchTable
  227. float.TryParse(paras[0].ToString(), out _setpoint);
  228. _aoFlow.FloatValue = _setpoint;
  229. return true;
  230. }
  231. private void MonitorTolerance()
  232. {
  233. }
  234. }
  235. }