diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TLDevice.cs b/csharp/Lib/Devices/Battery48TL/Battery48TLDevice.cs index 58e0b9144..5702c1227 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TLDevice.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TLDevice.cs @@ -14,6 +14,7 @@ public class Battery48TlDevice : ModbusDevice 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 public Battery48TlDevice(ModbusClient client): base(client) { + SlaveId = client.SlaveId; } } \ No newline at end of file diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TlDevices.cs b/csharp/Lib/Devices/Battery48TL/Battery48TlDevices.cs index 6d6a98c63..bdd25d8d8 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TlDevices.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TlDevices.cs @@ -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; + } + } } \ No newline at end of file diff --git a/csharp/Lib/Protocols/Modbus/Clients/ModbusClient.cs b/csharp/Lib/Protocols/Modbus/Clients/ModbusClient.cs index 2aba23c4d..230a49a2d 100644 --- a/csharp/Lib/Protocols/Modbus/Clients/ModbusClient.cs +++ b/csharp/Lib/Protocols/Modbus/Clients/ModbusClient.cs @@ -11,8 +11,9 @@ using UInt16s = IReadOnlyCollection; 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...