Update
This commit is contained in:
@@ -17,16 +17,49 @@ namespace Modbus.Net.Modbus
|
|||||||
return receiveBytes =>
|
return receiveBytes =>
|
||||||
{
|
{
|
||||||
var writeContent = receiveBytes.Length > 6 ? new byte[receiveBytes.Length - 7] : null;
|
var writeContent = receiveBytes.Length > 6 ? new byte[receiveBytes.Length - 7] : null;
|
||||||
if (receiveBytes.Length > 6) Array.Copy(receiveBytes, 7, writeContent, 0, receiveBytes.Length - 7);
|
if (receiveBytes.Length > 6)
|
||||||
return new ReceiveDataDef()
|
|
||||||
{
|
{
|
||||||
SlaveAddress = receiveBytes[0],
|
Array.Copy(receiveBytes, 7, writeContent, 0, receiveBytes.Length - 7);
|
||||||
FunctionCode = receiveBytes[1],
|
return new ReceiveDataDef()
|
||||||
StartAddress = (ushort)(receiveBytes[2] * 256 + receiveBytes[3]),
|
{
|
||||||
Count = (ushort)(receiveBytes[4] * 256 + receiveBytes[5]),
|
SlaveAddress = receiveBytes[0],
|
||||||
WriteByteCount = (byte)(receiveBytes.Length > 6 ? receiveBytes[6] : 0),
|
FunctionCode = receiveBytes[1],
|
||||||
WriteContent = writeContent
|
StartAddress = (ushort)(receiveBytes[2] * 256 + receiveBytes[3]),
|
||||||
};
|
Count = (ushort)(receiveBytes[4] * 256 + receiveBytes[5]),
|
||||||
|
WriteByteCount = (byte)(receiveBytes.Length > 6 ? receiveBytes[6] : 0),
|
||||||
|
WriteContent = writeContent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (receiveBytes.Length == 6)
|
||||||
|
{
|
||||||
|
if (receiveBytes[1] == 1 || receiveBytes[1] == 2)
|
||||||
|
{
|
||||||
|
writeContent = null;
|
||||||
|
return new ReceiveDataDef()
|
||||||
|
{
|
||||||
|
SlaveAddress = receiveBytes[0],
|
||||||
|
FunctionCode = receiveBytes[1],
|
||||||
|
StartAddress = (ushort)(receiveBytes[2] * 256 + receiveBytes[3]),
|
||||||
|
Count = (ushort)(receiveBytes[4] * 256 + receiveBytes[5]),
|
||||||
|
WriteByteCount = 2,
|
||||||
|
WriteContent = writeContent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
writeContent = new byte[2] { receiveBytes[4], receiveBytes[5] };
|
||||||
|
return new ReceiveDataDef()
|
||||||
|
{
|
||||||
|
SlaveAddress = receiveBytes[0],
|
||||||
|
FunctionCode = receiveBytes[1],
|
||||||
|
StartAddress = (ushort)(receiveBytes[2] * 256 + receiveBytes[3]),
|
||||||
|
Count = 1,
|
||||||
|
WriteByteCount = 2,
|
||||||
|
WriteContent = writeContent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else return null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,16 @@
|
|||||||
<UserSecretsId>dotnet-ModbusTcpToRtu-b7b7d9ed-80ce-4790-86de-5c3cf21e0a2e</UserSecretsId>
|
<UserSecretsId>dotnet-ModbusTcpToRtu-b7b7d9ed-80ce-4790-86de-5c3cf21e0a2e</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="service.bat" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="service.bat">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.1" />
|
||||||
|
|||||||
21
Samples/ModbusTcpToRtu/appsettings.Production.json
Normal file
21
Samples/ModbusTcpToRtu/appsettings.Production.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Error",
|
||||||
|
"Override": {
|
||||||
|
"Microsoft": "Error",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Error",
|
||||||
|
"Microsoft": "Error",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Quartz": {
|
||||||
|
"LogLevel": "Error"
|
||||||
|
}
|
||||||
|
}
|
||||||
4
Samples/ModbusTcpToRtu/service.bat
Normal file
4
Samples/ModbusTcpToRtu/service.bat
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
sc delete ModbusTcpToRtu
|
||||||
|
sc create ModbusTcpToRtu "binPath=%~dp0ModbusTcpToRtu.exe" start= delayed-auto
|
||||||
|
sc start ModbusTcpToRtu
|
||||||
|
pause
|
||||||
Reference in New Issue
Block a user