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 DataList { get { return _lstItems; } } private List _lstItems = new List(); //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 nameValues) { _lstItems.Clear(); int interval = SC.GetValue("System.FDC.SampleInterval"); if (interval < 50) interval = 50; _delayTime = SC.GetValue("System.FDC.DelayTime"); if (_delayTime < 0) _delayTime = 10; foreach (var item in nameValues) { string name = item.Key; if (!string.IsNullOrEmpty(name)) { var dataType = Singleton.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 nameValues) { foreach (var item in nameValues) { string name = item.Key; if (!string.IsNullOrEmpty(name)) { var dataType = Singleton.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; } } }