Fdc.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System.Collections.Generic;
  2. using System.Diagnostics;
  3. using System.Xml;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using MECF.Framework.Common.CommonData;
  8. using MECF.Framework.Common.SCCore;
  9. namespace Venus_RT.Modules.PMs
  10. {
  11. public class Fdc
  12. {
  13. public List<FdcDataItem> DataList
  14. {
  15. get
  16. {
  17. return _lstItems;
  18. }
  19. }
  20. private List<FdcDataItem> _lstItems = new List<FdcDataItem>();
  21. private PeriodicJob _monitorThread;
  22. private string _module;
  23. private Stopwatch _delaytimer = new Stopwatch();
  24. private int _delayTime;
  25. //private Dictionary<string, string> _setpointDataMap = new Dictionary<string, string>();
  26. public Fdc(string module)
  27. {
  28. _monitorThread = new PeriodicJob(300, OnMonitor, "fdc thread");
  29. _module = module;
  30. }
  31. public void Reset(List<string> names)
  32. {
  33. _lstItems.Clear();
  34. //_setpointDataMap.Clear();
  35. //string groupName = SC.GetStringValue("System.FDC.DataGroupName");
  36. //if (string.IsNullOrEmpty(groupName))
  37. // groupName = "Process";
  38. int interval = SC.GetValue<int>("System.FDC.SampleInterval");
  39. if (interval < 50)
  40. interval = 50;
  41. _delayTime = SC.GetValue<int>("System.FDC.DelayTime");
  42. if (_delayTime < 0)
  43. _delayTime = 10;
  44. //var content = TypedConfigManager.Instance.GetTypedConfigContent("DataGroup", "");
  45. //XmlDocument xmlContent = new XmlDocument();
  46. //xmlContent.LoadXml(content);
  47. //var items = xmlContent.SelectNodes($"DataGroupConfig/DataGroup[@name='{groupName}']/DataItem");
  48. foreach (var item in names)
  49. {
  50. //var node = item as XmlElement;
  51. string name = item;
  52. if (!string.IsNullOrEmpty(name) && name.StartsWith($"{_module}."))
  53. {
  54. var dataType = Singleton<DataManager>.Instance.GetDataType(name);
  55. if (dataType == typeof(double) || dataType == typeof(float) ||
  56. dataType == typeof(int) || dataType == typeof(ushort) || dataType == typeof(short))
  57. {
  58. _lstItems.Add(new FdcDataItem()
  59. {
  60. Name = name,
  61. });
  62. }
  63. }
  64. }
  65. //var fdcMap = xmlContent.SelectNodes($"DataGroupConfig/DataGroup[@name='Fdc']/DataItem");
  66. //foreach (var item in fdcMap)
  67. //{
  68. // var node = item as XmlElement;
  69. // string name = node.GetAttribute("name");
  70. // if (!string.IsNullOrEmpty(name) && name.StartsWith($"{_module}.") && (_lstItems.FirstOrDefault(x => x.Name == name) != null))
  71. // {
  72. // string controlName = node.GetAttribute("control_name");
  73. // if (!string.IsNullOrEmpty(controlName))
  74. // _setpointDataMap[name] = controlName;
  75. // }
  76. //}
  77. _monitorThread.ChangeInterval(interval);
  78. }
  79. //pair: controlname - setpoint value
  80. public void Start(params float[] floats)
  81. {
  82. ClearPreviousData();
  83. for (int i = 0; i < floats.Length; i++)
  84. {
  85. _lstItems[i].SetPoint = floats[i];
  86. }
  87. //foreach (var fdcDataItem in _lstItems)
  88. //{
  89. // if (!_setpointDataMap.ContainsKey(fdcDataItem.Name))
  90. // continue;
  91. // if (!setpointControlData.ContainsKey(_setpointDataMap[fdcDataItem.Name]))
  92. // continue;
  93. // if (!float.TryParse(setpointControlData[_setpointDataMap[fdcDataItem.Name]], out float floatValue))
  94. // continue;
  95. // fdcDataItem.SetPoint = floatValue;
  96. //}
  97. _delaytimer.Restart();
  98. _monitorThread.Start();
  99. }
  100. public void Stop()
  101. {
  102. _monitorThread.Pause();
  103. ClearPreviousData();
  104. }
  105. public void ClearPreviousData()
  106. {
  107. foreach (var fdcDataItem in _lstItems)
  108. {
  109. fdcDataItem.Clear();
  110. }
  111. }
  112. private bool OnMonitor()
  113. {
  114. try
  115. {
  116. if (_delaytimer.IsRunning)
  117. {
  118. if (_delaytimer.ElapsedMilliseconds < _delayTime)
  119. return true;
  120. else
  121. {
  122. _delaytimer.Stop();
  123. }
  124. }
  125. foreach (var fdcDataItem in _lstItems)
  126. {
  127. var objValue = DATA.Poll(fdcDataItem.Name);
  128. float floatValue = 0f;
  129. if (objValue != null)
  130. {
  131. float.TryParse(objValue.ToString(), out floatValue);
  132. }
  133. fdcDataItem.Update(floatValue);
  134. }
  135. }
  136. catch
  137. {
  138. }
  139. return true;
  140. }
  141. }
  142. }