master
tq 6 months ago
parent 825050bf85
commit 000d0ade8e

@ -9,8 +9,6 @@ internal class Program
{
public static void Main(string[] args)
{
TestPerson testPerson = new TestPerson();
testPerson.intParam = 11;
testPerson.intParamNull = 12;
@ -36,6 +34,8 @@ internal class Program
// testPerson.de2 = -12.12d;
// testPerson.bl = false;
testPerson.ft2 = -13.126f;
testPerson.ft3 = 1000f;
testPerson.d3 = -13.129d;
byte[] bytes2 = ModelConvert.Encode(testPerson);
@ -64,10 +64,12 @@ internal class Program
//double c6 = testPerson1.de2;
//bool c4 = testPerson1.bl;
float c5 = testPerson1.ft2;
// 偏移量
float c6 = testPerson1.ft3;
// double负数转换
double d3 = testPerson1.d3;
double d4 = -d3;
List<PropertyAttribute> list = new List<PropertyAttribute>
@ -145,7 +147,6 @@ internal class Program
{
Console.WriteLine(b);
}
}
private static void Test1()

@ -80,6 +80,20 @@ public class TestPerson
[PropertyAttribute(384, 4, PropertyReadConstant.Byte, 0.1, 2)]
public float ft2 { get; set; }
[PropertyAttribute(416, 4, PropertyReadConstant.Byte, 1,0,300)]
public float ft3 { get; set; }
[PropertyAttribute(448, 4, PropertyReadConstant.Byte,0.01,2)]
public double d3 { get; set; }
//[PropertyAttribute(416, 8, PropertyReadConstant.Byte, 0.01, 2)]

@ -80,12 +80,16 @@ public static class ModelConvert
else if (propertyType == FLOAT)
{
field.SetValue(t,
Convert.ChangeType(Math.Round(BitUtls.Byte2Float(bytes, start, length, scale) - offset, attribute.Round), propertyType), null);
Convert.ChangeType(
Math.Round(BitUtls.Byte2Float(bytes, start, length, scale) - offset, attribute.Round),
propertyType), null);
}
else if (propertyType == DOUBLE)
{
field.SetValue(t,
Convert.ChangeType(Math.Round(BitUtls.Byte2Double(bytes, start, length, scale) - offset, attribute.Round), propertyType), null);
Convert.ChangeType(
Math.Round(BitUtls.Byte2Double(bytes, start, length, scale) - offset, attribute.Round),
propertyType), null);
}
else if (propertyType == STRING)
{
@ -164,7 +168,7 @@ public static class ModelConvert
if (propertyType == USHORT)
{
return BitConverter.GetBytes((ushort)(((short)value + offset) / scale));
return BitConverter.GetBytes((ushort)(((ushort)value + offset) / scale));
}
if (propertyType == SHORT)

Loading…
Cancel
Save