示例#1
0
        public bool WriteRawFloatValueByType(double value, DataUtils.DataType destType, uint address)
        {
            bool result = false;

            if (address >= StartAddress)
            {
                result = DataUtils.WriteRawFloatValueByType(value, destType, RawData, address - StartAddress);
            }

            return(result);
        }
示例#2
0
        public bool ReadRawIntValueByType(out uint value, DataUtils.DataType sourceType, uint address)
        {
            bool result = false;

            value = 0;

            if (address >= StartAddress)
            {
                result = DataUtils.ReadRawIntValueByType(out value, sourceType, RawData, address - StartAddress);
            }

            return(result);
        }
示例#3
0
        protected bool CalculateChecksumForRange(uint startAddr, uint numBytes, DataUtils.DataType readingType, out uint checksum)
        {
            bool result = false;

            checksum = 0;

            if ((startAddr >= 0) && (numBytes > 0) && (mMemory != null))
            {
                result = true;

                for (uint addr = startAddr; addr < startAddr + numBytes; addr += DataUtils.GetDataTypeSize(readingType))
                {
                    uint temp = 0;

                    result &= mMemory.ReadRawIntValueByType(out temp, readingType, addr);

                    checksum += temp;
                }
            }

            return(result);
        }
        public override double ConvertTo(byte[] rawData, DataUtils.DataType dataType)
        {
            double rawValue = 0.0;

            if (rawData != null)
            {
                if (BitMask != 0xFFFFFFFF)
                {
                    byte[] localRawData = new byte[rawData.Length];

                    for (int x = 0; x < rawData.Length; x++)
                    {
                        localRawData[x] = (byte)(rawData[x] & (BitMask >> x));
                    }

                    rawData = localRawData;
                }

                DataUtils.ReadRawFloatValueByType(out rawValue, dataType, rawData, 0);
            }

            return(DataUtils.GetCorrectedValueFromRaw(rawValue, Scale, Offset));
        }
 public override byte[] ConvertFrom(double val, DataUtils.DataType dataType)
 {
     throw new NotImplementedException();
 }
 public abstract double ConvertTo(byte[] rawData, DataUtils.DataType dataType);
 public abstract byte[] ConvertFrom(double val, DataUtils.DataType dataType);
示例#8
0
        public static unsafe bool ReadRawIntValueByType(out UInt32 value, DataUtils.DataType sourceType, byte[] rawData, UInt32 offset)
        {
            bool result = false;

            value = 0;

            if ((rawData != null) && (GetDataTypeSize(sourceType) + offset <= rawData.Length))
            {
                result = true;

                fixed(void *source = &rawData[offset])
                {
                    switch (sourceType)
                    {
                    case DataUtils.DataType.Int8:
                    {
                        value = (UInt32)(*(SByte *)(source));
                        break;
                    }

                    case DataUtils.DataType.UInt8:
                    {
                        value = *(Byte *)(source);
                        Debug.Assert(value >= 0.0);
                        break;
                    }

                    case DataUtils.DataType.Int16:
                    {
                        value = (UInt32)(*(Int16 *)(source));
                        break;
                    }

                    case DataUtils.DataType.UInt16:
                    {
                        value = *(UInt16 *)(source);
                        Debug.Assert(value >= 0.0);
                        break;
                    }

                    case DataUtils.DataType.Int32:
                    {
                        value = (UInt32)(*(Int32 *)(source));
                        break;
                    }

                    case DataUtils.DataType.UInt32:
                    {
                        value = *(UInt32 *)(source);
                        Debug.Assert(value >= 0.0);
                        break;
                    }

                    default:
                    {
                        value  = 0;
                        result = false;
                        break;
                    }
                    }
                }
            }

            return(result);
        }
示例#9
0
        public static unsafe bool WriteRawIntValueByType(UInt32 value, DataUtils.DataType destType, byte[] rawDataDest, UInt32 offset)
        {
            bool result = false;

            if ((rawDataDest != null) && (GetDataTypeSize(destType) + offset <= rawDataDest.Length))
            {
                result = true;

                fixed(void *dest = &rawDataDest[offset])
                {
                    switch (destType)
                    {
                    case DataUtils.DataType.Int8:
                    {
                        SByte *castDest = (SByte *)dest;
                        *      castDest = (SByte)Math.Min(Math.Max(value, SByte.MinValue), SByte.MaxValue);
                        break;
                    }

                    case DataUtils.DataType.UInt8:
                    {
                        Byte *castDest = (Byte *)dest;
                        *     castDest = (Byte)Math.Min(Math.Max(value, Byte.MinValue), Byte.MaxValue);
                        break;
                    }

                    case DataUtils.DataType.Int16:
                    {
                        Int16 *castDest = (Int16 *)dest;
                        *      castDest = (Int16)Math.Min(Math.Max(value, Int16.MinValue), Int16.MaxValue);
                        break;
                    }

                    case DataUtils.DataType.UInt16:
                    {
                        UInt16 *castDest = (UInt16 *)dest;
                        *       castDest = (UInt16)Math.Min(Math.Max(value, UInt16.MinValue), UInt16.MaxValue);
                        break;
                    }

                    case DataUtils.DataType.Int32:
                    {
                        Int32 *castDest = (Int32 *)dest;
                        *      castDest = (Int32)Math.Min(Math.Max(value, Int32.MinValue), Int32.MaxValue);
                        break;
                    }

                    case DataUtils.DataType.UInt32:
                    {
                        UInt32 *castDest = (UInt32 *)dest;
                        *       castDest = (UInt32)Math.Min(Math.Max(value, UInt32.MinValue), UInt32.MaxValue);
                        break;
                    }

                    default:
                    {
                        result = false;
                        break;
                    }
                    }
                }
            }

            return(result);
        }