if a battery is not reachable, Battery48TlDevices now does not give up and reports the remaining ones instead
This commit is contained in:
parent
28d46d6689
commit
8596fddb04
|
@ -14,6 +14,7 @@ public class Battery48TlDevice : ModbusDevice<Battery48TlRecord>
|
|||
public const Int32 BaudRate = 115200;
|
||||
public const Int32 DataBits = 8;
|
||||
|
||||
public Byte SlaveId { get; }
|
||||
|
||||
public Battery48TlDevice(String tty, Byte slaveId, SshHost host) : this
|
||||
(
|
||||
|
@ -41,6 +42,7 @@ public class Battery48TlDevice : ModbusDevice<Battery48TlRecord>
|
|||
|
||||
public Battery48TlDevice(ModbusClient client): base(client)
|
||||
{
|
||||
SlaveId = client.SlaveId;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,8 @@ public class Battery48TlDevices
|
|||
try
|
||||
{
|
||||
var records = _Devices
|
||||
.Select(d => d.Read())
|
||||
.Select(TryRead)
|
||||
.NotNull()
|
||||
.ToArray(_Devices.Count);
|
||||
|
||||
return new Battery48TlRecords(records);
|
||||
|
@ -26,4 +27,19 @@ public class Battery48TlDevices
|
|||
return Battery48TlRecords.Null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Battery48TlRecord? TryRead(Battery48TlDevice d)
|
||||
{
|
||||
try
|
||||
{
|
||||
return d.Read();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Failed to read Battery node {d.SlaveId}\n{e.Message}");
|
||||
// TODO: log
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,8 +11,9 @@ using UInt16s = IReadOnlyCollection<UInt16>;
|
|||
|
||||
public abstract class ModbusClient
|
||||
{
|
||||
public Byte SlaveId { get; }
|
||||
|
||||
internal Channel Channel { get; }
|
||||
internal Byte SlaveId { get; }
|
||||
internal Endian Endian { get; }
|
||||
|
||||
// TODO: add additional functions: coils...
|
||||
|
|
Loading…
Reference in New Issue