From 1cf49f74eaa7a05fc87c40dec98d283de0637f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Tue, 21 Jan 2025 20:00:28 +0100 Subject: [PATCH] Added README for cli tool --- .../Protocols/AsciiProtocol.cs | 4 + .../Protocols/RtuProtocol.cs | 4 + CliClient/Program.cs | 4 +- CliClient/README.md | 95 +++++++++++++++++++ 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 CliClient/README.md diff --git a/AMWD.Protocols.Modbus.Common/Protocols/AsciiProtocol.cs b/AMWD.Protocols.Modbus.Common/Protocols/AsciiProtocol.cs index b6d5566..03ebb6c 100644 --- a/AMWD.Protocols.Modbus.Common/Protocols/AsciiProtocol.cs +++ b/AMWD.Protocols.Modbus.Common/Protocols/AsciiProtocol.cs @@ -675,6 +675,10 @@ namespace AMWD.Protocols.Modbus.Common.Protocols /// /// Calculate LRC for Modbus ASCII. /// + /// + /// The LRC calculation algorithm is defined in the Modbus serial line specification. + /// See Modbus over Serial Line v1.02, Appendix B, page 38. + /// /// The message chars. /// The start index. /// The number of bytes to calculate. diff --git a/AMWD.Protocols.Modbus.Common/Protocols/RtuProtocol.cs b/AMWD.Protocols.Modbus.Common/Protocols/RtuProtocol.cs index 40a2a8b..5a7109a 100644 --- a/AMWD.Protocols.Modbus.Common/Protocols/RtuProtocol.cs +++ b/AMWD.Protocols.Modbus.Common/Protocols/RtuProtocol.cs @@ -733,6 +733,10 @@ namespace AMWD.Protocols.Modbus.Common.Protocols /// /// Calculate CRC16 for Modbus RTU. /// + /// + /// The CRC 16 calculation algorithm is defined in the Modbus serial line specification. + /// See Modbus over Serial Line v1.02, Appendix B, page 40. + /// /// The message bytes. /// The start index. /// The number of bytes to calculate. diff --git a/CliClient/Program.cs b/CliClient/Program.cs index 403854f..ae54848 100644 --- a/CliClient/Program.cs +++ b/CliClient/Program.cs @@ -460,7 +460,7 @@ namespace AMWD.Protocols.Modbus.CliClient private static void PrintHelp() { - Console.WriteLine("Usage: amwd-modbus [OPTIONS] |"); + Console.WriteLine($"Usage: {typeof(Program).Assembly.GetName().Name} [OPTIONS] |"); Console.WriteLine(); Console.WriteLine("Serial Port:"); Console.WriteLine(" COM1, COM2, ... on Windows"); @@ -522,7 +522,7 @@ namespace AMWD.Protocols.Modbus.CliClient Console.WriteLine(); Console.WriteLine("Serial Options:"); Console.WriteLine(" -b, --baud #"); - Console.WriteLine(" The baud rate (e.g. 9600, 19200, 38400, 115200). Default: 19200"); + Console.WriteLine(" The baud rate (e.g. 9600). Default: 19200"); Console.WriteLine(); Console.WriteLine(" -d, --databits #"); Console.WriteLine(" The number of data bits (7/8 for ASCII, otherwise 8). Default: 8"); diff --git a/CliClient/README.md b/CliClient/README.md new file mode 100644 index 0000000..9746e9d --- /dev/null +++ b/CliClient/README.md @@ -0,0 +1,95 @@ +# Modbus CLI client + +This project contains a small CLI tool to test Modbus connections. + +``` +Usage: modbus-client [OPTIONS] | + +Serial Port: + COM1, COM2, ... on Windows + /dev/ttyS0, /dev/ttyUSB0, ... on Linux + +TCP Host: + 192.168.x.y as IPv4 + fd00:1234:x:y::z as IPv6 + +General Options: + -h, --help + Shows this help message. + + --debug + Waits for a debugger to attach before starting. + + -m, --protocol + Select which protocol to use. + + -a, --address # + The slave/device address. 1-247 for serial, 0-255 for TCP. Default: 1 + + -r, --reference # + The start reference to read from. 0-65535. Default: 0 + + -c, --count # + The number of values to read. Default: 1 + + -t, --type + Reads a discrete value (bool): Coil or Discrete Input. + + -t, --type input: + Reads an input register. Kind: (e.g. i32) + hex = print as HEX representation + i = signed integer (8, 16, 32, 64) + u = unsigned integer (8, 16, 32, 64) + f = floating point (32, 64) + + -t, --type holding: + Reads a holding register. Kind: (e.g. i32) + hex = print as HEX representation + i = signed integer (8, 16, 32, 64) + u = unsigned integer (8, 16, 32, 64) + f = floating point (32, 64) + + -t, --type id + Tries to read the device identification (Fn 43, Regular). + This option implies --once. + + -i, --interval # + The polling interval in milliseconds. Default: 1000 + + -o, --timeout # + The timeout in milliseconds. Default: 1000 + + -1, --once + Just query once, no interval polling. + + +Serial Options: + -b, --baud # + The baud rate (e.g. 9600). Default: 19200 + + -d, --databits # + The number of data bits (7/8 for ASCII, otherwise 8). Default: 8 + + -s, --stopbits # + The number of stop bits (1/2). Default: 1 + + -p, --parity + The kind of parity. Default: even + + --enable-rs485 + Enables the RS485 software switch for serial adapters capable of RS232 and RS485. + + +TCP Options: + -p, --port # + The TCP port of the remote device. Default: 502 +``` + + +--- + +Published under MIT License (see [choose a license]) + + + +[choose a license]: https://choosealicense.com/licenses/mit/