Add try Catch over SystemControl write function

This commit is contained in:
atef 2023-07-13 09:50:40 +02:00
parent df0983e97e
commit dafef572ab
1 changed files with 11 additions and 11 deletions

View File

@ -17,7 +17,7 @@ public class TruConvertAcDcDevices
public TruConvertAcDcDevices(Channel transport) public TruConvertAcDcDevices(Channel transport)
{ {
var modbusClient = new ModbusTcpClient(transport, 0); var modbusClient = new ModbusTcpClient(transport, slaveId: 0);
_SystemControl = new ModbusDevice<SystemControlRegisters>(modbusClient); _SystemControl = new ModbusDevice<SystemControlRegisters>(modbusClient);
@ -56,22 +56,22 @@ public class TruConvertAcDcDevices
} }
public void Write(AcDcDevicesRecord r) public void Write(AcDcDevicesRecord r)
{
try
{ {
if (r.SystemControl is not null) if (r.SystemControl is not null)
_SystemControl.Write(r.SystemControl); // must run BEFORE the attached devices _SystemControl.Write(r.SystemControl); // must run BEFORE the attached devices
foreach (var (ctrl, device) in r.Devices.Zip(_AcDcs)) foreach (var (ctrl, device) in r.Devices.Zip(_AcDcs))
{
try
{ {
device.Write(ctrl); device.Write(ctrl);
} }
}
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e); Console.WriteLine(e);
// TODO: log // TODO: log
} }
} }
}
} }