IoTrigger2.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.IOCore;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Xml;
  10. namespace FurnaceRT.Devices
  11. {
  12. public class IoTrigger2 : BaseDevice, IDevice
  13. {
  14. private DIAccessor _diFeedback = null;
  15. private DOAccessor _doTrigger = null;
  16. private AOAccessor _aoTrigger = null;
  17. public DOAccessor DoTrigger => _doTrigger;
  18. public IoTrigger2(string module, XmlElement node, string ioModule = "")
  19. {
  20. base.Module = module;
  21. base.Name = $"TrigGasLineHeaterUnit{ioModule.Replace("GasLine", "")}{node.GetAttribute("id")}";
  22. base.Display = node.GetAttribute("display");
  23. base.DeviceID = node.GetAttribute("schematicId");
  24. _diFeedback = ParseDiNode("diFeedback", node, ioModule);
  25. _doTrigger = ParseDoNode("doTrigger", node, ioModule);
  26. _aoTrigger = ParseAoNode("aoTrigger", node, ioModule);
  27. }
  28. public bool Value
  29. {
  30. get
  31. {
  32. if (_diFeedback != null)
  33. return _diFeedback.Value;
  34. if (_doTrigger != null)
  35. return _doTrigger.Value;
  36. if (_aoTrigger != null)
  37. return _aoTrigger.FloatValue > 0;
  38. return false;
  39. }
  40. }
  41. public float AOValue
  42. {
  43. get
  44. {
  45. if (_aoTrigger != null)
  46. return _aoTrigger.FloatValue;
  47. return 0f;
  48. }
  49. }
  50. public bool SetPulseTrigger(bool value, out string reason)
  51. {
  52. reason = "";
  53. _doTrigger?.SetPulseValue(value, 1500);
  54. return true;
  55. }
  56. public bool SetTrigger(bool value, out string reason)
  57. {
  58. reason = "";
  59. _doTrigger?.SetValue(value, out reason);
  60. if (_aoTrigger != null)
  61. _aoTrigger.FloatValue = value ? 1 : 0;
  62. return true;
  63. }
  64. public bool SetAOTrigger(float value, out string reason)
  65. {
  66. reason = "";
  67. if (_aoTrigger != null)
  68. _aoTrigger.FloatValue = value;
  69. return true;
  70. }
  71. public bool Initialize()
  72. {
  73. if (_aoTrigger != null)
  74. DATA.Subscribe($"{Module}.{Name}.AOValue", () => AOValue);
  75. return true;
  76. }
  77. public void Terminate()
  78. {
  79. }
  80. public void Monitor()
  81. {
  82. }
  83. public void Reset()
  84. {
  85. }
  86. }
  87. }