IoPlcDateTime.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml;
  6. using Aitex.Core.RT.IOCore;
  7. namespace Aitex.Core.RT.Device.Unit
  8. {
  9. public class IoPlcDateTime : BaseDevice, IDevice
  10. {
  11. private AIAccessor _aiYear;
  12. private AIAccessor _aiMonth;
  13. private AIAccessor _aiDay;
  14. private AIAccessor _aiHour;
  15. private AIAccessor _aiMinute;
  16. private AIAccessor _aiSecond;
  17. public DateTime CurrentDateTime
  18. {
  19. get
  20. {
  21. if (Year <1000 && Month == 0 && Day == 0)
  22. return DateTime.Now;
  23. return new DateTime(Year, Month, Day, Hour, Minute, Second);
  24. }
  25. }
  26. public int Year
  27. {
  28. get
  29. {
  30. return _aiYear == null ? DateTime.Now.Year : (int)_aiYear.Value;
  31. }
  32. }
  33. public int Month
  34. {
  35. get
  36. {
  37. return _aiMonth == null ? DateTime.Now.Month : (int)_aiMonth.Value;
  38. }
  39. }
  40. public int Day
  41. {
  42. get
  43. {
  44. return _aiDay == null ? DateTime.Now.Day : (int)_aiDay.Value;
  45. }
  46. }
  47. public int Hour
  48. {
  49. get
  50. {
  51. return _aiHour == null ? DateTime.Now.Hour : (int)_aiHour.Value;
  52. }
  53. }
  54. public int Minute
  55. {
  56. get
  57. {
  58. return _aiMinute == null ? DateTime.Now.Minute : (int)_aiMinute.Value;
  59. }
  60. }
  61. public int Second
  62. {
  63. get
  64. {
  65. return _aiSecond == null ? DateTime.Now.Second : (int)_aiSecond.Value;
  66. }
  67. }
  68. public IoPlcDateTime(string module, XmlElement node, string ioModule = "")
  69. {
  70. base.Module = module;
  71. base.Name = node.GetAttribute("id");
  72. base.Display = node.GetAttribute("display");
  73. base.DeviceID = node.GetAttribute("schematicId");
  74. _aiYear = ParseAiNode("aiYear", node, ioModule);
  75. _aiMonth = ParseAiNode("aiMonth", node, ioModule);
  76. _aiDay = ParseAiNode("aiDay", node, ioModule);
  77. _aiHour = ParseAiNode("aiHour", node, ioModule);
  78. _aiMinute = ParseAiNode("aiMinute", node, ioModule);
  79. _aiSecond = ParseAiNode("aiSecond", node, ioModule);
  80. }
  81. public bool Initialize()
  82. {
  83. return true;
  84. }
  85. public void Terminate()
  86. {
  87. }
  88. public void Monitor()
  89. {
  90. }
  91. public void Reset()
  92. {
  93. }
  94. }
  95. }