diff --git a/Modbus.Net/Modbus.Net.BigEndian3412/Modbus.Net.BigEndian3412.csproj b/Modbus.Net/Modbus.Net.BigEndian3412/Modbus.Net.BigEndian3412.csproj new file mode 100644 index 0000000..162b91f --- /dev/null +++ b/Modbus.Net/Modbus.Net.BigEndian3412/Modbus.Net.BigEndian3412.csproj @@ -0,0 +1,35 @@ + + + + net6.0 + 10.0 + Modbus.Net.BigEndian3412 + Modbus.Net.BigEndian3412 + Modbus.Net.BigEndian3412 + 1.4.1 + Chris L.(Luo Sheng) + Hangzhou Delian Science Technology Co.,Ltd. + Modbus.Net.Modbus + Modbus.Net Modbus Implementation + Copyright 2023 Hangzhou Delian Science Technology Co.,Ltd. + https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.BigEndian3412 + https://github.com/parallelbgls/Modbus.Net + git + hardware communicate protocol modbus Delian + False + True + True + True + MIT + README.md + snupkg + + + + + + + + + + \ No newline at end of file diff --git a/Modbus.Net/Modbus.Net.BigEndian3412/Modbus.Net.BigEndian3412ValueHelper.cs b/Modbus.Net/Modbus.Net.BigEndian3412/Modbus.Net.BigEndian3412ValueHelper.cs new file mode 100644 index 0000000..fd6c267 --- /dev/null +++ b/Modbus.Net/Modbus.Net.BigEndian3412/Modbus.Net.BigEndian3412ValueHelper.cs @@ -0,0 +1,53 @@ +using System; + +namespace Modbus.Net +{ + public partial class Endian + { + public const int BigEndian3412 = 10; + } + + public class BigEndian3412ValueHelper : BigEndianLsbValueHelper + { + private static BigEndian3412ValueHelper _bigEndian3412Instance; + + /// + /// 构造器 + /// + protected BigEndian3412ValueHelper() + { + } + + /// + /// 覆写的实例获取 + /// + protected override ValueHelper _Instance => _bigEndian3412Instance; + + /// + /// 是否为大端 + /// + protected new bool LittleEndian => false; + + protected new bool LittleEndianBit => false; + + /// + /// 覆盖的获取实例的方法 + /// + public new static BigEndian3412ValueHelper Instance + => _bigEndian3412Instance ?? (_bigEndian3412Instance = new BigEndian3412ValueHelper()); + + public override float GetFloat(byte[] data, ref int pos) + { + Array.Reverse(data, pos, 4); + byte temp; + temp = data[pos]; data[pos] = data[pos+2]; data[pos+2] = temp; + temp = data[pos+1]; data[pos+1] = data[pos+3]; data[pos+3] = temp; + var t = BitConverter.ToSingle(data, pos); + temp = data[pos]; data[pos] = data[pos+2]; data[pos+2] = temp; + temp = data[pos+1]; data[pos+1] = data[pos+3]; data[pos+3] = temp; + Array.Reverse(data, pos, 4); + pos += 4; + return t; + } + } +} \ No newline at end of file diff --git a/Modbus.Net/Modbus.Net.BigEndian3412/README.md b/Modbus.Net/Modbus.Net.BigEndian3412/README.md new file mode 100644 index 0000000..f407a2f --- /dev/null +++ b/Modbus.Net/Modbus.Net.BigEndian3412/README.md @@ -0,0 +1,5 @@ +Modbus.Net.BigEndian3412 +=================== +Self defined EndianHelper implementation of Modbus.Net + +Doc has been moved to wiki. \ No newline at end of file diff --git a/Modbus.Net/Modbus.Net.Modbus.NA200H/README.md b/Modbus.Net/Modbus.Net.Modbus.NA200H/README.md index effd5ac..f90e141 100644 --- a/Modbus.Net/Modbus.Net.Modbus.NA200H/README.md +++ b/Modbus.Net/Modbus.Net.Modbus.NA200H/README.md @@ -1,7 +1,5 @@ Modbus.Net.Modbus =================== -[![NuGet](https://img.shields.io/nuget/v/Modbus.Net.Modbus.NA200H.svg)](https://www.nuget.org/packages/Modbus.Net.Modbus.NA200H/) - NA200H Implementation of Modbus.Net Doc has been moved to wiki. \ No newline at end of file diff --git a/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample/Modbus.Net.Modbus.SelfDefinedSample.csproj b/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample/Modbus.Net.Modbus.SelfDefinedSample.csproj index 6e88179..dadfb9b 100644 --- a/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample/Modbus.Net.Modbus.SelfDefinedSample.csproj +++ b/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample/Modbus.Net.Modbus.SelfDefinedSample.csproj @@ -12,7 +12,7 @@ Modbus.Net.Modbus Modbus.Net Modbus Implementation Copyright 2023 Hangzhou Delian Science Technology Co.,Ltd. - https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.Modbus.NA200H + https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample https://github.com/parallelbgls/Modbus.Net git hardware communicate protocol modbus Delian diff --git a/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample/README.md b/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample/README.md index 6195267..bc7a19a 100644 --- a/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample/README.md +++ b/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample/README.md @@ -1,7 +1,5 @@ Modbus.Net.Modbus =================== -[![NuGet](https://img.shields.io/nuget/v/Modbus.Net.Modbus.SelfDefinedSample.svg)](https://www.nuget.org/packages/Modbus.Net.Modbus.SelfDefinedSample/) - Self defined function get time and set time implementation of Modbus.Net Doc has been moved to wiki. \ No newline at end of file diff --git a/Modbus.Net/Modbus.Net.sln b/Modbus.Net/Modbus.Net.sln index 346f06b..2e32314 100644 --- a/Modbus.Net/Modbus.Net.sln +++ b/Modbus.Net/Modbus.Net.sln @@ -36,6 +36,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.Modbus.SelfDefin EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "h-opc", "..\h-opc\h-opc\h-opc.csproj", "{DC6425E4-1409-488D-A014-4DCC909CF542}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.BigEndian3412", "Modbus.Net.BigEndian3412\Modbus.Net.BigEndian3412.csproj", "{D48D4F79-1DA2-4C91-A9EE-FDCAEC09E808}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -90,6 +92,10 @@ Global {DC6425E4-1409-488D-A014-4DCC909CF542}.Debug|Any CPU.Build.0 = Debug|Any CPU {DC6425E4-1409-488D-A014-4DCC909CF542}.Release|Any CPU.ActiveCfg = Release|Any CPU {DC6425E4-1409-488D-A014-4DCC909CF542}.Release|Any CPU.Build.0 = Release|Any CPU + {D48D4F79-1DA2-4C91-A9EE-FDCAEC09E808}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D48D4F79-1DA2-4C91-A9EE-FDCAEC09E808}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D48D4F79-1DA2-4C91-A9EE-FDCAEC09E808}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D48D4F79-1DA2-4C91-A9EE-FDCAEC09E808}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Modbus.Net/Modbus.Net/Enum/Enum.cs b/Modbus.Net/Modbus.Net/Enum/Enum.cs index 190c1de..a041131 100644 --- a/Modbus.Net/Modbus.Net/Enum/Enum.cs +++ b/Modbus.Net/Modbus.Net/Enum/Enum.cs @@ -55,20 +55,32 @@ namespace Modbus.Net public static Endian Parse(string value) { - if (typeof(Endian).GetField(value) != null) + var Assemblies = AssemblyHelper.GetAllLibraryAssemblies(); + foreach (var assembly in Assemblies) { - return (int)typeof(Endian).GetField(value).GetValue(null); + if (assembly.GetType("Modbus.Net.Endian")?.GetField(value) != null) + { + return (int)assembly.GetType("Modbus.Net.Endian").GetField(value).GetValue(null); + } } throw new NotSupportedException("Endian name " + value + " is not supported."); } public override string ToString() { - foreach (var field in typeof(Endian).GetFields()) + var Assemblies = AssemblyHelper.GetAllLibraryAssemblies(); + foreach (var assembly in Assemblies) { - if ((int)field.GetValue(null) == Value) + var endianType = assembly.GetType("Modbus.Net.Endian"); + if (endianType != null) { - return field.Name; + foreach (var field in endianType.GetFields()) + { + if ((int)field.GetValue(null) == Value) + { + return field.Name; + } + } } } return null;