IoGasStick.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.OperationCenter;
  5. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MFCs;
  6. namespace Aitex.Core.RT.Device.Unit
  7. {
  8. public interface IGasStick
  9. {
  10. bool SetFlow(out string reason, int time, float flow);
  11. }
  12. public class IoGasStick : BaseDevice, IDevice, IGasStick
  13. {
  14. private IValve _valve;
  15. private IPressureMeter _pressure;
  16. private IMfc _mfc;
  17. private IValve _finalValve;
  18. public IoGasStick(string module, XmlElement node, string ioModule = "")
  19. {
  20. var attrModule = node.GetAttribute("module");
  21. base.Module = string.IsNullOrEmpty(attrModule) ? module : attrModule;
  22. base.Name = node.GetAttribute("id");
  23. base.Display = node.GetAttribute("display");
  24. base.DeviceID = node.GetAttribute("schematicId");
  25. _valve = DEVICE.GetDevice($"{Module}.{node.GetAttribute("valve")}") as IValve;
  26. _finalValve = DEVICE.GetDevice($"{Module}.{node.GetAttribute("final")}") as IValve;
  27. _pressure = DEVICE.GetDevice($"{Module}.{node.GetAttribute("pc")}") as IPressureMeter;
  28. _mfc = DEVICE.GetDevice($"{Module}.{node.GetAttribute("mfc")}") as IMfc;
  29. System.Diagnostics.Debug.Assert(_valve != null, "Valve setting not valid");
  30. System.Diagnostics.Debug.Assert(_finalValve != null, "Final Valve setting not valid");
  31. System.Diagnostics.Debug.Assert(_pressure != null, "Pressure switch setting not valid");
  32. System.Diagnostics.Debug.Assert(_mfc != null, "MFC setting not valid");
  33. }
  34. public bool Initialize()
  35. {
  36. OP.Subscribe($"{Module}.{Name}.Flow", SetFlow);
  37. return true;
  38. }
  39. private bool SetFlow(out string reason, int time, object[] param)
  40. {
  41. return SetFlow(out reason, time, Convert.ToSingle(param[0].ToString()));
  42. }
  43. public bool SetFlow(out string reason, int time, float flow)
  44. {
  45. bool isOn = flow > 0.1;
  46. if (!_valve.TurnValve(isOn, out reason))
  47. return false;
  48. //may other gas line is flowing, so we can not close the final valve here
  49. if (isOn && !_finalValve.TurnValve(isOn, out reason))
  50. return false;
  51. if (!_mfc.Ramp(flow, time, out reason))
  52. return false;
  53. return true;
  54. }
  55. public void Terminate()
  56. {
  57. }
  58. public void Monitor()
  59. {
  60. try
  61. {
  62. }
  63. catch (Exception ex)
  64. {
  65. LOG.Write(ex);
  66. }
  67. }
  68. public void Reset()
  69. {
  70. }
  71. }
  72. }