One try catch instead of two for DcDcDeviceRecord Read()

This commit is contained in:
atef 2023-09-12 19:31:39 +02:00
parent b213d97537
commit c51250a380
2 changed files with 12 additions and 22 deletions

View File

@ -6,15 +6,15 @@ namespace InnovEnergy.Lib.Devices.Battery48TL;
public class Battery48TlRecords public class Battery48TlRecords
{ {
public required DcBus Dc { get; init; } public required DcBus Dc { get; init; }
public required Boolean Eoc { get; init; } public required Boolean Eoc { get; init; }
public required IReadOnlyList<String> Warnings { get; init; } public required IReadOnlyList<String> Warnings { get; init; }
public required IReadOnlyList<String> Alarms { get; init; } public required IReadOnlyList<String> Alarms { get; init; }
public required Percent Soc { get; init; } public required Percent Soc { get; init; }
public required Percent CurrentMinSoc { get; init; } public required Percent CurrentMinSoc { get; init; }
public required Temperature Temperature { get; init; } public required Temperature Temperature { get; init; }
public required DcPower HeatingPower { get; init; } public required DcPower HeatingPower { get; init; }
public required UInt16 TimeSinceToc { get; init; } public required UInt16 TimeSinceToc { get; init; }
public required Boolean CalibrationChargeRequested { get; init; } public required Boolean CalibrationChargeRequested { get; init; }
public required IReadOnlyList<Battery48TlRecord> Devices { get; init; } public required IReadOnlyList<Battery48TlRecord> Devices { get; init; }

View File

@ -35,22 +35,12 @@ public class TruConvertDcDcDevices
public DcDcDevicesRecord Read() public DcDcDevicesRecord Read()
{ {
SystemControlRegisters? scStatus;
try try
{ {
scStatus = _SystemControl.Read(); var scStatus = _SystemControl.Read();
} var n = scStatus.NumberOfConnectedSlaves;
catch (Exception e)
{
Console.WriteLine(e);
return DcDcDevicesRecord.Null;
}
var n = scStatus.NumberOfConnectedSlaves;
try
{
var dcDcRecords = _DcDcs var dcDcRecords = _DcDcs
.Take(n) .Take(n)
.Select(dcdc => dcdc.Read()) .Select(dcdc => dcdc.Read())
@ -61,7 +51,7 @@ public class TruConvertDcDcDevices
catch catch
{ {
"Failed to read DCDC data".WriteLine(); "Failed to read DCDC data".WriteLine();
return new DcDcDevicesRecord(scStatus, Array.Empty<DcDcRecord>()); return new DcDcDevicesRecord(null, Array.Empty<DcDcRecord>());
} }
} }