patrick
2019-12-10 1c4426810c71eead57084be8a18ade8d314dd8c4
src/Bro.Device.Common/DeviceBase/PLCBase.cs
@@ -58,8 +58,6 @@
                        if (newValues == null || newValues.Count == 0)
                            continue;
                        //Stopwatch sw = new Stopwatch();
                        //sw.Start();
                        if (oldValues.Count == newValues.Count)
                        {
                            var tempNew = new List<int>(newValues);
@@ -67,13 +65,6 @@
                            MonitorCheckAndInvoke(tempNew, tempOld);
                        }
                        oldValues = new List<int>(newValues);
                        //sw.Stop();
                        //if (sw.ElapsedMilliseconds > 10)
                        //{
                        //    LogAsync(DateTime.Now, $"轮询时间:{sw.ElapsedMilliseconds}", "");
                        //    TimeRecordCSV(DateTime.Now, "轮询时间", (int)sw.ElapsedMilliseconds);
                        //}
                        Thread.Sleep(PLCIConfig.ScanInterval);
                    }
@@ -88,42 +79,31 @@
        protected virtual void MonitorCheckAndInvoke(List<int> tempNew, List<int> tempOld)
        {
            #region PLC警报信息
            //bool warningSignal = (m.TriggerIndex >= PLCIConfig.WarningStartIndex && m.TriggerIndex < PLCIConfig.WarningStartIndex + PLCIConfig.WarningLength);
            PLCIConfig.WarningSetCollection.ForEach(w =>
            {
                if (w.WarningIndex_Word < 0 || w.WarningIndex_Word >= tempNew.Count)
                    return;
            //if (warningSignal)
            //{
            //    if (newValue != oldValue)
            //    {
            //        int warningIndex = m.TriggerIndex - PLCIConfig.WarningStartIndex;
            //        for (int i = 0; i < 16; i++)
            //        {
            //            var ws = PLCIConfig.WarningSetCollection.FirstOrDefault(w => w.WaringIndex == (warningIndex * 16) + i);
                if (w.WarningIndex_Bit < 0 || w.WarningIndex_Bit > 16)
                    return;
            //            if (ws != null)
            //            {
            //                int newAlarmValue = newValue >> i & 1;
            //                int oldAlarmValue = oldValue >> i & 1;
                bool isOn = ((tempNew[w.WarningIndex_Word] >> w.WarningIndex_Bit) & 1) == 1;
            //                if (newAlarmValue != oldAlarmValue)
            //                {
            //                    OnMonitorAlarm?.BeginInvoke(ws, newAlarmValue == 1, null, null);
            //                    //仅保存警报信息,不保存提示信息
            //                    //if (ws.WarningLvl == 0)
            //                    //{
            //                    //    SaveAlarm(Config.StationCode, ws, newValue);
            //                    //}
            //                }
            //            }
            //        }
            //    }
            //    return;
            //}
                if (w.CurrentStatus != isOn)
                {
                    w.CurrentStatus = isOn;
                    OnMonitorAlarm?.BeginInvoke(DateTime.Now, this, w, null, null);
                }
            });
            #endregion
            PLCIConfig.MonitorSetCollection.ForEach(m =>
            {
                if (m.TriggerIndex < 0 || m.TriggerIndex >= tempNew.Count)
                {
                    return;
                }
                int newValue = tempNew[m.TriggerIndex];
                int oldValue = tempOld[m.TriggerIndex];
@@ -192,6 +172,11 @@
                } while (repeatTime > 0);
            }
        }
        public virtual void ResetAlarm()
        {
            PLCIConfig.WarningSetCollection.ForEach(u => u.CurrentStatus = !u.TriggerValue);
        }
        #endregion
    }
@@ -212,36 +197,8 @@
    {
    }
    public class PLCInitialConfigBase : InitialConfigBase
    public class PLCInitialConfigBase : InitialMonitorConfigBase
    {
        [Category("监听设置")]
        [Description("警报配置列表")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<WarningSet>), typeof(UITypeEditor))]
        public List<WarningSet> WarningSetCollection { get; set; } = new List<WarningSet>();
        [Category("监听设置")]
        [Description("监听操作配置集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<MonitorSet>), typeof(UITypeEditor))]
        public List<MonitorSet> MonitorSetCollection { get; set; } = new List<MonitorSet>();
        [Category("监听设置")]
        [Description("扫描间隔时间,单位:ms")]
        public int ScanInterval { get; set; } = 100;
        [Category("监听设置")]
        [Description("超时设置,单位:ms")]
        public int Timeout { get; set; } = 500;
        //[Category("输出设置")]
        //[Description("是否日志输出")]
        //public bool IsEnabelLog { get; set; } = false;
        //[Category("输出设置")]
        //[Description("输出文件路径")]
        //public string LogPath { get; set; } = @"D:\PLCLog.txt";
        #region 地址设置
        [Category("事件地址设置")]
        [Description("事件开始地址,PLC的实际寄存器地址。十进制,不包含功能码。")]