2017-12-21 Update 1 Serial Port Single Station
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="COM" value="COM1" />
|
||||
<add key="FBoxOpcDaHost" value="opcda://localhost/FBoxOpcServer" />
|
||||
<add key="IP" value="192.168.1.1" />
|
||||
<add key="ComConnectionTimeout" value="3000" />
|
||||
<add key="IPConnectionTimeout" value="5000" />
|
||||
<add key="ModbusPort" value="502" />
|
||||
<add key="OpcDaHost" value="opcda://localhost/..." />
|
||||
<add key="OpcUaHost" value="opc.tcp://localhost/..." />
|
||||
<add key="SiemensPort" value="102" />
|
||||
</appSettings>
|
||||
</configuration>
|
||||
@@ -1,72 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Modbus.Net.Core</AssemblyName>
|
||||
<RootNamespace>Modbus.Net</RootNamespace>
|
||||
<PackageId>Modbus.Net.Core</PackageId>
|
||||
<Version>1.4.1</Version>
|
||||
<Product>Modbus.Net</Product>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
<PackageLicenseUrl>https://github.com/parallelbgls/Modbus.Net/blob/master/LICENSE.md</PackageLicenseUrl>
|
||||
<PackageProjectUrl>https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/parallelbgls/Modbus.Net/</RepositoryUrl>
|
||||
<Description>High extensible hardware communication implementation platform.</Description>
|
||||
<Copyright>Copyright 2017 Hangzhou Delian IoT Science Technology Co.,Ltd.</Copyright>
|
||||
<PackageTags>hardware communicate protocal Delian</PackageTags>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>bin\Debug\netstandard2.0\Modbus.Net.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\src\Base.Common\AddressCombiner.cs" Link="AddressCombiner.cs" />
|
||||
<Compile Include="..\src\Base.Common\AddressFormater.cs" Link="AddressFormater.cs" />
|
||||
<Compile Include="..\src\Base.Common\AddressHelper.cs" Link="AddressHelper.cs" />
|
||||
<Compile Include="..\src\Base.Common\AddressTranslator.cs" Link="AddressTranslator.cs" />
|
||||
<Compile Include="..\src\Base.Common\AsyncHelper.cs" Link="AsyncHelper.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseConnector.cs" Link="BaseConnector.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseMachine.cs" Link="BaseMachine.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseMachineExtend.cs" Link="BaseMachineExtend.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseProtocal.cs" Link="BaseProtocal.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseUtility.cs" Link="BaseUtility.cs" />
|
||||
<Compile Include="..\src\Base.Common\CRC16.cs" Link="CRC16.cs" />
|
||||
<Compile Include="..\src\Base.Common\IProtocal.cs" Link="IProtocal.cs" />
|
||||
<Compile Include="..\src\Base.Common\IProtocalFormatting.cs" Link="IProtocalFormatting.cs" />
|
||||
<Compile Include="..\src\Base.Common\IProtocalLinker.cs" Link="IProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\IProtocalLinkerBytesExtend.cs" Link="IProtocalLinkerBytesExtend.cs" />
|
||||
<Compile Include="..\src\Base.Common\ProtocalLinker.cs" Link="ProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\ProtocalUnit.cs" Link="ProtocalUnit.cs" />
|
||||
<Compile Include="..\src\Base.Common\TaskManager.cs" Link="TaskManager.cs" />
|
||||
<Compile Include="..\src\Base.Common\TcpConnector.cs" Link="TcpConnector.cs" />
|
||||
<Compile Include="..\src\Base.Common\TcpProtocalLinker.cs" Link="TcpProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\ValueHelper.cs" Link="ValueHelper.cs" />
|
||||
<Compile Include="..\src\Base.Common\IUtilityMethod.cs" Link="IUtilityMethod.cs" />
|
||||
<Compile Include="..\src\Base.Common\IMachineMethod.cs" Link="IMachineMethod.cs" />
|
||||
<Compile Include="..\src\Base.Common\IConnector.cs" Link="IConnector.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Base.Common\ComProtocalLinker.cs" Link="ComProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\ComConnector.cs" Link="ComConnector.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Base.Common\PipeUnit.cs" Link="PipeUnit.cs" />
|
||||
<Compile Include="..\src\Base.Common\IController.cs" Link="IController.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseController.cs" Link="BaseController.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Nito.AsyncEx.Tasks" Version="1.1.0" />
|
||||
<PackageReference Include="Serilog" Version="2.5.0" />
|
||||
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />
|
||||
<PackageReference Include="System.Threading.ThreadPool" Version="4.3.0" />
|
||||
<PackageReference Include="System.IO.Ports" Version="4.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,59 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Modbus.Net.Modbus.Core</AssemblyName>
|
||||
<RootNamespace>Modbus.Net.Modbus</RootNamespace>
|
||||
<PackageId>Modbus.Net.Modbus.Core</PackageId>
|
||||
<Version>1.4.1</Version>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
<Product>Modbus.Net.Modbus</Product>
|
||||
<Description>Modbus.Net Modbus Implementation</Description>
|
||||
<Copyright>Copyright 2017 Hangzhou Delian IoT Science Technology Co.,Ltd.</Copyright>
|
||||
<PackageLicenseUrl>https://github.com/parallelbgls/Modbus.Net/blob/master/LICENSE.md</PackageLicenseUrl>
|
||||
<PackageProjectUrl>https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.Modbus</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/parallelbgls/Modbus.Net</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>hardware communicate protocal modbus Delian</PackageTags>
|
||||
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>bin\Debug\netstandard2.0\Modbus.Net.Modbus.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\src\Modbus.Common\AddressFormaterModbus.cs" Link="AddressFormaterModbus.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\AddressTranslatorModbus.cs" Link="AddressTranslatorModbus.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiProtocal.cs" Link="ModbusAsciiProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiProtocalLinker.cs" Link="ModbusAsciiProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiInTcpProtocal.cs" Link="ModbusAsciiInTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiInTcpProtocalLinker.cs" Link="ModbusAsciiInTcpProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Modbus.Common\ModbusMachine.cs" Link="ModbusMachine.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusProtocal.cs" Link="ModbusProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusProtocalLinkerBytesExtend.cs" Link="ModbusProtocalLinkerBytesExtend.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuProtocal.cs" Link="ModbusRtuProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuProtocalLinker.cs" Link="ModbusRtuProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuInTcpProtocal.cs" Link="ModbusRtuInTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuInTcpProtocalLinker.cs" Link="ModbusRtuInTcpProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Modbus.Common\ModbusTcpProtocal.cs" Link="ModbusTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusTcpProtocalLinker.cs" Link="ModbusTcpProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusUtility.cs" Link="ModbusUtility.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Modbus.Net.Core\Modbus.Net.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net45</TargetFramework>
|
||||
<TargetFrameworks>net45;netstandard20</TargetFrameworks>
|
||||
<AssemblyName>Modbus.Net.Modbus</AssemblyName>
|
||||
<RootNamespace>Modbus.Net.Modbus</RootNamespace>
|
||||
<PackageId>Modbus.Net.Modbus</PackageId>
|
||||
@@ -30,30 +30,7 @@
|
||||
<ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\src\Modbus.Common\AddressFormaterModbus.cs" Link="AddressFormaterModbus.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\AddressTranslatorModbus.cs" Link="AddressTranslatorModbus.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiProtocal.cs" Link="ModbusAsciiProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiProtocalLinker.cs" Link="ModbusAsciiProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiInTcpProtocal.cs" Link="ModbusAsciiInTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusAsciiInTcpProtocalLinker.cs" Link="ModbusAsciiInTcpProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Modbus.Common\ModbusMachine.cs" Link="ModbusMachine.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusProtocal.cs" Link="ModbusProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusProtocalLinkerBytesExtend.cs" Link="ModbusProtocalLinkerBytesExtend.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuProtocal.cs" Link="ModbusRtuProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuProtocalLinker.cs" Link="ModbusRtuProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuInTcpProtocal.cs" Link="ModbusRtuInTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusRtuInTcpProtocalLinker.cs" Link="ModbusRtuInTcpProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Modbus.Common\ModbusTcpProtocal.cs" Link="ModbusTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusTcpProtocalLinker.cs" Link="ModbusTcpProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Modbus.Common\ModbusUtility.cs" Link="ModbusUtility.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net45' ">
|
||||
<Reference Include="System.Configuration" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusAsciiInTcpProtocalLinker(string ip, int port)
|
||||
: base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FIFOController(500));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -16,6 +16,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusAsciiProtocalLinker(string com, int slaveAddress)
|
||||
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FIFOController(500));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -24,6 +24,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusRtuInTcpProtocalLinker(string ip, int port)
|
||||
: base(ip, port)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FIFOController(500));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -15,6 +15,7 @@ namespace Modbus.Net.Modbus
|
||||
public ModbusRtuProtocalLinker(string com, int slaveAddress)
|
||||
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FIFOController(500));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -142,13 +142,13 @@ namespace Modbus.Net.Modbus
|
||||
switch (_modbusType)
|
||||
{
|
||||
//Rtu协议
|
||||
/*case ModbusType.Rtu:
|
||||
case ModbusType.Rtu:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
? new ModbusRtuProtocal(SlaveAddress, MasterAddress, Endian)
|
||||
: new ModbusRtuProtocal(ConnectionString, SlaveAddress, MasterAddress, Endian);
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
//Tcp协议
|
||||
case ModbusType.Tcp:
|
||||
{
|
||||
@@ -160,8 +160,7 @@ namespace Modbus.Net.Modbus
|
||||
MasterAddress, Endian));
|
||||
break;
|
||||
}
|
||||
//Ascii协议
|
||||
/*
|
||||
//Ascii协议
|
||||
case ModbusType.Ascii:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
@@ -191,7 +190,6 @@ namespace Modbus.Net.Modbus
|
||||
MasterAddress, Endian));
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>Modbus.Net.Siemens.Core</AssemblyName>
|
||||
<RootNamespace>Modbus.Net.Siemens</RootNamespace>
|
||||
<PackageId>Modbus.Net.Siemens.Core</PackageId>
|
||||
<Version>1.4.1</Version>
|
||||
<Authors>Chris L.(Luo Sheng)</Authors>
|
||||
<Company>Hangzhou Delian IoT Science Technology Co.,Ltd.</Company>
|
||||
<Description>Modbus.Net Siemens Profinet Implementation</Description>
|
||||
<Copyright>Copyright 2017 Hangzhou Delian IoT Science Technology Co.,Ltd.</Copyright>
|
||||
<PackageLicenseUrl>https://github.com/parallelbgls/Modbus.Net/blob/master/LICENSE.md</PackageLicenseUrl>
|
||||
<PackageProjectUrl>https://github.com/parallelbgls/Modbus.Net/tree/master/Modbus.Net/Modbus.Net.Siemens</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/parallelbgls/Modbus.Net</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>hardware communicate protocal Siemens profinet Delian</PackageTags>
|
||||
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>bin\Debug\netstandard2.0\Modbus.Net.Siemens.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\src\Siemens.Common\AddressFormaterSiemens.cs" Link="AddressFormaterSiemens.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\AddressTranslatorSiemens.cs" Link="AddressTranslatorSiemens.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensMachine.cs" Link="SiemensMachine.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Siemens.Common\SiemensPpiProtocal.cs" Link="SiemensPpiProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensPpiProtocalLinker.cs" Link="SiemensPpiProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Siemens.Common\SiemensProtocal.cs" Link="SiemensProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensProtocalLinkerBytesExtend.cs" Link="SiemensProtocalLinkerBytesExtend.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensTcpProtocal.cs" Link="SiemensTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensTcpProtocalLinker.cs" Link="SiemensTcpProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensUtility.cs" Link="SiemensUtility.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.IO.Ports" Version="4.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Modbus.Net.Core\Modbus.Net.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net45</TargetFramework>
|
||||
<TargetFrameworks>net45;netstandard20</TargetFrameworks>
|
||||
<AssemblyName>Modbus.Net.Siemens</AssemblyName>
|
||||
<RootNamespace>Modbus.Net.Siemens</RootNamespace>
|
||||
<PackageId>Modbus.Net.Siemens</PackageId>
|
||||
@@ -25,26 +25,11 @@
|
||||
<DocumentationFile>bin\Debug\net45\Modbus.Net.Siemens.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\src\Siemens.Common\AddressFormaterSiemens.cs" Link="AddressFormaterSiemens.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\AddressTranslatorSiemens.cs" Link="AddressTranslatorSiemens.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensMachine.cs" Link="SiemensMachine.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Siemens.Common\SiemensPpiProtocal.cs" Link="SiemensPpiProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensPpiProtocalLinker.cs" Link="SiemensPpiProtocalLinker.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Siemens.Common\SiemensProtocal.cs" Link="SiemensProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensProtocalLinkerBytesExtend.cs" Link="SiemensProtocalLinkerBytesExtend.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensTcpProtocal.cs" Link="SiemensTcpProtocal.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensTcpProtocalLinker.cs" Link="SiemensTcpProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Siemens.Common\SiemensUtility.cs" Link="SiemensUtility.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Modbus.Net\Modbus.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net45' ">
|
||||
<Reference Include="System.Configuration" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -65,15 +65,6 @@ namespace Modbus.Net.Siemens
|
||||
return await base.SendReceiveAsync(unit, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public override bool Connect()
|
||||
{
|
||||
return AsyncHelper.RunSync(ConnectAsync);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接设备
|
||||
/// </summary>
|
||||
@@ -17,6 +17,7 @@ namespace Modbus.Net.Siemens
|
||||
public SiemensPpiProtocalLinker(string com, int slaveAddress)
|
||||
: base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new FIFOController(500));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -183,8 +183,7 @@ namespace Modbus.Net.Siemens
|
||||
_siemensType = value;
|
||||
switch (_siemensType)
|
||||
{
|
||||
//PPI
|
||||
/*
|
||||
//PPI
|
||||
case SiemensType.Ppi:
|
||||
{
|
||||
Wrapper = ConnectionString == null
|
||||
@@ -196,8 +195,7 @@ namespace Modbus.Net.Siemens
|
||||
case SiemensType.Mpi:
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
*/
|
||||
}
|
||||
//Ethenet
|
||||
case SiemensType.Tcp:
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.16
|
||||
VisualStudioVersion = 15.0.27130.2010
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net", "Modbus.Net\Modbus.Net.csproj", "{124EBEF2-8960-4447-84CF-1D683B1EF7CC}"
|
||||
EndProject
|
||||
@@ -30,12 +30,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrossLamp", "..\Samples\Cro
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnyType", "..\Samples\AnyType\AnyType.csproj", "{25FABD48-D82E-4E08-91A4-46F7057EC954}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modbus.Net.Core", "Modbus.Net.Core\Modbus.Net.Core.csproj", "{BBC091FC-A995-4C06-96F1-F91ECD70FA7E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modbus.Net.Modbus.Core", "Modbus.Net.Modbus.Core\Modbus.Net.Modbus.Core.csproj", "{71BF9248-B261-4C93-A039-FFA4D55A4A26}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modbus.Net.Siemens.Core", "Modbus.Net.Siemens.Core\Modbus.Net.Siemens.Core.csproj", "{84071437-A569-4AAE-BA44-732138AC010E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -78,18 +72,6 @@ Global
|
||||
{25FABD48-D82E-4E08-91A4-46F7057EC954}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{25FABD48-D82E-4E08-91A4-46F7057EC954}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{25FABD48-D82E-4E08-91A4-46F7057EC954}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BBC091FC-A995-4C06-96F1-F91ECD70FA7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BBC091FC-A995-4C06-96F1-F91ECD70FA7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BBC091FC-A995-4C06-96F1-F91ECD70FA7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BBC091FC-A995-4C06-96F1-F91ECD70FA7E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{71BF9248-B261-4C93-A039-FFA4D55A4A26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{71BF9248-B261-4C93-A039-FFA4D55A4A26}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{71BF9248-B261-4C93-A039-FFA4D55A4A26}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{71BF9248-B261-4C93-A039-FFA4D55A4A26}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{84071437-A569-4AAE-BA44-732138AC010E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{84071437-A569-4AAE-BA44-732138AC010E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{84071437-A569-4AAE-BA44-732138AC010E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{84071437-A569-4AAE-BA44-732138AC010E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Modbus.Net
|
||||
{
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Nito.AsyncEx;
|
||||
using Serilog;
|
||||
|
||||
namespace Modbus.Net
|
||||
@@ -18,7 +19,7 @@ namespace Modbus.Net
|
||||
/// <summary>
|
||||
/// 发送锁
|
||||
/// </summary>
|
||||
public object Lock { get; set; } = new object();
|
||||
public AsyncLock Lock { get; set; } = new AsyncLock();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -66,6 +67,9 @@ namespace Modbus.Net
|
||||
|
||||
private int _sendCount;
|
||||
|
||||
private Task _receiveThread;
|
||||
private bool _taskCancel = false;
|
||||
|
||||
/// <summary>
|
||||
/// Dispose是否执行
|
||||
/// </summary>
|
||||
@@ -200,69 +204,6 @@ namespace Modbus.Net
|
||||
return nBytelen;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 字符数组转字符串16进制
|
||||
/// </summary>
|
||||
/// <param name="inBytes"> 二进制字节 </param>
|
||||
/// <returns>类似"01 02 0F" </returns>
|
||||
public static string ByteToString(byte[] inBytes)
|
||||
{
|
||||
var stringOut = "";
|
||||
foreach (var inByte in inBytes)
|
||||
stringOut = stringOut + $"{inByte:X2}" + " ";
|
||||
|
||||
return stringOut.Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// strhex 转字节数组
|
||||
/// </summary>
|
||||
/// <param name="inString">类似"01 02 0F" 用空格分开的 </param>
|
||||
/// <returns> </returns>
|
||||
public static byte[] StringToByte(string inString)
|
||||
{
|
||||
var byteStrings = inString.Split(" ".ToCharArray());
|
||||
var byteOut = new byte[byteStrings.Length];
|
||||
for (var i = 0; i <= byteStrings.Length - 1; i++)
|
||||
byteOut[i] = byte.Parse(byteStrings[i], NumberStyles.HexNumber);
|
||||
return byteOut;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// strhex 转字节数组
|
||||
/// </summary>
|
||||
/// <param name="inString">类似"01 02 0F" 中间无空格 </param>
|
||||
/// <returns> </returns>
|
||||
public static byte[] StringToByte_2(string inString)
|
||||
{
|
||||
inString = inString.Replace(" ", "");
|
||||
|
||||
var byteStrings = new string[inString.Length / 2];
|
||||
var j = 0;
|
||||
for (var i = 0; i < byteStrings.Length; i++)
|
||||
{
|
||||
byteStrings[i] = inString.Substring(j, 2);
|
||||
j += 2;
|
||||
}
|
||||
|
||||
var byteOut = new byte[byteStrings.Length];
|
||||
for (var i = 0; i <= byteStrings.Length - 1; i++)
|
||||
byteOut[i] = byte.Parse(byteStrings[i], NumberStyles.HexNumber);
|
||||
|
||||
return byteOut;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串 转16进制字符串
|
||||
/// </summary>
|
||||
/// <param name="inString">unico </param>
|
||||
/// <returns>类似“01 0f” </returns>
|
||||
public static string Str_To_0X(string inString)
|
||||
{
|
||||
return ByteToString(Encoding.Default.GetBytes(inString));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 虚方法,可供子类重写
|
||||
/// </summary>
|
||||
@@ -346,7 +287,7 @@ namespace Modbus.Net
|
||||
/// 连接串口
|
||||
/// </summary>
|
||||
/// <returns>是否连接成功</returns>
|
||||
public override bool Connect()
|
||||
protected bool Connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -364,6 +305,8 @@ namespace Modbus.Net
|
||||
Linkers.Add(_slave, _com);
|
||||
SerialPort.Open();
|
||||
Log.Information("Com client {ConnectionToken} connect success", ConnectionToken);
|
||||
Controller.SendStart();
|
||||
ReceiveMsgThreadStart();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -391,6 +334,8 @@ namespace Modbus.Net
|
||||
if (Linkers.ContainsKey(_slave) && Connectors.ContainsKey(_com))
|
||||
try
|
||||
{
|
||||
ReceiveMsgThreadStop();
|
||||
Controller.SendStop();
|
||||
Dispose();
|
||||
Log.Information("Com client {ConnectionToken} disconnect success", ConnectionToken);
|
||||
return true;
|
||||
@@ -412,101 +357,152 @@ namespace Modbus.Net
|
||||
/// <returns>是否发送成功</returns>
|
||||
public string SendMsg(string sendStr)
|
||||
{
|
||||
var myByte = StringToByte_2(sendStr);
|
||||
var myByte = sendStr.StringToByte_2();
|
||||
|
||||
var returnBytes = SendMsg(myByte);
|
||||
|
||||
return ByteToString(returnBytes);
|
||||
return returnBytes.ByteToString();
|
||||
}
|
||||
|
||||
protected void CheckOpen()
|
||||
{
|
||||
if (!SerialPort.IsOpen)
|
||||
{
|
||||
try
|
||||
{
|
||||
SerialPort.Open();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Error(err, "Com client {ConnectionToken} open error", ConnectionToken);
|
||||
Dispose();
|
||||
try
|
||||
{
|
||||
SerialPort.Open();
|
||||
}
|
||||
catch (Exception err2)
|
||||
{
|
||||
Log.Error(err2, "Com client {ConnectionToken} open error", ConnectionToken);
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 带返回发送数据
|
||||
/// 发送数据,需要返回
|
||||
/// </summary>
|
||||
/// <param name="sendbytes">需要发送的数据</param>
|
||||
/// <param name="message">发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
public override byte[] SendMsg(byte[] sendbytes)
|
||||
protected byte[] SendMsg(byte[] message)
|
||||
{
|
||||
try
|
||||
return AsyncHelper.RunSync(() => SendMsgAsync(message));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据,需要返回
|
||||
/// </summary>
|
||||
/// <param name="message">发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
public override async Task<byte[]> SendMsgAsync(byte[] message)
|
||||
{
|
||||
CheckOpen();
|
||||
var task = SendMsgInner(message).WithCancellation(new CancellationTokenSource(10000).Token);
|
||||
var ans = await task;
|
||||
if (task.IsCanceled)
|
||||
{
|
||||
if (!SerialPort.IsOpen)
|
||||
try
|
||||
{
|
||||
SerialPort.Open();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Error(err, "Com client {ConnectionToken} open error", ConnectionToken);
|
||||
Dispose();
|
||||
SerialPort.Open();
|
||||
}
|
||||
Controller.ForceRemoveWaitingMessage(ans);
|
||||
return null;
|
||||
}
|
||||
return ans.ReceiveMessage;
|
||||
}
|
||||
|
||||
byte[] returnBytes;
|
||||
private async Task<MessageWaitingDef> SendMsgInner(byte[] message)
|
||||
{
|
||||
var messageSendingdef = Controller.AddMessage(message);
|
||||
messageSendingdef.SendMutex.WaitOne();
|
||||
await SendMsgWithoutConfirm(message);
|
||||
messageSendingdef.ReceiveMutex.WaitOne();
|
||||
return messageSendingdef;
|
||||
}
|
||||
|
||||
lock (SerialPort.Lock)
|
||||
protected override async Task SendMsgWithoutConfirm(byte[] message)
|
||||
{
|
||||
using (await SerialPort.Lock.LockAsync())
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Verbose("Com client {ConnectionToken} send msg length: {Length}", ConnectionToken,
|
||||
sendbytes.Length);
|
||||
Log.Verbose(
|
||||
$"Com client {ConnectionToken} send msg: {String.Concat(sendbytes.Select(p => " " + p.ToString("X2")))}");
|
||||
SerialPort.Write(sendbytes, 0, sendbytes.Length);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Error(err, "Com client {ConnectionToken} send msg error", ConnectionToken);
|
||||
return null;
|
||||
}
|
||||
RefreshSendCount();
|
||||
Log.Verbose("Com client {ConnectionToken} send msg length: {Length}", ConnectionToken,
|
||||
message.Length);
|
||||
Log.Verbose(
|
||||
$"Com client {ConnectionToken} send msg: {String.Concat(message.Select(p => " " + p.ToString("X2")))}");
|
||||
await Task.Run(()=>SerialPort.Write(message, 0, message.Length));
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Error(err, "Com client {ConnectionToken} send msg error", ConnectionToken);
|
||||
}
|
||||
RefreshSendCount();
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
protected override void ReceiveMsgThreadStart()
|
||||
{
|
||||
_receiveThread = Task.Run(()=>ReceiveMessage());
|
||||
}
|
||||
|
||||
protected override void ReceiveMsgThreadStop()
|
||||
{
|
||||
_taskCancel = true;
|
||||
}
|
||||
|
||||
private void ReceiveMessage()
|
||||
{
|
||||
while (!_taskCancel)
|
||||
{
|
||||
try
|
||||
{
|
||||
var returnBytes = ReadMsg();
|
||||
if (returnBytes != null)
|
||||
{
|
||||
returnBytes = ReadMsg();
|
||||
Log.Verbose("Com client {ConnectionToken} receive msg length: {Length}", ConnectionToken,
|
||||
returnBytes.Length);
|
||||
Log.Verbose(
|
||||
$"Com client {ConnectionToken} receive msg: {String.Concat(returnBytes.Select(p => " " + p.ToString("X2")))}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "Com client {ConnectionToken} read msg error", ConnectionToken);
|
||||
return null;
|
||||
|
||||
var isMessageConfirmed = Controller.ConfirmMessage(returnBytes);
|
||||
if (isMessageConfirmed == false)
|
||||
{
|
||||
//主动传输事件
|
||||
}
|
||||
}
|
||||
RefreshReceiveCount();
|
||||
}
|
||||
return returnBytes;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Log.Error(err, "Com client {ConnectionToken} read error", ConnectionToken);
|
||||
Dispose();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 带返回发送数据
|
||||
/// </summary>
|
||||
/// <param name="message">需要发送的数据</param>
|
||||
/// <returns>是否发送成功</returns>
|
||||
public override Task<byte[]> SendMsgAsync(byte[] message)
|
||||
{
|
||||
return Task.FromResult(SendMsg(message));
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "Com client {ConnectionToken} read msg error", ConnectionToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] ReadMsg()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!SerialPort.IsOpen)
|
||||
SerialPort.Open();
|
||||
CheckOpen();
|
||||
|
||||
byte[] data;
|
||||
Thread.Sleep(100);
|
||||
var i = ReadComm(out data, 10, 5000, 1000);
|
||||
var returndata = new byte[i];
|
||||
Array.Copy(data, 0, returndata, 0, i);
|
||||
return returndata;
|
||||
if (i > 0)
|
||||
{
|
||||
var returndata = new byte[i];
|
||||
Array.Copy(data, 0, returndata, 0, i);
|
||||
return returndata;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net45</TargetFramework>
|
||||
<TargetFrameworks>net45;netstandard20</TargetFrameworks>
|
||||
<AssemblyName>Modbus.Net</AssemblyName>
|
||||
<RootNamespace>Modbus.Net</RootNamespace>
|
||||
<PackageId>Modbus.Net</PackageId>
|
||||
@@ -27,46 +27,24 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\src\Base.Common\AddressCombiner.cs" Link="AddressCombiner.cs" />
|
||||
<Compile Include="..\src\Base.Common\AddressFormater.cs" Link="AddressFormater.cs" />
|
||||
<Compile Include="..\src\Base.Common\AddressHelper.cs" Link="AddressHelper.cs" />
|
||||
<Compile Include="..\src\Base.Common\AddressTranslator.cs" Link="AddressTranslator.cs" />
|
||||
<Compile Include="..\src\Base.Common\AsyncHelper.cs" Link="AsyncHelper.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseConnector.cs" Link="BaseConnector.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseMachine.cs" Link="BaseMachine.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseMachineExtend.cs" Link="BaseMachineExtend.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseProtocal.cs" Link="BaseProtocal.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseUtility.cs" Link="BaseUtility.cs" />
|
||||
<Compile Include="..\src\Base.Common\CRC16.cs" Link="CRC16.cs" />
|
||||
<Compile Include="..\src\Base.Common\IProtocal.cs" Link="IProtocal.cs" />
|
||||
<Compile Include="..\src\Base.Common\IProtocalFormatting.cs" Link="IProtocalFormatting.cs" />
|
||||
<Compile Include="..\src\Base.Common\IProtocalLinker.cs" Link="IProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\IProtocalLinkerBytesExtend.cs" Link="IProtocalLinkerBytesExtend.cs" />
|
||||
<Compile Include="..\src\Base.Common\ProtocalLinker.cs" Link="ProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\ProtocalUnit.cs" Link="ProtocalUnit.cs" />
|
||||
<Compile Include="..\src\Base.Common\TaskManager.cs" Link="TaskManager.cs" />
|
||||
<Compile Include="..\src\Base.Common\TcpConnector.cs" Link="TcpConnector.cs" />
|
||||
<Compile Include="..\src\Base.Common\TcpProtocalLinker.cs" Link="TcpProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\ValueHelper.cs" Link="ValueHelper.cs" />
|
||||
<Compile Include="..\src\Base.Common\IUtilityMethod.cs" Link="IUtilityMethod.cs" />
|
||||
<Compile Include="..\src\Base.Common\IMachineMethod.cs" Link="IMachineMethod.cs" />
|
||||
<Compile Include="..\src\Base.Common\IConnector.cs" Link="IConnector.cs" />
|
||||
<!--
|
||||
<Compile Include="..\src\Base.Common\ComProtocalLinker.cs" Link="ComProtocalLinker.cs" />
|
||||
<Compile Include="..\src\Base.Common\ComConnector.cs" Link="ComConnector.cs" />
|
||||
-->
|
||||
<Compile Include="..\src\Base.Common\PipeUnit.cs" Link="PipeUnit.cs" />
|
||||
<Compile Include="..\src\Base.Common\IController.cs" Link="IController.cs" />
|
||||
<Compile Include="..\src\Base.Common\BaseController.cs" Link="BaseController.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Nito.AsyncEx" Version="4.0.1" />
|
||||
<PackageReference Include="Serilog" Version="2.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net45' ">
|
||||
<PackageReference Include="Nito.AsyncEx" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net45' ">
|
||||
<Reference Include="System.Configuration" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard20' ">
|
||||
<PackageReference Include="Nito.AsyncEx.Tasks" Version="1.1.0" />
|
||||
<PackageReference Include="Nito.AsyncEx.Coordination" Version="1.0.2" />
|
||||
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />
|
||||
<PackageReference Include="System.Threading.ThreadPool" Version="4.3.0" />
|
||||
<PackageReference Include="System.IO.Ports" Version="4.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
74
Modbus.Net/Modbus.Net/SerialPortHelper.cs
Normal file
74
Modbus.Net/Modbus.Net/SerialPortHelper.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Modbus.Net
|
||||
{
|
||||
public static class SerialPortHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符数组转字符串16进制
|
||||
/// </summary>
|
||||
/// <param name="inBytes"> 二进制字节 </param>
|
||||
/// <returns>类似"01 02 0F" </returns>
|
||||
public static string ByteToString(this byte[] inBytes)
|
||||
{
|
||||
var stringOut = "";
|
||||
foreach (var inByte in inBytes)
|
||||
stringOut = stringOut + $"{inByte:X2}" + " ";
|
||||
|
||||
return stringOut.Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// strhex 转字节数组
|
||||
/// </summary>
|
||||
/// <param name="inString">类似"01 02 0F" 用空格分开的 </param>
|
||||
/// <returns> </returns>
|
||||
public static byte[] StringToByte(this string inString)
|
||||
{
|
||||
var byteStrings = inString.Split(" ".ToCharArray());
|
||||
var byteOut = new byte[byteStrings.Length];
|
||||
for (var i = 0; i <= byteStrings.Length - 1; i++)
|
||||
byteOut[i] = byte.Parse(byteStrings[i], NumberStyles.HexNumber);
|
||||
return byteOut;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// strhex 转字节数组
|
||||
/// </summary>
|
||||
/// <param name="inString">类似"01 02 0F" 中间无空格 </param>
|
||||
/// <returns> </returns>
|
||||
public static byte[] StringToByte_2(this string inString)
|
||||
{
|
||||
inString = inString.Replace(" ", "");
|
||||
|
||||
var byteStrings = new string[inString.Length / 2];
|
||||
var j = 0;
|
||||
for (var i = 0; i < byteStrings.Length; i++)
|
||||
{
|
||||
byteStrings[i] = inString.Substring(j, 2);
|
||||
j += 2;
|
||||
}
|
||||
|
||||
var byteOut = new byte[byteStrings.Length];
|
||||
for (var i = 0; i <= byteStrings.Length - 1; i++)
|
||||
byteOut[i] = byte.Parse(byteStrings[i], NumberStyles.HexNumber);
|
||||
|
||||
return byteOut;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串 转16进制字符串
|
||||
/// </summary>
|
||||
/// <param name="inString">unico </param>
|
||||
/// <returns>类似“01 0f” </returns>
|
||||
public static string Str_To_0X(this string inString)
|
||||
{
|
||||
return ByteToString(Encoding.Default.GetBytes(inString));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,6 +196,7 @@ namespace Modbus.Net
|
||||
try
|
||||
{
|
||||
Dispose();
|
||||
Controller.SendStop();
|
||||
Log.Information("Tcp client {ConnectionToken} disconnected successfully", ConnectionToken);
|
||||
return true;
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{124EBEF2-8960-4447-84CF-1D683B1EF7CC}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Modbus.Net</RootNamespace>
|
||||
<AssemblyName>Modbus.Net</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>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>
|
||||
</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AddressCombiner.cs" />
|
||||
<Compile Include="AddressFormater.cs" />
|
||||
<Compile Include="AddressTranslator.cs" />
|
||||
<Compile Include="AddressHelper.cs" />
|
||||
<Compile Include="AsyncHelper.cs" />
|
||||
<Compile Include="BaseMachineExtend.cs" />
|
||||
<Compile Include="BaseProtocal.cs" />
|
||||
<Compile Include="BaseUtility.cs" />
|
||||
<Compile Include="BaseMachine.cs" />
|
||||
<Compile Include="ComConnector.cs" />
|
||||
<Compile Include="ComProtocalLinker.cs" />
|
||||
<Compile Include="ConfigurationManager.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>ConfigurationManager.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BaseConnector.cs" />
|
||||
<Compile Include="CRC16.cs" />
|
||||
<Compile Include="IProtocal.cs" />
|
||||
<Compile Include="IProtocalFormatting.cs" />
|
||||
<Compile Include="IProtocalLinker.cs" />
|
||||
<Compile Include="ProtocalLinker.cs" />
|
||||
<Compile Include="IProtocalLinkerBytesExtend.cs" />
|
||||
<Compile Include="ProtocalUnit.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TaskManager.cs" />
|
||||
<Compile Include="TcpConnector.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="TcpProtocalLinker.cs" />
|
||||
<Compile Include="ValueHelper.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="ConfigurationManager.resx">
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>ConfigurationManager.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ModBus.Net.nuspec">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="README.md" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -18,9 +18,9 @@ namespace Modbus.Net.Tests
|
||||
[TestInitialize]
|
||||
public void Init()
|
||||
{
|
||||
_modbusTcpMachine = new ModbusMachine("1", ModbusType.Tcp, "192.168.3.10", null, true, 2, 0);
|
||||
//_modbusTcpMachine = new ModbusMachine("1", ModbusType.Tcp, "192.168.3.10", null, true, 2, 0);
|
||||
|
||||
//_modbusRtuMachine = new ModbusMachine("2", ModbusType.Rtu, "COM3", null, true, 2, 0);
|
||||
_modbusRtuMachine = new ModbusMachine("2", ModbusType.Rtu, "COM5", null, true, 2, 0);
|
||||
|
||||
//_modbusAsciiMachine = new ModbusMachine("3", ModbusType.Ascii, "COM5", null, true, 2, 0);
|
||||
}
|
||||
@@ -50,17 +50,17 @@ namespace Modbus.Net.Tests
|
||||
}
|
||||
};
|
||||
|
||||
_modbusTcpMachine.GetAddresses = addresses;
|
||||
//_modbusTcpMachine.GetAddresses = addresses;
|
||||
//_modbusAsciiMachine.GetAddresses = addresses;
|
||||
//_modbusRtuMachine.GetAddresses = addresses;
|
||||
await _modbusTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
_modbusRtuMachine.GetAddresses = addresses;
|
||||
//await _modbusTcpMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
//await _modbusAsciiMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
//await _modbusRtuMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
//var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
await _modbusRtuMachine.SetDatasAsync(MachineSetDataType.Address, dic1);
|
||||
//var ans = await _modbusTcpMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
var ans2 = await _modbusRtuMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
//var ans3 = await _modbusAsciiMachine.GetDatasAsync(MachineGetDataType.Address);
|
||||
Assert.AreEqual(ans["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
//Assert.AreEqual(ans2["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
//Assert.AreEqual(ans["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
Assert.AreEqual(ans2["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
//Assert.AreEqual(ans3["0X 1.0"].PlcValue, dic1["0X 1.0"]);
|
||||
}
|
||||
|
||||
@@ -317,8 +317,8 @@ namespace Modbus.Net.Tests
|
||||
public void MachineClean()
|
||||
{
|
||||
//_modbusAsciiMachine.Disconnect();
|
||||
//_modbusRtuMachine.Disconnect();
|
||||
_modbusTcpMachine.Disconnect();
|
||||
_modbusRtuMachine.Disconnect();
|
||||
//_modbusTcpMachine.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user