master
tq 6 months ago
parent 825050bf85
commit 000d0ade8e

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

@ -82,6 +82,20 @@ public class TestPerson
public float ft2 { get; set; } 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)] //[PropertyAttribute(416, 8, PropertyReadConstant.Byte, 0.01, 2)]
//public double de2 { get; set; } //public double de2 { get; set; }

@ -80,12 +80,16 @@ public static class ModelConvert
else if (propertyType == FLOAT) else if (propertyType == FLOAT)
{ {
field.SetValue(t, 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) else if (propertyType == DOUBLE)
{ {
field.SetValue(t, 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) else if (propertyType == STRING)
{ {
@ -164,7 +168,7 @@ public static class ModelConvert
if (propertyType == USHORT) if (propertyType == USHORT)
{ {
return BitConverter.GetBytes((ushort)(((short)value + offset) / scale)); return BitConverter.GetBytes((ushort)(((ushort)value + offset) / scale));
} }
if (propertyType == SHORT) if (propertyType == SHORT)

Loading…
Cancel
Save