|
|
@ -18,6 +18,7 @@ public static class BitUtls
|
|
|
|
private static readonly Type FLOAT = typeof(float);
|
|
|
|
private static readonly Type FLOAT = typeof(float);
|
|
|
|
private static readonly Type DOUBLE = typeof(double);
|
|
|
|
private static readonly Type DOUBLE = typeof(double);
|
|
|
|
private static readonly Type STRING = typeof(string);
|
|
|
|
private static readonly Type STRING = typeof(string);
|
|
|
|
|
|
|
|
private static readonly Type BYTEARRAY = typeof(byte[]);
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
@ -211,6 +212,7 @@ public static class BitUtls
|
|
|
|
public static object Bytes2Value(byte[] bytes, Type propertyType, int start, int length,
|
|
|
|
public static object Bytes2Value(byte[] bytes, Type propertyType, int start, int length,
|
|
|
|
double scale, int round,double offset)
|
|
|
|
double scale, int round,double offset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (propertyType == BOOLEAN)
|
|
|
|
if (propertyType == BOOLEAN)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Convert.ChangeType(Byte2Bit(bytes, start, length) == 1, propertyType);
|
|
|
|
return Convert.ChangeType(Byte2Bit(bytes, start, length) == 1, propertyType);
|
|
|
@ -255,6 +257,18 @@ public static class BitUtls
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Convert.ChangeType(BytesToHexStr(bytes, start, length), propertyType);
|
|
|
|
return Convert.ChangeType(BytesToHexStr(bytes, start, length), propertyType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (propertyType == BYTEARRAY)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
length = length / 8;
|
|
|
|
|
|
|
|
byte[] bt = new byte[length];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = start; i < (start + length); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bt[i - start] = bytes[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
throw new ArgumentException($"参数类型{propertyType}不支持encode!");
|
|
|
|
throw new ArgumentException($"参数类型{propertyType}不支持encode!");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -320,6 +334,11 @@ public static class BitUtls
|
|
|
|
return Encoding.ASCII.GetBytes(s);
|
|
|
|
return Encoding.ASCII.GetBytes(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (propertyType == BYTEARRAY)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var bytes = value as byte[];
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
throw new ArgumentException($"参数类型{propertyType}不支持encode!");
|
|
|
|
throw new ArgumentException($"参数类型{propertyType}不支持encode!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|