2017-12-27 Controller Maintainance and less exception throw

This commit is contained in:
parallelbgls
2017-12-27 16:59:39 +08:00
parent 54f15fc3dc
commit 9b49f5af50
39 changed files with 733 additions and 162 deletions

View File

@@ -0,0 +1,43 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modbus.Net-vs2015", "Modbus.Net\Modbus.Net-vs2015.csproj", "{0C662F94-7362-4D4F-AFD7-76562764893C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modbus.Net.Modbus-vs2015", "Modbus.Net.Modbus\Modbus.Net.Modbus-vs2015.csproj", "{AF2BFCBB-F396-4340-A612-5D0C2477C1B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modbus.Net.Siemens-vs2015", "Modbus.Net.Siemens\Modbus.Net.Siemens-vs2015.csproj", "{53EFB3C6-771E-44D2-9E77-5E70C86D00A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modbus.Net.OPC-vs2015", "Modbus.Net.OPC\Modbus.Net.OPC-vs2015.csproj", "{AD3FF8DE-B9C1-4242-ACC5-4E9400A883B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0C662F94-7362-4D4F-AFD7-76562764893C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C662F94-7362-4D4F-AFD7-76562764893C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C662F94-7362-4D4F-AFD7-76562764893C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C662F94-7362-4D4F-AFD7-76562764893C}.Release|Any CPU.Build.0 = Release|Any CPU
{AF2BFCBB-F396-4340-A612-5D0C2477C1B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF2BFCBB-F396-4340-A612-5D0C2477C1B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF2BFCBB-F396-4340-A612-5D0C2477C1B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF2BFCBB-F396-4340-A612-5D0C2477C1B3}.Release|Any CPU.Build.0 = Release|Any CPU
{53EFB3C6-771E-44D2-9E77-5E70C86D00A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53EFB3C6-771E-44D2-9E77-5E70C86D00A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53EFB3C6-771E-44D2-9E77-5E70C86D00A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{53EFB3C6-771E-44D2-9E77-5E70C86D00A5}.Release|Any CPU.Build.0 = Release|Any CPU
{AD3FF8DE-B9C1-4242-ACC5-4E9400A883B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD3FF8DE-B9C1-4242-ACC5-4E9400A883B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD3FF8DE-B9C1-4242-ACC5-4E9400A883B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD3FF8DE-B9C1-4242-ACC5-4E9400A883B5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {98BE5DC9-7F81-4673-9202-9C334802DAD9}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AF2BFCBB-F396-4340-A612-5D0C2477C1B3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Modbus.Net.Modbus</RootNamespace>
<AssemblyName>Modbus.Net.Modbus</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.5.0\lib\net45\Serilog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddressFormaterModbus.cs" />
<Compile Include="AddressTranslatorModbus.cs" />
<Compile Include="ModbusAsciiInTcpProtocol.cs" />
<Compile Include="ModbusAsciiInTcpProtocolLinker.cs" />
<Compile Include="ModbusAsciiProtocol.cs" />
<Compile Include="ModbusAsciiProtocolLinker.cs" />
<Compile Include="ModbusMachine.cs" />
<Compile Include="ModbusProtocol.cs" />
<Compile Include="ModbusProtocolLinkerBytesExtend.cs" />
<Compile Include="ModbusRtuInTcpProtocol.cs" />
<Compile Include="ModbusRtuInTcpProtocolLinker.cs" />
<Compile Include="ModbusRtuProtocol.cs" />
<Compile Include="ModbusRtuProtocolLinker.cs" />
<Compile Include="ModbusTcpProtocol.cs" />
<Compile Include="ModbusTcpProtocolLinker.cs" />
<Compile Include="ModbusUtility.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modbus.Net\Modbus.Net-vs2015.csproj">
<Project>{0c662f94-7362-4d4f-afd7-76562764893c}</Project>
<Name>Modbus.Net-vs2015</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="project.json" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -26,6 +26,10 @@
<DocumentationFile>bin\Debug\Modbus.Net.Modbus.xml</DocumentationFile> <DocumentationFile>bin\Debug\Modbus.Net.Modbus.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" /> <ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" />
</ItemGroup> </ItemGroup>
@@ -35,6 +39,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.4.0" /> <Folder Include="Properties\" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -36,7 +36,7 @@ namespace Modbus.Net.Modbus
public override bool? CheckRight(byte[] content) public override bool? CheckRight(byte[] content)
{ {
//ProtocolLinker不会返回null //ProtocolLinker不会返回null
if (!base.CheckRight(content).Value) return false; if (base.CheckRight(content) != true) return false;
//CRC校验失败 //CRC校验失败
var contentString = Encoding.ASCII.GetString(content); var contentString = Encoding.ASCII.GetString(content);
if (!Crc16.GetInstance().LrcEfficacy(contentString)) if (!Crc16.GetInstance().LrcEfficacy(contentString))

View File

@@ -17,7 +17,7 @@ namespace Modbus.Net.Modbus
public ModbusAsciiProtocolLinker(string com, int slaveAddress) public ModbusAsciiProtocolLinker(string com, int slaveAddress)
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress) : base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
{ {
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<int>[] { new List<int> { 0, 1 }}, 500)); ((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[] { new List<(int,int)> { (0,0), (1,1) }}, 100));
} }
/// <summary> /// <summary>
@@ -28,7 +28,7 @@ namespace Modbus.Net.Modbus
public override bool? CheckRight(byte[] content) public override bool? CheckRight(byte[] content)
{ {
//ProtocolLinker不会返回null //ProtocolLinker不会返回null
if (!base.CheckRight(content).Value) return false; if (base.CheckRight(content) != true) return false;
//CRC校验失败 //CRC校验失败
var contentString = Encoding.ASCII.GetString(content); var contentString = Encoding.ASCII.GetString(content);
if (!Crc16.GetInstance().LrcEfficacy(contentString)) if (!Crc16.GetInstance().LrcEfficacy(contentString))

View File

@@ -35,7 +35,7 @@ namespace Modbus.Net.Modbus
public override bool? CheckRight(byte[] content) public override bool? CheckRight(byte[] content)
{ {
//ProtocolLinker的CheckRight不会返回null //ProtocolLinker的CheckRight不会返回null
if (!base.CheckRight(content).Value) return false; if (base.CheckRight(content) != true) return false;
//CRC校验失败 //CRC校验失败
if (!Crc16.GetInstance().CrcEfficacy(content)) if (!Crc16.GetInstance().CrcEfficacy(content))
throw new ModbusProtocolErrorException(501); throw new ModbusProtocolErrorException(501);

View File

@@ -16,7 +16,7 @@ namespace Modbus.Net.Modbus
public ModbusRtuProtocolLinker(string com, int slaveAddress) public ModbusRtuProtocolLinker(string com, int slaveAddress)
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress) : base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
{ {
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<int>[]{new List<int>{0}}, 500)); ((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[]{new List<(int,int)>{(0,0), (1,1)}}, 100));
} }
/// <summary> /// <summary>
@@ -27,7 +27,7 @@ namespace Modbus.Net.Modbus
public override bool? CheckRight(byte[] content) public override bool? CheckRight(byte[] content)
{ {
//ProtocolLinker的CheckRight不会返回null //ProtocolLinker的CheckRight不会返回null
if (!base.CheckRight(content).Value) return false; if (base.CheckRight(content) != true) return false;
//CRC校验失败 //CRC校验失败
if (!Crc16.GetInstance().CrcEfficacy(content)) if (!Crc16.GetInstance().CrcEfficacy(content))
throw new ModbusProtocolErrorException(501); throw new ModbusProtocolErrorException(501);

View File

@@ -34,7 +34,7 @@ namespace Modbus.Net.Modbus
public override bool? CheckRight(byte[] content) public override bool? CheckRight(byte[] content)
{ {
//ProtocolLinker的CheckRight不会返回null //ProtocolLinker的CheckRight不会返回null
if (!base.CheckRight(content).Value) return false; if (base.CheckRight(content) != true) return false;
//长度校验失败 //长度校验失败
if (content[5] != content.Length - 6) if (content[5] != content.Length - 6)
throw new ModbusProtocolErrorException(500); throw new ModbusProtocolErrorException(500);

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Modbus.Net.Modbus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Modbus.Net")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("07bcb9ac-a522-4348-8774-2825fd8a6e64")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.1")]
[assembly: AssemblyFileVersion("0.0.0.1")]

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Serilog" version="2.5.0" targetFramework="net45" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
</packages>

View File

@@ -0,0 +1,5 @@
{
"runtimes": {
"win": {}
}
}

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AD3FF8DE-B9C1-4242-ACC5-4E9400A883B5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Modbus.Net.OPC</RootNamespace>
<AssemblyName>Modbus.Net.OPC</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="h-opc, Version=0.9.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\H.Opc.0.9.3\lib\h-opc.dll</HintPath>
</Reference>
<Reference Include="Opc.Ua.Client, Version=1.2.334.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\H.Opc.0.9.3\lib\Opc.Ua.Client.dll</HintPath>
</Reference>
<Reference Include="Opc.Ua.Configuration, Version=1.2.334.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\H.Opc.0.9.3\lib\Opc.Ua.Configuration.dll</HintPath>
</Reference>
<Reference Include="Opc.Ua.Core, Version=1.2.334.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\H.Opc.0.9.3\lib\Opc.Ua.Core.dll</HintPath>
</Reference>
<Reference Include="OpcComRcw, Version=2.0.105.1, Culture=neutral, PublicKeyToken=9a40e993cbface53, processorArchitecture=MSIL">
<HintPath>..\packages\H.Opc.0.9.3\lib\OpcComRcw.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="OpcNetApi, Version=2.1.105.1, Culture=neutral, PublicKeyToken=9a40e993cbface53, processorArchitecture=MSIL">
<HintPath>..\packages\H.Opc.0.9.3\lib\OpcNetApi.dll</HintPath>
</Reference>
<Reference Include="OpcNetApi.Com, Version=2.1.105.1, Culture=neutral, PublicKeyToken=9a40e993cbface53, processorArchitecture=MSIL">
<HintPath>..\packages\H.Opc.0.9.3\lib\OpcNetApi.Com.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.5.0\lib\net45\Serilog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddressFormaterOpc.cs" />
<Compile Include="AddressTranslatorOpc.cs" />
<Compile Include="ClientExtend.cs" />
<Compile Include="OpcConnector.cs" />
<Compile Include="OpcDaConnector.cs" />
<Compile Include="OpcDaMachine.cs" />
<Compile Include="OpcDaProtocol.cs" />
<Compile Include="OpcDaProtocolLinker.cs" />
<Compile Include="OpcDaUtility.cs" />
<Compile Include="OpcMachine.cs" />
<Compile Include="OpcProtocol.cs" />
<Compile Include="OpcProtocolLinker.cs" />
<Compile Include="OpcUaConnector.cs" />
<Compile Include="OpcUaMachine.cs" />
<Compile Include="OpcUaProtocol.cs" />
<Compile Include="OpcUaProtocolLinker.cs" />
<Compile Include="OpcUaUtility.cs" />
<Compile Include="OpcUtility.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modbus.Net\Modbus.Net-vs2015.csproj">
<Project>{0c662f94-7362-4d4f-afd7-76562764893c}</Project>
<Name>Modbus.Net-vs2015</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="project.json" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -26,6 +26,10 @@
<DocumentationFile>bin\Debug\Modbus.Net.OPC.xml</DocumentationFile> <DocumentationFile>bin\Debug\Modbus.Net.OPC.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="H.Opc" Version="0.9.3" /> <PackageReference Include="H.Opc" Version="0.9.3" />
</ItemGroup> </ItemGroup>
@@ -38,4 +42,8 @@
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Modbus.Net.OPC")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Modbus.Net")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("07bcb9ac-a522-4348-8774-2825fd8a6e64")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.1")]
[assembly: AssemblyFileVersion("0.0.0.1")]

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="H.Opc" version="0.9.3" targetFramework="net45" />
<package id="Serilog" version="2.5.0" targetFramework="net45" />
</packages>

View File

@@ -0,0 +1,5 @@
{
"runtimes": {
"win": {}
}
}

View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{53EFB3C6-771E-44D2-9E77-5E70C86D00A5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Modbus.Net.Siemens</RootNamespace>
<AssemblyName>Modbus.Net.Siemens</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.5.0\lib\net45\Serilog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddressFormaterSiemens.cs" />
<Compile Include="AddressTranslatorSiemens.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SiemensMachine.cs" />
<Compile Include="SiemensPpiProtocol.cs" />
<Compile Include="SiemensPpiProtocolLinker.cs" />
<Compile Include="SiemensProtocol.cs" />
<Compile Include="SiemensProtocolLinkerBytesExtend.cs" />
<Compile Include="SiemensStructDefinition.cs" />
<Compile Include="SiemensTcpProtocol.cs" />
<Compile Include="SiemensTcpProtocolLinker.cs" />
<Compile Include="SiemensUtility.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modbus.Net\Modbus.Net-vs2015.csproj">
<Project>{0c662f94-7362-4d4f-afd7-76562764893c}</Project>
<Name>Modbus.Net-vs2015</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="project.json" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -25,6 +25,10 @@
<DocumentationFile>bin\Debug\Modbus.Net.Siemens.xml</DocumentationFile> <DocumentationFile>bin\Debug\Modbus.Net.Siemens.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" /> <ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" />
</ItemGroup> </ItemGroup>
@@ -33,4 +37,8 @@
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Modbus.Net.Siemens")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Modbus.Net")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("07bcb9ac-a522-4348-8774-2825fd8a6e64")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.1")]
[assembly: AssemblyFileVersion("0.0.0.1")]

View File

@@ -18,7 +18,7 @@ namespace Modbus.Net.Siemens
public SiemensPpiProtocolLinker(string com, int slaveAddress) public SiemensPpiProtocolLinker(string com, int slaveAddress)
: base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress) : base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress)
{ {
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<int>[] { new List<int> { 5 }, new List<int> { 6 }, new List<int> { 11, 12 } }, 500)); ((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[] { new List<(int,int)> { (4,5) }, new List<(int,int)> {(5,4) }, new List<(int,int)> { (11 ,11), (12,12) } }, 100));
} }
/// <summary> /// <summary>
@@ -84,7 +84,7 @@ namespace Modbus.Net.Siemens
/// <returns>报文是否正确</returns> /// <returns>报文是否正确</returns>
public override bool? CheckRight(byte[] content) public override bool? CheckRight(byte[] content)
{ {
if (!base.CheckRight(content).Value) return false; if (base.CheckRight(content) != true) return false;
var fcsCheck = 0; var fcsCheck = 0;
if (content.Length == 1 && content[0] == 0xe5) if (content.Length == 1 && content[0] == 0xe5)
return true; return true;

View File

@@ -26,7 +26,7 @@ namespace Modbus.Net.Siemens
public SiemensTcpProtocolLinker(string ip, int port) public SiemensTcpProtocolLinker(string ip, int port)
: base(ip, port) : base(ip, port)
{ {
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<int>[] { new List<int> { 11, 12 } }, 500)); ((BaseConnector)BaseConnector).AddController(new MatchDirectlySendController(new ICollection<(int,int)>[] { new List<(int,int)> { (11,11), (12,12) } }, 500));
} }
/// <summary> /// <summary>
@@ -36,7 +36,7 @@ namespace Modbus.Net.Siemens
/// <returns>报文是否正确</returns> /// <returns>报文是否正确</returns>
public override bool? CheckRight(byte[] content) public override bool? CheckRight(byte[] content)
{ {
if (!base.CheckRight(content).Value) return false; if (base.CheckRight(content) != true) return false;
switch (content[5]) switch (content[5])
{ {
case 0xd0: case 0xd0:

View File

@@ -67,7 +67,7 @@ namespace Modbus.Net.Siemens
private readonly ushort _tsapDst; private readonly ushort _tsapDst;
private ushort _sendCount; private ushort _sendCount;
private object _counterLock = new object(); private readonly object _counterLock = new object();
private SiemensType _siemensType; private SiemensType _siemensType;

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Serilog" version="2.5.0" targetFramework="net45" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
</packages>

View File

@@ -0,0 +1,5 @@
{
"runtimes": {
"win": {}
}
}

View File

@@ -39,7 +39,8 @@ namespace Modbus.Net
public override async Task<byte[]> SendMsgAsync(byte[] message) public override async Task<byte[]> SendMsgAsync(byte[] message)
{ {
var ans = await SendMsgCtrl(message); var ans = await SendMsgCtrl(message);
return ans?.ReceiveMessage; if (ans == null) return new byte[0];
return ans.ReceiveMessage;
} }
/// <summary> /// <summary>

View File

@@ -34,7 +34,7 @@ namespace Modbus.Net
{ {
var def = new MessageWaitingDef var def = new MessageWaitingDef
{ {
Key = GetKeyFromMessage(sendMessage), Key = GetKeyFromMessage(sendMessage)?.Item1,
SendMessage = sendMessage, SendMessage = sendMessage,
SendMutex = new AutoResetEvent(false), SendMutex = new AutoResetEvent(false),
ReceiveMutex = new AutoResetEvent(false) ReceiveMutex = new AutoResetEvent(false)
@@ -94,7 +94,7 @@ namespace Modbus.Net
/// </summary> /// </summary>
/// <param name="message">待确认的信息</param> /// <param name="message">待确认的信息</param>
/// <returns>信息的检索关键字</returns> /// <returns>信息的检索关键字</returns>
protected abstract string GetKeyFromMessage(byte[] message); protected abstract (string,string)? GetKeyFromMessage(byte[] message);
/// <inheritdoc /> /// <inheritdoc />
public bool ConfirmMessage(byte[] receiveMessage) public bool ConfirmMessage(byte[] receiveMessage)

View File

@@ -114,10 +114,8 @@ namespace Modbus.Net
else else
{ {
//自动寻找存在的协议并将其加载 //自动寻找存在的协议并将其加载
var protocalUnit = if (!(Activator.CreateInstance(type.GetTypeInfo().Assembly
Activator.CreateInstance(type.GetTypeInfo().Assembly .GetType(protocalName)) is TProtocolUnit protocalUnit))
.GetType(protocalName)) as TProtocolUnit;
if (protocalUnit == null)
throw new InvalidCastException($"No ProtocolUnit {nameof(TProtocolUnit)} implemented"); throw new InvalidCastException($"No ProtocolUnit {nameof(TProtocolUnit)} implemented");
protocalUnit.Endian = Endian; protocalUnit.Endian = Endian;
Register(protocalUnit); Register(protocalUnit);

View File

@@ -92,7 +92,7 @@ namespace Modbus.Net
} }
/// <inheritdoc /> /// <inheritdoc />
protected override string GetKeyFromMessage(byte[] message) protected override (string,string)? GetKeyFromMessage(byte[] message)
{ {
return null; return null;
} }

View File

@@ -11,114 +11,47 @@ namespace Modbus.Net
/// <summary> /// <summary>
/// 通讯号匹配模式的控制器 /// 通讯号匹配模式的控制器
/// </summary> /// </summary>
public class MatchController : BaseController public class MatchController : FifoController
{ {
private MessageWaitingDef _currentSendingPos;
private bool _taskCancel = false;
/// <summary>
/// 获取间隔
/// </summary>
public int AcquireTime { get; }
/// <summary> /// <summary>
/// 匹配字典 /// 匹配字典
/// </summary> /// </summary>
protected ICollection<int>[] KeyMatches { get; } protected ICollection<(int,int)>[] KeyMatches { get; }
/// <summary> /// <summary>
/// 构造器 /// 构造器
/// </summary> /// </summary>
/// <param name="keyMatches">匹配字典每个Collection代表一个匹配集合每一个匹配集合中的数字代表需要匹配的位置最后计算出来的数字是所有位置数字按照集合排序后叠放在一起</param> /// <param name="keyMatches">匹配字典每个Collection代表一个匹配集合每一个匹配集合中的数字代表需要匹配的位置最后计算出来的数字是所有位置数字按照集合排序后叠放在一起</param>
/// <param name="acquireTime">获取间隔</param> /// <param name="acquireTime">获取间隔</param>
public MatchController(ICollection<int>[] keyMatches, int acquireTime) public MatchController(ICollection<(int,int)>[] keyMatches, int acquireTime) : base(acquireTime)
{ {
KeyMatches = keyMatches; KeyMatches = keyMatches;
AcquireTime = acquireTime;
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void SendingMessageControlInner() protected override (string,string)? GetKeyFromMessage(byte[] message)
{ {
try string ans1 = "";
{ string ans2 = "";
while (!_taskCancel)
{
if (AcquireTime > 0)
{
Thread.Sleep(AcquireTime);
}
lock (WaitingMessages)
{
if (_currentSendingPos == null)
{
if (WaitingMessages.Count > 0)
{
_currentSendingPos = WaitingMessages.First();
_currentSendingPos.SendMutex.Set();
}
}
if (_currentSendingPos != null)
{
if (WaitingMessages.Count <= 0)
{
_currentSendingPos = null;
}
if (WaitingMessages.Count > WaitingMessages.IndexOf(_currentSendingPos) + 1)
{
_currentSendingPos = WaitingMessages[WaitingMessages.IndexOf(_currentSendingPos) + 1];
_currentSendingPos.SendMutex.Set();
}
}
}
}
}
catch (ObjectDisposedException)
{
//ignore
}
catch (Exception e)
{
Log.Error(e, "Controller throws exception");
}
}
/// <inheritdoc />
public override void SendStart()
{
_taskCancel = false;
base.SendStart();
}
/// <inheritdoc />
public override void SendStop()
{
_taskCancel = false;
}
/// <inheritdoc />
protected override string GetKeyFromMessage(byte[] message)
{
string ans = "";
foreach (var matchPoses in KeyMatches) foreach (var matchPoses in KeyMatches)
{ {
int tmpCount = 0; int tmpCount = 0, tmpCount2 = 0;
foreach (var matchPos in matchPoses) foreach (var matchPos in matchPoses)
{ {
tmpCount = tmpCount * 256 + message[matchPos]; tmpCount = tmpCount * 256 + message[matchPos.Item1];
tmpCount2 = tmpCount2 * 256 + message[matchPos.Item2];
} }
ans += tmpCount + " "; ans1 += tmpCount + " ";
ans2 += tmpCount2 + " ";
} }
return ans; return (ans1, ans2);
} }
/// <inheritdoc /> /// <inheritdoc />
protected override MessageWaitingDef GetMessageFromWaitingList(byte[] receiveMessage) protected override MessageWaitingDef GetMessageFromWaitingList(byte[] receiveMessage)
{ {
var returnKey = GetKeyFromMessage(receiveMessage); var returnKey = GetKeyFromMessage(receiveMessage);
return WaitingMessages.FirstOrDefault(p=>p.Key == returnKey); return WaitingMessages.FirstOrDefault(p=>returnKey.HasValue && p.Key == returnKey.Value.Item2);
} }
} }
} }

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Modbus.Net
{
/// <summary>
/// 匹配控制器,载入队列后直接发送
/// </summary>
public class MatchDirectlySendController : MatchController
{
/// <inheritdoc />
public MatchDirectlySendController(ICollection<(int, int)>[] keyMatches, int acquireTime) : base(keyMatches,
acquireTime)
{
}
/// <inheritdoc />
protected override bool AddMessageToList(MessageWaitingDef def)
{
var ans = base.AddMessageToList(def);
if (ans)
{
def.SendMutex.Set();
}
return ans;
}
/// <inheritdoc />
protected override void SendingMessageControlInner()
{
//empty
}
}
}

View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0C662F94-7362-4D4F-AFD7-76562764893C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Modbus.Net</RootNamespace>
<AssemblyName>Modbus.Net</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Nito.AsyncEx, Version=4.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nito.AsyncEx.4.0.1\lib\net45\Nito.AsyncEx.dll</HintPath>
</Reference>
<Reference Include="Nito.AsyncEx.Concurrent, Version=4.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nito.AsyncEx.4.0.1\lib\net45\Nito.AsyncEx.Concurrent.dll</HintPath>
</Reference>
<Reference Include="Nito.AsyncEx.Enlightenment, Version=4.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nito.AsyncEx.4.0.1\lib\net45\Nito.AsyncEx.Enlightenment.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.6.0\lib\net45\Serilog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddressCombiner.cs" />
<Compile Include="AddressFormater.cs" />
<Compile Include="AddressHelper.cs" />
<Compile Include="AddressTranslator.cs" />
<Compile Include="AsyncHelper.cs" />
<Compile Include="BaseConnector.cs" />
<Compile Include="BaseController.cs" />
<Compile Include="BaseMachine.cs" />
<Compile Include="BaseMachineExtend.cs" />
<Compile Include="BaseProtocol.cs" />
<Compile Include="BaseUtility.cs" />
<Compile Include="ComConnector.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ComProtocalLinker.cs" />
<Compile Include="CRC16.cs" />
<Compile Include="FifoController.cs" />
<Compile Include="IConnector.cs" />
<Compile Include="IController.cs" />
<Compile Include="IMachineMethod.cs" />
<Compile Include="IProtocol.cs" />
<Compile Include="IProtocolFormatting.cs" />
<Compile Include="IProtocolLinker.cs" />
<Compile Include="IProtocolLinkerBytesExtend.cs" />
<Compile Include="IUtilityMethod.cs" />
<Compile Include="MatchController.cs" />
<Compile Include="MatchDirectlySendController.cs" />
<Compile Include="PipeUnit.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProtocalLinker.cs" />
<Compile Include="ProtocalUnit.cs" />
<Compile Include="SerialPortHelper.cs" />
<Compile Include="TaskManager.cs" />
<Compile Include="TcpConnector.cs" />
<Compile Include="TcpProtocalLinker.cs" />
<Compile Include="TypeExtensions.cs" />
<Compile Include="ValueHelper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
</Project>

View File

@@ -26,8 +26,13 @@
<DocumentationFile>bin\Debug\Modbus.Net.xml</DocumentationFile> <DocumentationFile>bin\Debug\Modbus.Net.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Serilog" Version="2.5.0" /> <PackageReference Include="Serilog" Version="2.5.0" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45' "> <ItemGroup Condition="'$(TargetFramework)' == 'net45' ">
@@ -47,4 +52,8 @@
<PackageReference Include="System.IO.Ports" Version="4.4.0" /> <PackageReference Include="System.IO.Ports" Version="4.4.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Modbus.Net")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Modbus.Net")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("07bcb9ac-a522-4348-8774-2825fd8a6e64")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.1")]
[assembly: AssemblyFileVersion("0.0.0.1")]

View File

@@ -65,6 +65,17 @@ namespace Modbus.Net
IProtocolLinkerBytesExtend; IProtocolLinkerBytesExtend;
return bytesExtend?.BytesDecact(content); return bytesExtend?.BytesDecact(content);
} }
public override bool? CheckRight(byte[] content)
{
if (content == null)
{
Disconnect();
return false;
}
if (content.Length == 0) return null;
return true;
}
} }
/// <summary> /// <summary>

View File

@@ -52,9 +52,13 @@ namespace Modbus.Net
/// <typeparam name="T">IOutputStruct的具体类型</typeparam> /// <typeparam name="T">IOutputStruct的具体类型</typeparam>
/// <returns>结构化的输出数据</returns> /// <returns>结构化的输出数据</returns>
public T Unformat<T>(TParamOut messageBytes, ref int pos) where T : class, IOutputStruct public T Unformat<T>(TParamOut messageBytes, ref int pos) where T : class, IOutputStruct
{
if (messageBytes != null)
{ {
return Unformat(messageBytes, ref pos) as T; return Unformat(messageBytes, ref pos) as T;
} }
return null;
}
/// <summary> /// <summary>
/// 转换静态方法,把对象数组转换为字节数组。 /// 转换静态方法,把对象数组转换为字节数组。

3
Modbus.Net/Modbus.Net/package-lock.json generated Normal file
View File

@@ -0,0 +1,3 @@
{
"lockfileVersion": 1
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net45" />
<package id="Nito.AsyncEx" version="4.0.1" targetFramework="net45" />
<package id="Serilog" version="2.6.0" targetFramework="net45" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
</packages>

View File

@@ -0,0 +1,5 @@
{
"runtimes": {
"win": {}
}
}

View File

@@ -12,7 +12,7 @@ namespace Modbus.Net.PersistedTests
{ {
Log.Logger = new LoggerConfiguration().MinimumLevel.Verbose().WriteTo.Console().CreateLogger(); Log.Logger = new LoggerConfiguration().MinimumLevel.Verbose().WriteTo.Console().CreateLogger();
IMachineProperty<int> machine = new ModbusMachine<int, string>(1, ModbusType.Rtu, "COM1", IMachineProperty<int> machine = new ModbusMachine<int, string>(1, ModbusType.Ascii, "COM5",
new List<AddressUnit>() new List<AddressUnit>()
{ {
new AddressUnit() new AddressUnit()
@@ -40,65 +40,9 @@ namespace Modbus.Net.PersistedTests
DataType = typeof(ushort) DataType = typeof(ushort)
}, },
}, true, 2, 1); }, true, 2, 1);
IMachineProperty<int> machine2 = new ModbusMachine<int, string>(2, ModbusType.Rtu, "COM1",
new List<AddressUnit>()
{
new AddressUnit()
{
Id = "1",
Area = "4X",
Address = 11,
Name = "test 1",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "2",
Area = "4X",
Address = 12,
Name = "test 2",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "3",
Area = "4X",
Address = 13,
Name = "test 3",
DataType = typeof(ushort)
},
}, true, 3, 1);
IMachineProperty<int> machine3 = new ModbusMachine<int, string>(3, ModbusType.Rtu, "COM1",
new List<AddressUnit>()
{
new AddressUnit()
{
Id = "1",
Area = "4X",
Address = 21,
Name = "test 1",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "2",
Area = "4X",
Address = 22,
Name = "test 2",
DataType = typeof(ushort)
},
new AddressUnit()
{
Id = "3",
Area = "4X",
Address = 23,
Name = "test 3",
DataType = typeof(ushort)
},
}, true, 4, 1);
TaskManager<int> manager = new TaskManager<int>(20, true); TaskManager<int> manager = new TaskManager<int>(20, true);
manager.AddMachines<string>(new List<IMachineProperty<int>>{machine, machine2, machine3}); manager.AddMachines<string>(new List<IMachineProperty<int>>{machine});
Random r = new Random(); Random r = new Random();
manager.InvokeTimerForMachine(1, new TaskItemSetData(() => new Dictionary<string, double> manager.InvokeTimerForMachine(1, new TaskItemSetData(() => new Dictionary<string, double>
{ {