IoTrigger.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Windows.Forms.VisualStyles;
  3. using System.Xml;
  4. using Aitex.Core.Common.DeviceData;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.Util;
  8. namespace Aitex.Core.RT.Device.Unit
  9. {
  10. public class IoTrigger : BaseDevice, IDevice
  11. {
  12. private DOAccessor _doTrigger = null;
  13. [Subscription(AITTrigPropertyName.Status)]
  14. public bool Value
  15. {
  16. get { return _doTrigger.Value; }
  17. }
  18. public IoTrigger(string module, XmlElement node)
  19. {
  20. base.Module = module;
  21. base.Name = node.GetAttribute("id");
  22. base.Display = node.GetAttribute("display");
  23. base.DeviceID = node.GetAttribute("schematicId");
  24. _doTrigger = ParseDoNode("doTrigger", node);
  25. }
  26. public bool SetTrigger(bool value, out string reason)
  27. {
  28. return _doTrigger.SetValue(value, out reason);
  29. }
  30. public bool Initialize()
  31. {
  32. DATA.Subscribe(string.Format("Device.{0}.{1}", Module , Name), () =>
  33. {
  34. AITTrigData data = new AITTrigData()
  35. {
  36. DeviceName = Name,
  37. DeviceSchematicId = DeviceID,
  38. DisplayName = Display,
  39. Status = Value,
  40. };
  41. return data;
  42. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  43. DEVICE.Register(String.Format("{0}.{1}", Name, AITTrigOperation.TrigOn), (out string reason, int time, object[] param) =>
  44. {
  45. bool ret = SetTrigger(true, out reason);
  46. if (ret)
  47. {
  48. reason = string.Format("{0} On", Name);
  49. return true;
  50. }
  51. return false;
  52. });
  53. DEVICE.Register(String.Format("{0}.{1}", Name, AITTrigOperation.TrigOff), (out string reason, int time, object[] param) =>
  54. {
  55. bool ret = SetTrigger(false, out reason);
  56. if (ret)
  57. {
  58. reason = string.Format("{0} Off", Name);
  59. return true;
  60. }
  61. return false;
  62. });
  63. return true;
  64. }
  65. public void Terminate()
  66. {
  67. }
  68. public void Monitor()
  69. {
  70. }
  71. public void Reset()
  72. {
  73. }
  74. }
  75. }