This commit is contained in:
luosheng
2023-06-28 13:09:50 +08:00
parent 6cd4e9d1e6
commit 49a7623651
8 changed files with 117 additions and 10 deletions

View File

@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<AssemblyName>Modbus.Net.BigEndian3412</AssemblyName>
<RootNamespace>Modbus.Net.BigEndian3412</RootNamespace>
<PackageId>Modbus.Net.BigEndian3412</PackageId>
<Version>1.4.1</Version>
<Authors>Chris L.(Luo Sheng)</Authors>
<Company>Hangzhou Delian Science Technology Co.,Ltd.</Company>
<Product>Modbus.Net.Modbus</Product>
<Description>Modbus.Net Modbus Implementation</Description>
<Copyright>Copyright 2023 Hangzhou Delian Science Technology Co.,Ltd.</Copyright>
<PackageProjectUrl>https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.BigEndian3412</PackageProjectUrl>
<RepositoryUrl>https://github.com/parallelbgls/Modbus.Net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>hardware communicate protocol modbus Delian</PackageTags>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<IncludeSymbols>True</IncludeSymbols>
<IncludeSource>True</IncludeSource>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath=""/>
</ItemGroup>
</Project>

View File

@@ -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;
/// <summary>
/// 构造器
/// </summary>
protected BigEndian3412ValueHelper()
{
}
/// <summary>
/// 覆写的实例获取
/// </summary>
protected override ValueHelper _Instance => _bigEndian3412Instance;
/// <summary>
/// 是否为大端
/// </summary>
protected new bool LittleEndian => false;
protected new bool LittleEndianBit => false;
/// <summary>
/// 覆盖的获取实例的方法
/// </summary>
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;
}
}
}

View File

@@ -0,0 +1,5 @@
Modbus.Net.BigEndian3412
===================
Self defined EndianHelper implementation of Modbus.Net
Doc has been moved to wiki.

View File

@@ -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.

View File

@@ -12,7 +12,7 @@
<Product>Modbus.Net.Modbus</Product>
<Description>Modbus.Net Modbus Implementation</Description>
<Copyright>Copyright 2023 Hangzhou Delian Science Technology Co.,Ltd.</Copyright>
<PackageProjectUrl>https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.Modbus.NA200H</PackageProjectUrl>
<PackageProjectUrl>https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.Modbus.SelfDefinedSample</PackageProjectUrl>
<RepositoryUrl>https://github.com/parallelbgls/Modbus.Net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>hardware communicate protocol modbus Delian</PackageTags>

View File

@@ -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.

View File

@@ -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

View File

@@ -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;