/// <summary>
 ///
 /// </summary>
 /// <param name="tag"></param>
 /// <returns></returns>
 public bool AddTag(HisRunTag tag)
 {
     if (mCurrentCount < MaxTagCount)
     {
         var cc = tag.Circle;
         if (mTimerTags.ContainsKey(cc))
         {
             mTimerTags[cc].Add(tag);
         }
         else
         {
             mTimerTags.Add(cc, new List <HisRunTag>()
             {
                 tag
             });
             mCount.Add(cc, 0);
         }
         mCurrentCount++;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="tag"></param>
 public void Remove(HisRunTag tag)
 {
     if (mTimerTags.ContainsKey(tag.Circle))
     {
         mTimerTags[tag.Circle].Remove(tag);
         mCurrentCount--;
     }
 }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="tag"></param>
 /// <returns></returns>
 public bool AddTag(HisRunTag tag)
 {
     if (mCurrentCount < MaxTagCount)
     {
         mTags.Add(tag.Id, tag);
         mCurrentCount++;
         return(true);
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="tag"></param>
        public void Remove(HisRunTag tag)
        {
            if (mTags.ContainsKey(tag.Id))
            {
                mTags.Remove(tag.Id);
                mCurrentCount--;
            }
            bool btmp = false;

            if (mChangedTags.ContainsKey(tag.Id))
            {
                mChangedTags.Remove(tag.Id, out btmp);
            }
            mValueChangedNotifier?.UnRegistor(tag.Id);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public bool AddTag(HisRunTag tag)
        {
            if (mCurrentCount < MaxTagCount)
            {
                mTags.Add(tag.Id, tag);
                mCurrentCount++;

                mChangedTags.TryAdd(tag.Id, false);
                mValueChangedNotifier?.Registor(tag.Id);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="oldcircle"></param>
        public void UpdateCircle(HisRunTag tag, long oldcircle)
        {
            if (mTimerTags.ContainsKey(oldcircle) && mTimerTags[oldcircle].Contains(tag))
            {
                if (mTimerTags.ContainsKey(oldcircle))
                {
                    mTimerTags[oldcircle].Remove(tag);
                }

                var cc = tag.Circle;
                if (mTimerTags.ContainsKey(cc))
                {
                    mTimerTags[cc].Add(tag);
                }
                else
                {
                    mTimerTags.Add(cc, new List <HisRunTag>()
                    {
                        tag
                    });
                    mCount.Add(cc, DateTime.UtcNow);
                }
            }
        }
Example #7
0
        /// <summary>
        /// 初始化
        /// </summary>
        public void Init()
        {
            if (mRealEnginer != null)
            {
                if (mManager == null)
                {
                    mManager = new Cdy.Tag.HisDatabaseSerise().Load();
                }

                mLastProcesser = new TimerMemoryCacheProcesser()
                {
                    Id = 0
                };
                mRecordTimerProcesser.Clear();
                mRecordTimerProcesser.Add(mLastProcesser);

                mValueChangedProcesser.Clear();
                mValueChangedProcesser.Add(mLastValueChangedProcesser);

                // var count = MemoryCachTime * 1000 / MemoryTimeTick;
                var       count        = CachMemoryTime;
                var       realbaseaddr = mRealEnginer.Memory;
                IntPtr    realHandle   = mRealEnginer.MemoryHandle;
                HisRunTag mHisTag      = null;
                foreach (var vv in mManager.HisTags)
                {
                    var realaddr = (int)mRealEnginer.GetDataAddr((int)vv.Value.Id);
                    switch (vv.Value.TagType)
                    {
                    case Cdy.Tag.TagType.Bool:
                    case Cdy.Tag.TagType.Byte:
                        mHisTag = new ByteHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.Short:
                    case Cdy.Tag.TagType.UShort:
                        mHisTag = new ShortHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.Int:
                    case Cdy.Tag.TagType.UInt:
                        mHisTag = new IntHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.Long:
                    case Cdy.Tag.TagType.ULong:
                        mHisTag = new LongHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.Float:
                        mHisTag = new FloatHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.Double:
                        mHisTag = new DoubleHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.DateTime:
                        mHisTag = new DateTimeHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.String:
                        mHisTag = new StirngHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.UIntPoint:
                    case Cdy.Tag.TagType.IntPoint:
                        mHisTag = new IntPointHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.UIntPoint3:
                    case Cdy.Tag.TagType.IntPoint3:
                        mHisTag = new IntPoint3HisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.ULongPoint:
                    case Cdy.Tag.TagType.LongPoint:
                        mHisTag = new LongPointHisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;

                    case Cdy.Tag.TagType.ULongPoint3:
                    case Cdy.Tag.TagType.LongPoint3:
                        mHisTag = new LongPoint3HisRunTag()
                        {
                            Id = vv.Value.Id, Circle = vv.Value.Circle, Type = vv.Value.Type, TagType = vv.Value.TagType, RealMemoryAddr = realbaseaddr, RealMemoryPtr = realHandle, RealValueAddr = realaddr, CompressType = vv.Value.CompressType, Parameters = vv.Value.Parameters
                        };
                        break;
                    }
                    mHisTag.MaxCount = count;
                    mHisTags.Add(vv.Key, mHisTag);

                    if (mHisTag.Type == Cdy.Tag.RecordType.Timer)
                    {
                        if (!mLastProcesser.AddTag(mHisTag))
                        {
                            mLastProcesser = new TimerMemoryCacheProcesser()
                            {
                                Id = mLastProcesser.Id + 1
                            };
                            mLastProcesser.AddTag(mHisTag);
                            mRecordTimerProcesser.Add(mLastProcesser);
                        }
                    }
                    else
                    {
                        if (!mLastValueChangedProcesser.AddTag(mHisTag))
                        {
                            mLastValueChangedProcesser = new ValueChangedMemoryCacheProcesser()
                            {
                                Name = "ValueChanged" + mTagCount
                            };
                            mValueChangedProcesser.Add(mLastValueChangedProcesser);
                        }
                    }
                    mTagCount++;
                }
            }
            AllocMemory();
        }