Innovenergy_trunk/csharp/Lib/Devices/Battery48TL/Battery48TlDevices.cs

35 lines
847 B
C#

using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.Devices.Battery48TL;
public class Battery48TlDevices
{
private readonly IReadOnlyList<Battery48TlDevice> _Devices;
public Battery48TlDevices(IReadOnlyList<Battery48TlDevice> devices) => _Devices = devices;
public Battery48TlRecords? Read()
{
var records = _Devices
.Select(TryRead)
.NotNull()
.ToList();
return Battery48TlRecords.FromBatteries(records);
}
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;
}
}
}