Exemplo n.º 1
0
      public double GetDouble(uint address, bool absoluteAddress = false, uint?mask = null, int?shift = null)
      {
          object lockValue   = WatchVariableLockManager.GetMemoryLockValue(address, typeof(double), mask, shift);
          double?parsedValue = ParsingUtilities.ParseDoubleNullable(lockValue);

          if (parsedValue.HasValue)
          {
              return(parsedValue.Value);
          }

          return(BitConverter.ToDouble(ReadRam((UIntPtr)address, 8, EndiannessType.Little, absoluteAddress), 0));
      }
Exemplo n.º 2
0
        public static string FormatValue(object number, int?numDigits = null, bool usePrefix = true)
        {
            object numberFormatted = number;

            // Make sure it's a number
            if (!TypeUtilities.IsNumber(numberFormatted))
            {
                numberFormatted = ParsingUtilities.ParseDoubleNullable(numberFormatted);
                if (numberFormatted == null)
                {
                    return(number.ToString());
                }
            }

            // Convert floats/doubles into ints/uints
            if (numberFormatted is float || numberFormatted is double)
            {
                if (numberFormatted is float floatValue)
                {
                    numberFormatted = Math.Round(floatValue);
                }
                if (numberFormatted is double doubleValue)
                {
                    numberFormatted = Math.Round(doubleValue);
                }

                int?intValueNullable = ParsingUtilities.ParseIntNullable(numberFormatted);
                if (intValueNullable.HasValue)
                {
                    numberFormatted = intValueNullable.Value;
                }
                uint?uintValueNullable = ParsingUtilities.ParseUIntNullable(numberFormatted);
                if (uintValueNullable.HasValue)
                {
                    numberFormatted = uintValueNullable.Value;
                }
            }

            if (!TypeUtilities.IsIntegerNumber(numberFormatted))
            {
                return(number.ToString());
            }

            string numDigitsString = numDigits.HasValue ? numDigits.Value.ToString() : "";
            string hexString       = String.Format("{0:X" + numDigitsString + "}", numberFormatted);
            string prefix          = usePrefix ? "0x" : "";

            if (numDigits.HasValue)
            {
                hexString = StringUtilities.ExactLength(hexString, numDigits.Value, true, '0');
            }
            return(prefix + hexString);
        }
Exemplo n.º 3
0
        public bool SetValueRoundingWrapping(Type type, object value, uint address, bool absoluteAddress = false, uint?mask = null)
        {
            if (value is string)
            {
                value = ParsingUtilities.ParseDoubleNullable((string)value);
                if (value == null)
                {
                    return(false);
                }

                if (type == typeof(byte))
                {
                    value = ParsingUtilities.ParseByteRoundingWrapping((double)value);
                }
                if (type == typeof(sbyte))
                {
                    value = ParsingUtilities.ParseSByteRoundingWrapping((double)value);
                }
                if (type == typeof(short))
                {
                    value = ParsingUtilities.ParseShortRoundingWrapping((double)value);
                }
                if (type == typeof(ushort))
                {
                    value = ParsingUtilities.ParseUShortRoundingWrapping((double)value);
                }
                if (type == typeof(int))
                {
                    value = ParsingUtilities.ParseIntRoundingWrapping((double)value);
                }
                if (type == typeof(uint))
                {
                    value = ParsingUtilities.ParseUIntRoundingWrapping((double)value);
                }
            }

            return(SetValue(type, value.ToString(), address, absoluteAddress, mask));
        }
Exemplo n.º 4
0
      public bool SetValue(Type type, object value, uint address, bool absoluteAddress = false, uint?mask = null, int?shift = null)
      {
          if (value is string)
          {
              if (type == typeof(byte))
              {
                  value = ParsingUtilities.ParseByteNullable(value);
              }
              if (type == typeof(sbyte))
              {
                  value = ParsingUtilities.ParseSByteNullable(value);
              }
              if (type == typeof(short))
              {
                  value = ParsingUtilities.ParseShortNullable(value);
              }
              if (type == typeof(ushort))
              {
                  value = ParsingUtilities.ParseUShortNullable(value);
              }
              if (type == typeof(int))
              {
                  value = ParsingUtilities.ParseIntNullable(value);
              }
              if (type == typeof(uint))
              {
                  value = ParsingUtilities.ParseUIntNullable(value);
              }
              if (type == typeof(float))
              {
                  value = ParsingUtilities.ParseFloatNullable(value);
              }
              if (type == typeof(double))
              {
                  value = ParsingUtilities.ParseDoubleNullable(value);
              }
          }

          if (value == null)
          {
              return(false);
          }

          if (type == typeof(byte))
          {
              return(SetValue((byte)value, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(sbyte))
          {
              return(SetValue((sbyte)value, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(short))
          {
              return(SetValue((short)value, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(ushort))
          {
              return(SetValue((ushort)value, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(int))
          {
              return(SetValue((int)value, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(uint))
          {
              return(SetValue((uint)value, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(float))
          {
              return(SetValue((float)value, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(double))
          {
              return(SetValue((double)value, address, absoluteAddress, mask, shift));
          }

          throw new ArgumentOutOfRangeException("Cannot call ProcessStream.SetValue with type " + type);
      }
Exemplo n.º 5
0
      public bool SetValueRoundingWrapping(
          Type type, object value, uint address, bool absoluteAddress = false, uint?mask = null, int?shift = null)
      {
          // Allow short circuiting if object is already of type
          if (type == typeof(byte) && value is byte byteValue)
          {
              return(SetValue(byteValue, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(sbyte) && value is sbyte sbyteValue)
          {
              return(SetValue(sbyteValue, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(short) && value is short shortValue)
          {
              return(SetValue(shortValue, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(ushort) && value is ushort ushortValue)
          {
              return(SetValue(ushortValue, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(int) && value is int intValue)
          {
              return(SetValue(intValue, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(uint) && value is uint uintValue)
          {
              return(SetValue(uintValue, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(float) && value is float floatValue)
          {
              return(SetValue(floatValue, address, absoluteAddress, mask, shift));
          }
          if (type == typeof(double) && value is double doubleValue)
          {
              return(SetValue(doubleValue, address, absoluteAddress, mask, shift));
          }

          value = ParsingUtilities.ParseDoubleNullable(value);
          if (value == null)
          {
              return(false);
          }

          if (type == typeof(byte))
          {
              value = ParsingUtilities.ParseByteRoundingWrapping(value);
          }
          if (type == typeof(sbyte))
          {
              value = ParsingUtilities.ParseSByteRoundingWrapping(value);
          }
          if (type == typeof(short))
          {
              value = ParsingUtilities.ParseShortRoundingWrapping(value);
          }
          if (type == typeof(ushort))
          {
              value = ParsingUtilities.ParseUShortRoundingWrapping(value);
          }
          if (type == typeof(int))
          {
              value = ParsingUtilities.ParseIntRoundingWrapping(value);
          }
          if (type == typeof(uint))
          {
              value = ParsingUtilities.ParseUIntRoundingWrapping(value);
          }

          return(SetValue(type, value.ToString(), address, absoluteAddress, mask, shift));
      }