IoTrigger.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 DOAccessor _doTrigger = null;
  9. private AOAccessor _aoTrigger = null;
  10. public DOAccessor DoTrigger => _doTrigger;
  11. public IoTrigger(string module, XmlElement node, string ioModule = "")
  12. {
  13. base.Module = module;
  14. base.Name = node.GetAttribute("id");
  15. base.Display = node.GetAttribute("display");
  16. base.DeviceID = node.GetAttribute("schematicId");
  17. _doTrigger = ParseDoNode("doTrigger", node, ioModule);
  18. _aoTrigger = ParseAoNode("aoTrigger", node, ioModule);
  19. }
  20. public bool Value
  21. {
  22. get
  23. {
  24. if (_doTrigger != null)
  25. return _doTrigger.Value;
  26. if (_aoTrigger != null)
  27. return _aoTrigger.FloatValue > 0;
  28. return false;
  29. }
  30. }
  31. public float AOValue
  32. {
  33. get
  34. {
  35. if (_aoTrigger != null)
  36. return _aoTrigger.FloatValue;
  37. return 0f;
  38. }
  39. }
  40. public bool SetPulseTrigger(bool value, out string reason)
  41. {
  42. reason = "";
  43. _doTrigger?.SetPulseValue(value, 1500);
  44. return true;
  45. }
  46. public bool SetTrigger(bool value, out string reason)
  47. {
  48. reason = "";
  49. _doTrigger?.SetValue(value, out reason);
  50. if(_aoTrigger != null)
  51. _aoTrigger.FloatValue = value ? 1 : 0;
  52. return true;
  53. }
  54. public bool SetAOTrigger(float value, out string reason)
  55. {
  56. reason = "";
  57. if (_aoTrigger != null)
  58. _aoTrigger.FloatValue = value;
  59. return true;
  60. }
  61. public bool Initialize()
  62. {
  63. if (_aoTrigger != null)
  64. DATA.Subscribe($"{Module}.{Name}.AOValue", () => AOValue);
  65. return true;
  66. }
  67. public void Terminate()
  68. {
  69. }
  70. public void Monitor()
  71. {
  72. }
  73. public void Reset()
  74. {
  75. }
  76. }
  77. }