From 000d0ade8ea5a50a4205346660871dcef3b88140 Mon Sep 17 00:00:00 2001 From: tq <1916474859@qq,com> Date: Thu, 18 Apr 2024 13:07:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleStarter/Program.cs | 15 ++++++++------- ConsoleStarter/TestPerson.cs | 14 ++++++++++++++ HybirdFrameworkCore/Utils/ModelConvert.cs | 10 +++++++--- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/ConsoleStarter/Program.cs b/ConsoleStarter/Program.cs index 33e315e..650c04c 100644 --- a/ConsoleStarter/Program.cs +++ b/ConsoleStarter/Program.cs @@ -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 list = new List @@ -145,7 +147,6 @@ internal class Program { Console.WriteLine(b); } - } private static void Test1() diff --git a/ConsoleStarter/TestPerson.cs b/ConsoleStarter/TestPerson.cs index 5b41052..124ad2f 100644 --- a/ConsoleStarter/TestPerson.cs +++ b/ConsoleStarter/TestPerson.cs @@ -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)] diff --git a/HybirdFrameworkCore/Utils/ModelConvert.cs b/HybirdFrameworkCore/Utils/ModelConvert.cs index d5c0760..0004a15 100644 --- a/HybirdFrameworkCore/Utils/ModelConvert.cs +++ b/HybirdFrameworkCore/Utils/ModelConvert.cs @@ -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)