IoTrigger.cs 2.6 KB

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