Fdc.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System.Collections.Generic;
  2. using System.Diagnostics;
  3. using Aitex.Core.RT.DataCenter;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.CommonData;
  7. namespace Venus_RT.Modules.PMs
  8. {
  9. public class Fdc
  10. {
  11. public List<FdcDataItem> DataList
  12. {
  13. get
  14. {
  15. return _lstItems;
  16. }
  17. }
  18. private List<FdcDataItem> _lstItems = new List<FdcDataItem>();
  19. //private PeriodicJob _monitorThread;
  20. private string _module;
  21. private Stopwatch _delaytimer = new Stopwatch();
  22. private int _delayTime;
  23. public Fdc(string module)
  24. {
  25. //_monitorThread = new PeriodicJob(300, OnMonitor, "fdc thread");
  26. _module = module;
  27. }
  28. public void Reset(Dictionary<string,float> nameValues)
  29. {
  30. _lstItems.Clear();
  31. int interval = SC.GetValue<int>("System.FDC.SampleInterval");
  32. if (interval < 50)
  33. interval = 50;
  34. _delayTime = SC.GetValue<int>("System.FDC.DelayTime");
  35. if (_delayTime < 0)
  36. _delayTime = 10;
  37. foreach (var item in nameValues)
  38. {
  39. string name = item.Key;
  40. if (!string.IsNullOrEmpty(name))
  41. {
  42. var dataType = Singleton<DataManager>.Instance.GetDataType($"{_module}.{name}");
  43. if (dataType == typeof(double) || dataType == typeof(float) ||
  44. dataType == typeof(int) || dataType == typeof(ushort) || dataType == typeof(short))
  45. {
  46. _lstItems.Add(new FdcDataItem()
  47. {
  48. KeyValue=item
  49. });
  50. }
  51. }
  52. }
  53. }
  54. public void AppendKeyValues(Dictionary<string, float> nameValues)
  55. {
  56. foreach (var item in nameValues)
  57. {
  58. string name = item.Key;
  59. if (!string.IsNullOrEmpty(name))
  60. {
  61. var dataType = Singleton<DataManager>.Instance.GetDataType($"{_module}.{name}");
  62. if (dataType == typeof(double) || dataType == typeof(float) ||
  63. dataType == typeof(int) || dataType == typeof(ushort) || dataType == typeof(short))
  64. {
  65. _lstItems.Add(new FdcDataItem()
  66. {
  67. KeyValue = item
  68. });
  69. }
  70. }
  71. }
  72. }
  73. //pair: controlname - setpoint value
  74. public void Start()
  75. {
  76. ClearPreviousData();
  77. _delaytimer.Restart();
  78. }
  79. public void Stop()
  80. {
  81. //_monitorThread.Pause();
  82. ClearPreviousData();
  83. }
  84. public void ClearPreviousData()
  85. {
  86. foreach (var fdcDataItem in _lstItems)
  87. {
  88. fdcDataItem.Clear();
  89. }
  90. }
  91. public bool OnMonitor()
  92. {
  93. try
  94. {
  95. if (_delaytimer.IsRunning)
  96. {
  97. if (_delaytimer.ElapsedMilliseconds < _delayTime)
  98. return true;
  99. else
  100. {
  101. _delaytimer.Stop();
  102. }
  103. }
  104. foreach (var fdcDataItem in _lstItems)
  105. {
  106. var objValue = DATA.Poll(fdcDataItem.Name);
  107. float floatValue = 0f;
  108. if (objValue != null)
  109. {
  110. float.TryParse(objValue.ToString(), out floatValue);
  111. }
  112. fdcDataItem.Update(floatValue);
  113. }
  114. }
  115. catch
  116. {
  117. }
  118. return true;
  119. }
  120. }
  121. }