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

35 lines
847 B
C#
Raw Normal View History

2023-06-13 10:53:52 +00:00
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.Devices.Battery48TL;
public class Battery48TlDevices
{
private readonly IReadOnlyList<Battery48TlDevice> _Devices;
public Battery48TlDevices(IReadOnlyList<Battery48TlDevice> devices) => _Devices = devices;
2023-08-30 14:47:28 +00:00
public Battery48TlRecords? Read()
2023-06-13 10:53:52 +00:00
{
2023-08-30 14:47:28 +00:00
var records = _Devices
.Select(TryRead)
.NotNull()
.ToList();
2023-06-13 10:53:52 +00:00
2023-08-30 14:47:28 +00:00
return Battery48TlRecords.FromBatteries(records);
2023-06-13 10:53:52 +00:00
}
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;
}
}
2023-06-13 10:53:52 +00:00
}