Пример #1
0
        /// <summary>
        /// 主通信流程:Step 6:根据数据更新上位机相关信息
        /// </summary>
        protected void Update()
        {
            DateTime dt = DateTime.Now;

            if (DataChange != null)
            {
                HistoryData[] values = new HistoryData[_changedList.Count];
                int           i      = 0;
                foreach (int index in _changedList)
                {
                    ITag item     = _items[index];
                    var  itemData = item.Read();//这是从缓存Cache中读取的数据
                    if (item.Active)
                    {
                        item.Update(itemData, dt, QUALITIES.QUALITY_GOOD);
                    }

                    /*
                     * 下面的语言判断是否要更新有变化的Itag:
                     * 1.对敏感度为零的,只要有任何变化都要更新;??浮点数和零 比较大小
                     * 2.对于浮点数,新值的变化要超过敏感的 百分比
                     */
                    if (_deadband == 0 || (item.Address.VarType == DataType.FLOAT &&
                                           (Math.Abs(itemData.Single / item.Value.Single - 1) > _deadband)))
                    {
                        values[i].ID        = item.ID;
                        values[i].Quality   = item.Quality;
                        values[i].Value     = itemData;
                        values[i].TimeStamp = item.TimeStamp;
                        i++;
                    }
                }

                foreach (DataChangeEventHandler deleg in DataChange.GetInvocationList())     //批量调用绑定在事件上面的委托
                {
                    deleg.BeginInvoke(this, new DataChangeEventArgs(1, values), null, null); //只在这个地方,才去调用绑定的事件,对那些更新周期为零的变量进行存储,存储周期随Group
                }
            }
            else
            {
                foreach (int index in _changedList)
                {
                    ITag item = _items[index];
                    if (item.Active)
                    {
                        item.Update(item.Read(), dt, QUALITIES.QUALITY_GOOD);
                    }
                }
            }
        }
Пример #2
0
        protected void Update()
        {
            DateTime dt = DateTime.Now;

            if (DataChange != null)
            {
                HistoryData[] values = new HistoryData[_changedList.Count];
                int           i      = 0;
                foreach (int index in _changedList)
                {
                    ITag item     = _items[index];
                    var  itemData = item.Read();
                    if (item.Active)
                    {
                        item.Update(itemData, dt, QUALITIES.QUALITY_GOOD);
                    }
                    if (_deadband == 0 || (item.Address.VarType == DataType.FLOAT &&
                                           (Math.Abs(itemData.Single / item.Value.Single - 1) > _deadband)))
                    {
                        values[i].ID        = item.ID;
                        values[i].Quality   = item.Quality;
                        values[i].Value     = itemData;
                        values[i].TimeStamp = item.TimeStamp;
                        i++;
                    }
                }

                foreach (DataChangeEventHandler deleg in DataChange.GetInvocationList())
                {
                    deleg.BeginInvoke(this, new DataChangeEventArgs(1, values), null, null);
                }
            }
            else
            {
                foreach (int index in _changedList)
                {
                    ITag item = _items[index];
                    if (item.Active)
                    {
                        item.Update(item.Read(), dt, QUALITIES.QUALITY_GOOD);
                    }
                }
            }

            _changedList.Clear();
        }