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,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>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" />
</ItemGroup>
@@ -35,6 +39,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
<Folder Include="Properties\" />
</ItemGroup>
</Project>

View File

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

View File

@@ -17,7 +17,7 @@ namespace Modbus.Net.Modbus
public ModbusAsciiProtocolLinker(string com, int 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>
@@ -28,7 +28,7 @@ namespace Modbus.Net.Modbus
public override bool? CheckRight(byte[] content)
{
//ProtocolLinker不会返回null
if (!base.CheckRight(content).Value) return false;
if (base.CheckRight(content) != true) return false;
//CRC校验失败
var contentString = Encoding.ASCII.GetString(content);
if (!Crc16.GetInstance().LrcEfficacy(contentString))

View File

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

View File

@@ -16,7 +16,7 @@ namespace Modbus.Net.Modbus
public ModbusRtuProtocolLinker(string com, int 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>
@@ -27,7 +27,7 @@ namespace Modbus.Net.Modbus
public override bool? CheckRight(byte[] content)
{
//ProtocolLinker的CheckRight不会返回null
if (!base.CheckRight(content).Value) return false;
if (base.CheckRight(content) != true) return false;
//CRC校验失败
if (!Crc16.GetInstance().CrcEfficacy(content))
throw new ModbusProtocolErrorException(501);

View File

@@ -34,7 +34,7 @@ namespace Modbus.Net.Modbus
public override bool? CheckRight(byte[] content)
{
//ProtocolLinker的CheckRight不会返回null
if (!base.CheckRight(content).Value) return false;
if (base.CheckRight(content) != true) return false;
//长度校验失败
if (content[5] != content.Length - 6)
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": {}
}
}