From 9b997b353fc17dfff048338420b410d3e9a2e641 Mon Sep 17 00:00:00 2001 From: ig Date: Tue, 20 Jun 2023 09:51:13 +0200 Subject: [PATCH] Add .ToString for Batch, helps debugging --- .../Lib/Protocols/Modbus/Reflection/Batch.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/csharp/Lib/Protocols/Modbus/Reflection/Batch.cs b/csharp/Lib/Protocols/Modbus/Reflection/Batch.cs index 21542ba89..15be8c7d0 100644 --- a/csharp/Lib/Protocols/Modbus/Reflection/Batch.cs +++ b/csharp/Lib/Protocols/Modbus/Reflection/Batch.cs @@ -8,7 +8,10 @@ namespace InnovEnergy.Lib.Protocols.Modbus.Reflection; #pragma warning disable CS8509 #pragma warning disable CS8524 -internal record Batch(Action Read, Action Write); +internal record Batch(Action Read, Action Write, String DebugString) +{ + public override String ToString() => DebugString; +} public static class Batches { @@ -60,10 +63,16 @@ public static class Batches var count = (UInt16)(endAddress - startAddress); var kind = members[0].Kind; var isWritable = kind is ModbusKind.HoldingRegister or ModbusKind.Coil; - - return new Batch(Read(), Write()); + var debugString = $"{kind}: {startAddress}" + (endAddress - 1 == startAddress ? "" : $"-{endAddress - 1}"); - Action Read() + + // var modPoll = $"{kind}: {startAddress}-{endAddress}"; // TODO + var read = MakeRead(); + var write = MakeWrite(); + + return new Batch(read, write, debugString); + + Action MakeRead() { Func readModbus = kind switch { @@ -85,7 +94,7 @@ public static class Batches }; } - Action Write() + Action MakeWrite() { if (!isWritable) return _ => { }; // nop