using InnovEnergy.Lib.Devices.Adam6360D; using InnovEnergy.Lib.Devices.Amax5070; using InnovEnergy.Lib.Protocols.Modbus.Channels; namespace InnovEnergy.App.SodiStoreMax.SaliMaxRelays; public class RelaysDevice { private Adam6360DDevice AdamDevice { get; } public RelaysDevice(String hostname) => AdamDevice = new Adam6360DDevice(hostname, 2); public RelaysDevice(Channel channel) => AdamDevice = new Adam6360DDevice(channel, 2); public RelaysRecord? Read() { try { return AdamDevice.Read(); } catch (Exception e) { $"Failed to read from {nameof(RelaysDevice)}\n{e}".LogError(); return null; } } public void Write(RelaysRecord r) { try { AdamDevice.Write(r); } catch (Exception e) { $"Failed to write to {nameof(RelaysDevice)}\n{e}".LogError(); } } } public class RelaysDeviceAmax { private Amax5070Device AmaxDevice { get; } public RelaysDeviceAmax(Channel channel) => AmaxDevice = new Amax5070Device(channel); public RelaysRecordAmax? Read() { try { return AmaxDevice.Read(); } catch (Exception e) { $"Failed to read from {nameof(RelaysDeviceAmax)}\n{e}".LogError(); return null; } } public void Write(RelaysRecordAmax r) { try { AmaxDevice.Write(r); } catch (Exception e) { $"Failed to write to {nameof(RelaysDeviceAmax)}\n{e}".LogError(); } } }