/// <summary> /// /// </summary> /// <param name="startMemory"></param> /// <param name="offset"></param> /// <returns></returns> public override unsafe bool CheckValueChangeToLastRecordValue(void *startMemory, long offset) { mTmpValue = MemoryHelper.ReadByte(startMemory, offset); if (mTmpValue != mLastValue || mLastValue == byte.MinValue) { mLastValue = mTmpValue; return(true); } else { return(false); } }
/// <summary> /// /// </summary> /// <param name="startMemory"></param> /// <param name="offset"></param> /// <returns></returns> public override unsafe bool CheckValueChangeToLastRecordValue(void *startMemory, long offset) { var len = MemoryHelper.ReadByte(startMemory, offset + 1); var mTmpValue = new string((char *)startMemory, (int)(offset + 1), len); if (mTmpValue != mLastValue) { mLastValue = mTmpValue; return(true); } else { return(false); } }
public void UpdateValue(int count, int tim) { var vcount = count > MaxCount ? MaxCount : count; Count = vcount; //数据内容: 时间戳(time1+time2+...) +数值区(value1+value2+...)+质量戳区(q1+q2+....) //实时数据内存结构为:实时值+时间戳+质量戳,时间戳2个字节,质量戳1个字节 HisAddr.WriteUShortDirect(TimerValueStartAddr + vcount * 2, (ushort)(tim)); //写入数值 HisAddr.WriteBytesDirect(HisValueStartAddr + vcount * SizeOfValue, RealMemoryPtr, RealValueAddr, SizeOfValue); //更新质量戳 // HisAddr.WriteByteDirect(HisQulityStartAddr + vcount, RealMemoryAddr[RealValueAddr + SizeOfValue + 8]); HisAddr.WriteByteDirect(HisQulityStartAddr + vcount, MemoryHelper.ReadByte((void *)(RealMemoryPtr), RealValueAddr + SizeOfValue + 8)); }
/// <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]); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="offset"></param> /// <returns></returns> public virtual byte ReadByte(long offset) { mPosition = offset + 1; return(MemoryHelper.ReadByte((void *)mHandles, offset)); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="index"></param> /// <returns></returns> public byte GetQuality(int index) { return(MemoryHelper.ReadByte((void *)handle, mQulityAddr + index)); }
/// <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.ReadShort((void *)handle, index * 2); break; case 4: re = MemoryHelper.ReadInt32((void *)handle, index * 4); break; case 5: re = MemoryHelper.ReadInt32((void *)handle, index * 4); break; case 6: re = MemoryHelper.ReadInt32((void *)handle, index * 8); break; case 7: re = MemoryHelper.ReadInt32((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: int cc = 0; int pos = 0; while (true) { if (cc >= index) { break; } //pos += (mDataBuffer[pos]+1); pos += MemoryHelper.ReadByte((void *)handle, pos) + 1; cc++; } re = new string((char *)handle, pos + 1, MemoryHelper.ReadByte((void *)handle, pos)); break; } time = MemoryHelper.ReadDateTime((void *)handle, index * 8 + mTimeAddr); qulity = MemoryHelper.ReadByte((void *)handle, mQulityAddr + index); return((T)re); }