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

45 lines
1.1 KiB
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;
public Battery48TlRecords Read()
{
try
{
var records = _Devices
.Select(TryRead)
.NotNull()
2023-06-13 10:53:52 +00:00
.ToArray(_Devices.Count);
return new Battery48TlRecords(records);
}
2023-07-10 08:35:29 +00:00
catch (Exception e)
2023-06-13 10:53:52 +00:00
{
2023-08-18 13:57:00 +00:00
Console.WriteLine("Failed to read Battery data \n" + e.Message);
2023-06-13 10:53:52 +00:00
// TODO: log
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;
}
}
2023-06-13 10:53:52 +00:00
}