From e830e43c363323a009836e52ff1230a8405f2845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Wed, 17 Jul 2024 18:00:16 +0200 Subject: [PATCH] Clearified/fixed description of different protocol implementations --- .../Protocols/RtuOverTcpProtocol.cs | 16 +++++++++------- AMWD.Protocols.Modbus.Common/README.md | 9 +++++++-- AMWD.Protocols.Modbus.Tcp/README.md | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/AMWD.Protocols.Modbus.Common/Protocols/RtuOverTcpProtocol.cs b/AMWD.Protocols.Modbus.Common/Protocols/RtuOverTcpProtocol.cs index 67fcb6a..72089b4 100644 --- a/AMWD.Protocols.Modbus.Common/Protocols/RtuOverTcpProtocol.cs +++ b/AMWD.Protocols.Modbus.Common/Protocols/RtuOverTcpProtocol.cs @@ -6,11 +6,13 @@ using AMWD.Protocols.Modbus.Common.Contracts; namespace AMWD.Protocols.Modbus.Common.Protocols { /// - /// Implementation of the Modbus RTU over TCP protocol. + /// Implementation of the Modbus RTU over Modbus TCP protocol. /// /// /// The Modbus RTU over Modbus TCP is rarely used. - /// It is a non-standard variant of Modbus TCP that includes the Modbus RTU CRC at the end of the message. + /// It is a non-standard variant of Modbus TCP that includes wrapps a Modbus RTU message within a Modbus TCP message. + ///
+ /// Definition found on Fernhill Software. ///
public class RtuOverTcpProtocol : IModbusProtocol { @@ -475,16 +477,16 @@ namespace AMWD.Protocols.Modbus.Common.Protocols // Function code request[7] = (byte)ModbusFunctionCode.WriteSingleRegister; - byte[] addrBytes = register.Address.ToBigEndianBytes(); - request[8] = addrBytes[0]; + byte[] addrBytes = register.Address.ToBigEndianBytes(); + request[8] = addrBytes[0]; request[9] = addrBytes[1]; - request[10] = register.HighByte; + request[10] = register.HighByte; request[11] = register.LowByte; // CRC - byte[] crc = RtuProtocol.CRC16(request, 6, 6); - request[12] = crc[0]; + byte[] crc = RtuProtocol.CRC16(request, 6, 6); + request[12] = crc[0]; request[13] = crc[1]; return request; diff --git a/AMWD.Protocols.Modbus.Common/README.md b/AMWD.Protocols.Modbus.Common/README.md index ce2a2f2..ba38c91 100644 --- a/AMWD.Protocols.Modbus.Common/README.md +++ b/AMWD.Protocols.Modbus.Common/README.md @@ -59,8 +59,8 @@ Here you have the specific default implementations for the Modbus Protocol. - ASCII - RTU -- RTU over TCP - TCP +- [RTU over TCP] **NOTE:** The implementations over serial line (RTU and ASCII) have a minimum unit ID of one (1) and maximum unit ID of 247 referring to the specification. @@ -68,4 +68,9 @@ This validation is _not_ implemented here due to real world experience, that som --- -Published under MIT License (see [**tl;dr**Legal](https://www.tldrlegal.com/license/mit-license)) +Published under MIT License (see [**tl;dr**Legal]) + + + +[RTU over TCP]: https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html +[**tl;dr**Legal]: https://www.tldrlegal.com/license/mit-license diff --git a/AMWD.Protocols.Modbus.Tcp/README.md b/AMWD.Protocols.Modbus.Tcp/README.md index c459fe3..8ce403b 100644 --- a/AMWD.Protocols.Modbus.Tcp/README.md +++ b/AMWD.Protocols.Modbus.Tcp/README.md @@ -23,14 +23,14 @@ float voltage = registers.GetSingle(); Console.WriteLine($"The voltage of device #{unitId} between L1 and N is: {voltage:N2}V"); ``` -If you want to use the `RTU over TCP` protocol instead, you can do this on initialization: +If you have a device speaking `RTU` connected over `TCP`, you can use it as followed: ```csharp // [...] using var client = new ModbusTcpClient(host, port) { - Protocol = new RtuOverTcpProtocol(); + Protocol = new RtuProtocol() }; // [...]