示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public T GetValue(int index, out DateTime time, out byte qulity)
        {
            object re = null;

            switch (mDataType)
            {
            case 0:
                re = Convert.ToBoolean(MemoryHelper.ReadByte((void *)handle, index));
                break;

            case 1:
                re = MemoryHelper.ReadByte((void *)handle, index);
                break;

            case 2:
                re = MemoryHelper.ReadShort((void *)handle, index * 2);
                break;

            case 3:
                re = MemoryHelper.ReadUShort((void *)handle, index * 2);
                break;

            case 4:
                re = MemoryHelper.ReadInt32((void *)handle, index * 4);
                break;

            case 5:
                re = MemoryHelper.ReadUInt32((void *)handle, index * 4);
                break;

            case 6:
                re = MemoryHelper.ReadInt64((void *)handle, index * 8);
                break;

            case 7:
                re = MemoryHelper.ReadUInt64((void *)handle, index * 8);
                break;

            case 8:
                re = MemoryHelper.ReadFloat((void *)handle, index * 4);
                break;

            case 9:
                re = MemoryHelper.ReadDouble((void *)handle, index * 8);
                break;

            case 10:
                re = MemoryHelper.ReadDateTime((void *)handle, index * 8);
                break;

            case 11:

                if (mStringCach != null)
                {
                    re = mStringCach[index];
                }
                else
                {
                    mStringCach = new List <string>(mCount);
                    int cc  = 0;
                    int pos = 0;
                    int len = 0;
                    while (cc < this.mCount)
                    {
                        len = MemoryHelper.ReadByte((void *)handle, pos);
                        mStringCach.Add(new string((sbyte *)handle, pos + 1, len, Encoding.Unicode));
                        pos += len + 1;
                        cc++;
                    }
                    re = mStringCach[index];
                }

                break;

            case 12:
                var x = MemoryHelper.ReadInt32((void *)handle, index * 8);
                var y = MemoryHelper.ReadInt32((void *)handle, index * 8 + 4);
                re = new IntPointData(x, y);
                break;

            case 13:
                re = new UIntPointData(MemoryHelper.ReadUInt32((void *)handle, index * 8), MemoryHelper.ReadUInt32((void *)handle, index * 8 + 4));
                break;

            case 14:
                re = new IntPoint3Data(MemoryHelper.ReadInt32((void *)handle, index * 12), MemoryHelper.ReadInt32((void *)handle, index * 12 + 4), MemoryHelper.ReadInt32((void *)handle, index * 12 + 8));
                break;

            case 15:
                re = new UIntPoint3Data(MemoryHelper.ReadUInt32((void *)handle, index * 12), MemoryHelper.ReadUInt32((void *)handle, index * 12 + 4), MemoryHelper.ReadUInt32((void *)handle, index * 12 + 8));
                break;

            case 16:
                re = new LongPointData(MemoryHelper.ReadInt64((void *)handle, index * 16), MemoryHelper.ReadInt64((void *)handle, index * 16 + 8));
                break;

            case 17:
                re = new ULongPointData(MemoryHelper.ReadUInt64((void *)handle, index * 16), MemoryHelper.ReadUInt64((void *)handle, index * 16 + 8));
                break;

            case 18:
                re = new LongPoint3Data(MemoryHelper.ReadInt64((void *)handle, index * 24), MemoryHelper.ReadInt64((void *)handle, index * 24 + 8), MemoryHelper.ReadInt64((void *)handle, index * 24 + 16));
                break;

            case 19:
                re = new ULongPoint3Data(MemoryHelper.ReadUInt64((void *)handle, index * 24), MemoryHelper.ReadUInt64((void *)handle, index * 24 + 8), MemoryHelper.ReadUInt64((void *)handle, index * 24 + 16));
                break;
            }

            time   = MemoryHelper.ReadDateTime((void *)handle, index * 8 + mTimeAddr);
            qulity = MemoryHelper.ReadByte((void *)handle, mQulityAddr + index);



            return((T)re);
        }
示例#2
0
文件: HisRunTag.cs 项目: cdy816/mars
 /// <summary>
 /// 执行快照
 /// </summary>
 public void Snape()
 {
     System.Runtime.InteropServices.Marshal.Copy(RealMemoryPtr + RealValueAddr, ValueSnape, 0, SizeOfValue);
     // QulitySnape = RealMemoryAddr[RealValueAddr + SizeOfValue + 8];
     QulitySnape = MemoryHelper.ReadByte((void *)(RealMemoryPtr), RealValueAddr + SizeOfValue + 8);
 }
示例#3
0
文件: HisRunTag.cs 项目: cdy816/mars
        /// <summary>
        ///
        /// </summary>
        /// <param name="count"></param>
        /// <param name="tim"></param>
        public virtual void UpdateValue3(int count, int tim)
        {
            var vcount = count > MaxCount ? MaxCount : count;

            Count = vcount;

            //数据内容: 时间戳(time1+time2+...) +数值区(value1+value2+...)+质量戳区(q1+q2+....)
            //实时数据内存结构为:实时值+时间戳+质量戳,时间戳2个字节,质量戳1个字节
            CurrentDataMemory.WriteUShortDirect(CurrentMemoryPointer, (int)(TimerValueStartAddr + vcount * 2), (ushort)(tim));

            //写入数值
            CurrentDataMemory.WriteBytesDirect(CurrentMemoryPointer, (int)(HisValueStartAddr + vcount * SizeOfValue), RealMemoryPtr, RealValueAddr, SizeOfValue);

            //更新质量戳
            CurrentDataMemory.WriteByteDirect(CurrentMemoryPointer, (int)(HisQulityStartAddr + vcount), MemoryHelper.ReadByte((void *)(RealMemoryPtr), RealValueAddr + SizeOfValue + 8));
            // CurrentDataMemory.WriteByteDirect(CurrentMemoryPointer, (int)(HisQulityStartAddr + vcount), RealMemoryAddr[RealValueAddr + SizeOfValue + 8]);
        }
示例#4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <returns></returns>
 public virtual float ReadFloat(long offset)
 {
     mPosition = offset + 4;
     return(MemoryHelper.ReadFloat((void *)mHandles, offset));
 }
示例#5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <returns></returns>
 public virtual ulong ReadULong(long offset)
 {
     mPosition = offset + 8;
     return(MemoryHelper.ReadUInt64((void *)mHandles, offset));
 }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="offset"></param>
        /// <returns></returns>
        public virtual DateTime ReadDateTime(long offset)
        {
            mPosition = offset + sizeof(DateTime);

            return(MemoryHelper.ReadDateTime((void *)mHandles, offset));
        }
示例#7
0
 public virtual uint ReadUInt(long offset)
 {
     mPosition = offset + 4;
     return(MemoryHelper.ReadUInt32((void *)mHandles, offset));
 }
示例#8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public virtual void WriteULong(long offset, ulong value)
 {
     MemoryHelper.WriteUInt64((void *)mHandles, offset, value);
     Position = offset + 8;
 }
示例#9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public void WriteULongDirect(long offset, ulong value)
 {
     MemoryHelper.WriteUInt64((void *)mHandles, offset, value);
 }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="tid"></param>
        /// <param name="offset"></param>
        /// <param name="dataTimes"></param>
        /// <param name="timetick"></param>
        /// <returns></returns>
        private static Dictionary <MarshalMemoryBlock, Tuple <List <DateTime>, int> > ReadTagDataBlock2(DataFileSeriserbase datafile, int tid, long offset, List <DateTime> dataTimes, out int timetick)
        {
            int      fileDuration, blockDuration = 0;
            int      tagCount     = 0;
            long     blockpointer = 0;
            DateTime time;
            var      tagIndex = ReadTagIndexInDataPointer(datafile, tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);

            Dictionary <long, MarshalMemoryBlock> rtmp = new Dictionary <long, MarshalMemoryBlock>();

            Dictionary <MarshalMemoryBlock, Tuple <List <DateTime>, int> > re = new Dictionary <MarshalMemoryBlock, Tuple <List <DateTime>, int> >();

            if (tagCount == 0)
            {
                return(re);
            }

            int blockcount = fileDuration * 60 / blockDuration;

            var startTime = datafile.ReadDateTime(0);

            int buffersize = 1024 * 1024 * 2;
            //分配读缓存
            IntPtr mdataBuffer    = Marshal.AllocHGlobal(buffersize);
            long   mbufferadderss = 0;
            int    bufferLen      = buffersize;


            // var headdata = GetHeadBlock(datafile, offset + blockpointer, tagCount * blockcount * 12);

            var headdata = datafile.Read(offset + blockpointer + tagIndex * blockcount * 12, blockcount * 12);

            long mLastBuffer       = 0;
            int  mLastDataLoc      = 0;
            int  mLastDataSize     = 0;
            MarshalMemoryBlock vmm = null;

            foreach (var vdd in dataTimes)
            {
                var ttmp       = (vdd - startTime).TotalMinutes;
                int blockindex = (int)(ttmp / blockDuration);

                if (blockindex > blockcount)
                {
                    throw new Exception("DataPointer index is out of total block number");
                }

                //var dataPointer = headdata.ReadInt(tagIndex * blockcount * 12 + blockindex * 12); //读取DataBlock的相对地址
                //var dataPointerbase = headdata.ReadLong(tagIndex * blockcount * 12 + blockindex * 12 + 4); //读取DataBlock的基地址

                var dataPointer     = headdata.ReadInt(blockindex * 12);      //读取DataBlock的相对地址
                var dataPointerbase = headdata.ReadLong(blockindex * 12 + 4); //读取DataBlock的基地址

                if (dataPointerbase > 0)
                {
                    ////var datasize = datafile.ReadInt(dataPointer); //读取DataBlock 的大小
                    //var vmm = GetDataMemory(datafile, dataPointerbase, dataPointer);


                    if (dataPointer > 0)
                    {
                        vmm = GetDataMemory(datafile, dataPointerbase, dataPointer);
                    }
                    else
                    {
                        //说明数据没有采用Zip压缩,可以直接读取使用
                        var dp       = dataPointerbase + (dataPointer & 0x7FFFFFFF);
                        int datasize = 0;
                        int dataloc  = 0;
                        if (dp >= mbufferadderss && (dp - mbufferadderss + 4) <= bufferLen && (dp - mbufferadderss + 4 + MemoryHelper.ReadInt32(mdataBuffer, dp - mbufferadderss)) <= bufferLen)
                        {
                            datasize = MemoryHelper.ReadInt32(mdataBuffer, dp - mbufferadderss);
                            dataloc  = (int)(dp - mbufferadderss + 4);
                        }
                        else
                        {
                            bufferLen      = datafile.Read(mdataBuffer, dp, buffersize);
                            mbufferadderss = dp;
                            datasize       = MemoryHelper.ReadInt32(mdataBuffer, 0);
                            dataloc        = (int)(dp - mbufferadderss + 4);
                        }

                        if (datasize > 0 && (mLastBuffer != mbufferadderss || mLastDataLoc != dataloc || mLastDataSize != datasize))
                        {
                            vmm = new MarshalMemoryBlock(datasize, datasize);
                            MemoryHelper.MemoryCopy(mdataBuffer, dataloc, vmm.Buffers[0], 0, datasize);

                            mLastBuffer   = mbufferadderss;
                            mLastDataLoc  = dataloc;
                            mLastDataSize = datasize;
                        }
                        else if (datasize <= 0)
                        {
                            vmm = null;
                        }
                    }

                    if (vmm != null)
                    {
                        if (!rtmp.ContainsKey(dataPointer))
                        {
                            //var rmm = datafile.Read(dataPointer + 4, datasize);
                            if (!re.ContainsKey(vmm))
                            {
                                re.Add(vmm, new Tuple <List <DateTime>, int>(new List <DateTime>()
                                {
                                    vdd
                                }, blockindex));
                            }
                            else
                            {
                                re[vmm].Item1.Add(vdd);
                            }
                            rtmp.Add(dataPointer, vmm);
                        }
                        else
                        {
                            //var rmm = rtmp[dataPointer];
                            if (!re.ContainsKey(vmm))
                            {
                                re.Add(vmm, new Tuple <List <DateTime>, int>(new List <DateTime>()
                                {
                                    vdd
                                }, blockindex));
                            }
                            else
                            {
                                re[vmm].Item1.Add(vdd);
                            }
                        }
                    }
                }
            }

            headdata.Dispose();
            Marshal.FreeHGlobal(mdataBuffer);
            return(re);
        }
示例#11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="startTime"></param>
        /// <param name="tid"></param>
        /// <param name="offset"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="timetick"></param>
        /// <returns></returns>
        private static IEnumerable <Tuple <MarshalMemoryBlock, DateTime, DateTime, int> > ReadTagDataBlock2(DataFileSeriserbase datafile, int tid, long offset, DateTime start, DateTime end)
        {
            int      fileDuration, blockDuration = 0;
            int      tagCount     = 0;
            long     blockpointer = 0;
            int      timetick     = 0;
            DateTime time;

            var tagIndex   = ReadTagIndexInDataPointer(datafile, tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);
            int blockcount = fileDuration * 60 / blockDuration;

            //读取文件开始时间
            var startTime = datafile.ReadDateTime(0);

            DateTime sstart = start;
            DateTime send   = end;

            int buffersize = 1024 * 1024 * 2;
            //分配读缓存
            IntPtr mdataBuffer    = Marshal.AllocHGlobal(buffersize);
            long   mbufferadderss = 0;
            int    bufferLen      = 0;

            //var headdata = GetHeadBlock(datafile, offset + blockpointer, tagCount * blockcount * 12);

            var headdata = datafile.Read(offset + blockpointer + tagIndex * blockcount * 12, blockcount * 12);

            while (sstart < end)
            {
                var ttmp = Math.Round((sstart - startTime).TotalSeconds, 3);
                var vv   = blockDuration * 60 - (ttmp % (blockDuration * 60));
                send = sstart.AddSeconds(vv);

                if (send > end)
                {
                    send = end;
                }
                int blockindex = (int)(ttmp / (blockDuration * 60));

                if (blockindex >= blockcount)
                {
                    break;
                    //throw new Exception("DataPointer index is out of total block number");
                }

                //var dataPointer = headdata.ReadInt(tagIndex* blockcount * 12 + blockindex  * 12); //读取DataBlock的相对地址
                //var dataPointerbase = headdata.ReadLong(tagIndex * blockcount * 12 + blockindex * 12 + 4); //读取DataBlock的基地址


                var dataPointer = headdata.ReadInt(blockindex * 12);          //读取DataBlock的相对地址

                var dataPointerbase = headdata.ReadLong(blockindex * 12 + 4); //读取DataBlock的基地址

                if (dataPointerbase > 0)
                {
                    MarshalMemoryBlock vmm = null;
                    if (dataPointer > 0)
                    {
                        vmm = GetDataMemory(datafile, dataPointerbase, dataPointer);
                    }
                    else
                    {
                        //说明数据没有采用Zip压缩,可以直接读取使用
                        var dp       = dataPointerbase + (dataPointer & 0x7FFFFFFF);
                        int datasize = 0;
                        int dataloc  = 0;
                        if (dp >= mbufferadderss && (dp - mbufferadderss + 4) <= bufferLen && (dp - mbufferadderss + 4 + MemoryHelper.ReadInt32(mdataBuffer, dp - mbufferadderss)) <= bufferLen)
                        {
                            datasize = MemoryHelper.ReadInt32(mdataBuffer, dp - mbufferadderss);
                            dataloc  = (int)(dp - mbufferadderss + 4);
                        }
                        else
                        {
                            bufferLen      = datafile.Read(mdataBuffer, dp, buffersize);
                            mbufferadderss = dp;
                            datasize       = MemoryHelper.ReadInt32(mdataBuffer, 0);
                            dataloc        = (int)(dp - mbufferadderss + 4);
                        }

                        if (datasize > 0)
                        {
                            vmm = new MarshalMemoryBlock(datasize, datasize);
                            MemoryHelper.MemoryCopy(mdataBuffer, dataloc, vmm.Buffers[0], 0, datasize);
                        }
                    }
                    if (vmm != null)
                    {
                        yield return(new Tuple <MarshalMemoryBlock, DateTime, DateTime, int>(vmm, sstart, send, timetick));
                    }
                }
                sstart = send;
            }

            headdata.Dispose();
            Marshal.FreeHGlobal(mdataBuffer);
        }
示例#12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public void WriteByteDirect(long offset, byte value)
 {
     MemoryHelper.WriteByte((void *)mHandles, offset, value);
 }
示例#13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public void WriteByte(long offset, byte value)
 {
     MemoryHelper.WriteByte((void *)mHandles, offset, value);
     Position = offset + 1;
 }
示例#14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public void WriteLong(long offset, long value)
 {
     MemoryHelper.WriteInt64((void *)mHandles, offset, value);
     Position = offset + 8;
 }
示例#15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public virtual void WriteUShort(long offset, ushort value)
 {
     MemoryHelper.WriteUShort((void *)mHandles, offset, value);
     Position = offset + 2;
 }
示例#16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public virtual void WriteFloat(long offset, float value)
 {
     MemoryHelper.WriteFloat((void *)mHandles, offset, value);
     Position = offset + 4;
 }
示例#17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public void WriteUShortDirect(long offset, ushort value)
 {
     MemoryHelper.WriteUShort((void *)mHandles, offset, value);
 }
示例#18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public virtual void WriteFloatDirect(long offset, float value)
 {
     MemoryHelper.WriteFloat((void *)mHandles, offset, value);
 }
示例#19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="offset"></param>
        /// <returns></returns>

        public virtual int ReadInt(long offset)
        {
            mPosition = offset + sizeof(int);
            return(MemoryHelper.ReadInt32((void *)mHandles, offset));
        }
示例#20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public virtual void WriteDouble(long offset, double value)
 {
     MemoryHelper.WriteDouble((void *)mHandles, offset, value);
     Position = offset + 8;
 }
示例#21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <returns></returns>
 public virtual ushort ReadUShort(long offset)
 {
     mPosition = offset + 2;
     return(MemoryHelper.ReadUShort((void *)mHandles, offset));
 }
示例#22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public virtual void WriteDoubleDirect(long offset, double value)
 {
     MemoryHelper.WriteDouble((void *)mHandles, offset, value);
 }
示例#23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <returns></returns>
 public virtual double ReadDouble(long offset)
 {
     mPosition = offset + 8;
     return(MemoryHelper.ReadDouble((void *)mHandles, offset));
 }
示例#24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public virtual void WriteDatetime(long offset, DateTime value)
 {
     MemoryHelper.WriteDateTime((void *)mHandles, offset, value);
     Position = offset + 8;
 }
示例#25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <returns></returns>
 public virtual byte ReadByte(long offset)
 {
     mPosition = offset + 1;
     return(MemoryHelper.ReadByte((void *)mHandles, offset));
 }
示例#26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public virtual void WriteUInt(long offset, uint value)
 {
     MemoryHelper.WriteUInt32((void *)mHandles, offset, value);
     Position = offset + 4;
 }
示例#27
0
文件: HisRunTag.cs 项目: cdy816/mars
        public virtual void UpdateValue2(int count, int tim)
        {
            var vcount = count > MaxCount ? MaxCount : count;

            Count = vcount;

            //数据内容: 时间戳(time1+time2+...) +数值区(value1+value2+...)+质量戳区(q1+q2+....)
            //实时数据内存结构为:实时值+时间戳+质量戳,时间戳2个字节,质量戳1个字节
            HisValueMemoryStartAddr.WriteUShortDirect((int)(HisValueMemoryStartAddr.TimerAddress + vcount * 2), (ushort)(tim));

            //写入数值
            HisValueMemoryStartAddr.WriteBytesDirect((int)(HisValueMemoryStartAddr.ValueAddress + vcount * SizeOfValue), RealMemoryPtr, RealValueAddr, SizeOfValue);

            //更新质量戳
            //HisValueMemoryStartAddr.WriteByteDirect((int)(HisValueMemoryStartAddr.QualityAddress + vcount), RealMemoryAddr[RealValueAddr + SizeOfValue + 8]);
            HisValueMemoryStartAddr.WriteByteDirect((int)(HisValueMemoryStartAddr.QualityAddress + vcount), MemoryHelper.ReadByte((void *)(RealMemoryPtr), RealValueAddr + SizeOfValue + 8));
        }
示例#28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="value"></param>
 public void WriteUIntDirect(long offset, uint value)
 {
     MemoryHelper.WriteUInt32((void *)mHandles, offset, value);
 }
示例#29
0
        /// <summary>
        /// 拷贝DataRegion数据
        /// </summary>
        /// <param name="msource">源流</param>
        /// <param name="sourceheadpoint">源数据块指针</param>
        /// <param name="tagcount">变量个数</param>
        /// <param name="blockcount">数据块个数</param>
        /// <param name="mtarget">目标流</param>
        /// <param name="targetheadpoint">目标数据块</param>
        private unsafe void CopyRegionData(System.IO.Stream msource, MarshalFixedMemoryBlock sourceheadpoint, int tagcount, int blockcount, System.IO.Stream mtarget, out MarshalFixedMemoryBlock targetheadpoint)
        {
            //Stopwatch sw = new Stopwatch();
            //sw.Start();

            MarshalFixedMemoryBlock re   = new MarshalFixedMemoryBlock(sourceheadpoint.Length);
            MarshalFixedMemoryBlock data = new MarshalFixedMemoryBlock(blockcount * 302 * 264 * 2);

            //int bufferLenght = 2*1024 * 1024;
            //IntPtr[] databuffers = new IntPtr[blockcount];
            //long[] databufferLocations = new long[blockcount];
            //int[] databufferLens = new int[blockcount];

            //for(int i=0;i<blockcount;i++)
            //{
            //    databuffers[i] = Marshal.AllocHGlobal(bufferLenght);
            //}
            //sw.Stop();
            //LoggerService.Service.Debug("HisDataArrange", "初始化分配内存 耗时:"+ ltmp1 +"," +(sw.ElapsedMilliseconds-ltmp1));

            mtarget.Position += tagcount * 8 * blockcount;

            long mtargetposition = mtarget.Position;
            int  offset          = 0;

            for (int tagid = 0; tagid < tagcount; tagid++)
            {
                data.Clear();
                offset          = 0;
                mtargetposition = mtarget.Position;
                for (int blockid = 0; blockid < blockcount; blockid++)
                {
                    CheckPaused();

                    var baseaddress = sourceheadpoint.ReadInt(blockid * tagcount * 8 + tagid * 8);
                    //var baseaddress = sourceheadpoint.ReadLong(j * tagcount * 8 + i * 8 + 4);

                    if (baseaddress > 0)
                    {
                        //重新组织数据块指针的分布形式,使得一个变量的数据块指针在一起
                        //re.WriteInt(j * 12 + i * blockcount * 12, (int)(offset | 0x80000000));
                        //re.WriteLong(j * 12 + i * blockcount * 12 + 4, mtargetposition);
                        re.WriteLong(blockid * 8 + tagid * blockcount * 8, mtargetposition + offset);

                        int datasize = 0;
                        int dataloc  = 0;
                        if (baseaddress >= databufferLocations[blockid] && (baseaddress - databufferLocations[blockid] + 4) <= databufferLens[blockid] && (baseaddress - databufferLocations[blockid] + 4 + MemoryHelper.ReadInt32((void *)databuffers[blockid], baseaddress - databufferLocations[blockid])) <= databufferLens[blockid])
                        {
                            datasize = MemoryHelper.ReadInt32((void *)databuffers[blockid], baseaddress - databufferLocations[blockid]);
                            dataloc  = (int)(baseaddress - databufferLocations[blockid] + 4);
                        }
                        else
                        {
                            int len = (int)Math.Min(bufferLenght, msource.Length - msource.Position);
                            msource.Position = baseaddress;
                            msource.Read(new Span <byte>((void *)databuffers[blockid], len));
                            databufferLocations[blockid] = baseaddress;
                            databufferLens[blockid]      = len;
                            datasize = MemoryHelper.ReadInt32((void *)databuffers[blockid], 0);
                            dataloc  = (int)(baseaddress - databufferLocations[blockid] + 4);
                        }

                        data.CheckAndResize(data.Position + datasize + 4, 0.5);
                        data.WriteInt(offset, datasize);
                        offset += 4;


                        if ((dataloc + datasize) > bufferLenght || datasize <= 0)
                        {
                            targetheadpoint = null;
                            continue;
                        }

                        Buffer.MemoryCopy((void *)(databuffers[blockid] + dataloc), (void *)(data.Buffers + offset), datasize, datasize);
                        data.Position += datasize;
                        offset        += datasize;
                    }
                    else
                    {
                        //重新组织数据块指针的分布形式,使得一个变量的数据块指针在一起
                        //re.WriteInt(j * 12 + i * blockcount * 12, 0);
                        re.WriteLong(blockid * 8 + tagid * blockcount * 8, 0);
                    }
                }

                data.WriteToStream(mtarget, 0, offset);
            }

            data.Dispose();

            //for (int i = 0; i < blockcount; i++)
            //{
            //    Marshal.FreeHGlobal(databuffers[i]);
            //}

            targetheadpoint = re;
        }
示例#30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="time"></param>
        /// <param name="qulity"></param>
        public void Add(object value, DateTime time, byte qulity)
        {
            if (mCount >= mLimite)
            {
                int newCount = (int)(mCount * 1.2);
                Resize(newCount);
                mLimite = newCount;
            }

            switch (mDataType)
            {
            case 0:
                Marshal.WriteByte(handle + mPosition, (byte)(((bool)value)?1:0));
                mPosition++;
                break;

            case 1:
                Marshal.WriteByte(handle + mPosition, (byte)value);
                //mDataBuffer[mPosition] = (byte)value;
                mPosition++;
                break;

            case 2:
                MemoryHelper.WriteShort((void *)handle, mPosition, Convert.ToInt16(value));
                mPosition += 2;
                break;

            case 3:
                MemoryHelper.WriteUShort((void *)handle, mPosition, Convert.ToUInt16(value));
                mPosition += 2;
                break;

            case 4:
                MemoryHelper.WriteInt32((void *)handle, mPosition, Convert.ToInt32(value));
                mPosition += 4;
                break;

            case 5:
                MemoryHelper.WriteUInt32((void *)handle, mPosition, Convert.ToUInt32(value));
                mPosition += 4;
                break;

            case 6:
                MemoryHelper.WriteInt64((void *)handle, mPosition, Convert.ToInt64(value));
                mPosition += 8;
                break;

            case 7:
                MemoryHelper.WriteUInt64((void *)handle, mPosition, Convert.ToUInt64(value));
                mPosition += 8;
                break;

            case 8:
                MemoryHelper.WriteFloat((void *)handle, mPosition, Convert.ToSingle(value));
                mPosition += 4;
                break;

            case 9:
                MemoryHelper.WriteDouble((void *)handle, mPosition, Convert.ToDouble(value));
                mPosition += 8;
                break;

            case 10:
                try
                {
                    MemoryHelper.WriteDateTime((void *)handle, mPosition, (DateTime)value);
                }
                catch
                {
                }
                mPosition += 8;
                break;

            case 11:

                var sdata = Encoding.Unicode.GetBytes((string)value);
                MemoryHelper.WriteByte((void *)handle, mPosition, (byte)sdata.Length);
                mPosition++;

                Marshal.Copy(sdata, 0, handle + mPosition, sdata.Length);
                mPosition += sdata.Length;
                break;

            case 12:
                Add((IntPointData)value, time, qulity);
                return;

            case 13:
                Add((UIntPointData)value, time, qulity);
                return;

            case 14:
                Add((IntPoint3Data)value, time, qulity);
                return;

            case 15:
                Add((UIntPoint3Data)value, time, qulity);
                return;

            case 16:
                Add((LongPointData)value, time, qulity);
                return;

            case 17:
                Add((ULongPointData)value, time, qulity);
                return;

            case 18:
                Add((LongPoint3Data)value, time, qulity);
                return;

            case 19:
                Add((ULongPoint3Data)value, time, qulity);
                return;
            }
            MemoryHelper.WriteDateTime((void *)handle, mCount * 8 + mTimeAddr, time);
            Marshal.WriteByte(handle + mCount + mQulityAddr, (byte)qulity);
            // mDataBuffer[mCount + mQulityAddr] = qulity;
            mCount++;
        }