123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using System.Collections.Generic;
- using System.Diagnostics;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using MECF.Framework.Common.CommonData;
- namespace Venus_RT.Modules.PMs
- {
- public class Fdc
- {
- public List<FdcDataItem> DataList
- {
- get
- {
- return _lstItems;
- }
- }
- private List<FdcDataItem> _lstItems = new List<FdcDataItem>();
- //private PeriodicJob _monitorThread;
- private string _module;
- private Stopwatch _delaytimer = new Stopwatch();
- private int _delayTime;
- public Fdc(string module)
- {
- //_monitorThread = new PeriodicJob(300, OnMonitor, "fdc thread");
- _module = module;
- }
- public void Reset(Dictionary<string,float> nameValues)
- {
- _lstItems.Clear();
- int interval = SC.GetValue<int>("System.FDC.SampleInterval");
- if (interval < 50)
- interval = 50;
- _delayTime = SC.GetValue<int>("System.FDC.DelayTime");
- if (_delayTime < 0)
- _delayTime = 10;
- foreach (var item in nameValues)
- {
- string name = item.Key;
- if (!string.IsNullOrEmpty(name))
- {
- var dataType = Singleton<DataManager>.Instance.GetDataType($"{_module}.{name}");
- if (dataType == typeof(double) || dataType == typeof(float) ||
- dataType == typeof(int) || dataType == typeof(ushort) || dataType == typeof(short))
- {
- _lstItems.Add(new FdcDataItem()
- {
- KeyValue=item
- });
- }
- }
- }
- }
- public void AppendKeyValues(Dictionary<string, float> nameValues)
- {
- foreach (var item in nameValues)
- {
- string name = item.Key;
- if (!string.IsNullOrEmpty(name))
- {
- var dataType = Singleton<DataManager>.Instance.GetDataType($"{_module}.{name}");
- if (dataType == typeof(double) || dataType == typeof(float) ||
- dataType == typeof(int) || dataType == typeof(ushort) || dataType == typeof(short))
- {
- _lstItems.Add(new FdcDataItem()
- {
- KeyValue = item
- });
- }
- }
- }
- }
- //pair: controlname - setpoint value
- public void Start()
- {
- ClearPreviousData();
-
- _delaytimer.Restart();
- }
- public void Stop()
- {
- //_monitorThread.Pause();
- ClearPreviousData();
- }
- public void ClearPreviousData()
- {
- foreach (var fdcDataItem in _lstItems)
- {
- fdcDataItem.Clear();
- }
- }
- public bool OnMonitor()
- {
- try
- {
- if (_delaytimer.IsRunning)
- {
- if (_delaytimer.ElapsedMilliseconds < _delayTime)
- return true;
- else
- {
- _delaytimer.Stop();
- }
- }
- foreach (var fdcDataItem in _lstItems)
- {
- var objValue = DATA.Poll(fdcDataItem.Name);
- float floatValue = 0f;
- if (objValue != null)
- {
- float.TryParse(objValue.ToString(), out floatValue);
- }
- fdcDataItem.Update(floatValue);
- }
- }
- catch
- {
- }
- return true;
- }
- }
- }
|