Add .ToString for Batch, helps debugging
This commit is contained in:
parent
49d7237c79
commit
9b997b353f
|
@ -8,7 +8,10 @@ namespace InnovEnergy.Lib.Protocols.Modbus.Reflection;
|
||||||
#pragma warning disable CS8509
|
#pragma warning disable CS8509
|
||||||
#pragma warning disable CS8524
|
#pragma warning disable CS8524
|
||||||
|
|
||||||
internal record Batch<R>(Action<R> Read, Action<R> Write);
|
internal record Batch<R>(Action<R> Read, Action<R> Write, String DebugString)
|
||||||
|
{
|
||||||
|
public override String ToString() => DebugString;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Batches
|
public static class Batches
|
||||||
{
|
{
|
||||||
|
@ -60,10 +63,16 @@ public static class Batches
|
||||||
var count = (UInt16)(endAddress - startAddress);
|
var count = (UInt16)(endAddress - startAddress);
|
||||||
var kind = members[0].Kind;
|
var kind = members[0].Kind;
|
||||||
var isWritable = kind is ModbusKind.HoldingRegister or ModbusKind.Coil;
|
var isWritable = kind is ModbusKind.HoldingRegister or ModbusKind.Coil;
|
||||||
|
var debugString = $"{kind}: {startAddress}" + (endAddress - 1 == startAddress ? "" : $"-{endAddress - 1}");
|
||||||
|
|
||||||
return new Batch<R>(Read(), Write());
|
|
||||||
|
|
||||||
Action<R> Read()
|
// var modPoll = $"{kind}: {startAddress}-{endAddress}"; // TODO
|
||||||
|
var read = MakeRead();
|
||||||
|
var write = MakeWrite();
|
||||||
|
|
||||||
|
return new Batch<R>(read, write, debugString);
|
||||||
|
|
||||||
|
Action<R> MakeRead()
|
||||||
{
|
{
|
||||||
Func<MbData> readModbus = kind switch
|
Func<MbData> readModbus = kind switch
|
||||||
{
|
{
|
||||||
|
@ -85,7 +94,7 @@ public static class Batches
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Action<R> Write()
|
Action<R> MakeWrite()
|
||||||
{
|
{
|
||||||
if (!isWritable)
|
if (!isWritable)
|
||||||
return _ => { }; // nop
|
return _ => { }; // nop
|
||||||
|
|
Loading…
Reference in New Issue