From 5fc72a4f390feb37ee0ac2f295760fac44a3c6d1 Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 14 Mar 2025 13:25:39 +0100 Subject: [PATCH] update Deligreen stand alone application --- .../DeviceState.cs | 8 ++ .../RelaysDeviceAmax.cs | 11 ++- .../RelaysRecordAmax.cs | 98 +++++++++++++++++++ .../SalimaxDevice.cs | 13 +++ 4 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 csharp/App/DeligreenBatteryCommunication/DeviceState.cs rename csharp/App/{SodiStoreMax/src/SaliMaxRelays => DeligreenBatteryCommunication}/RelaysDeviceAmax.cs (83%) create mode 100644 csharp/App/DeligreenBatteryCommunication/RelaysRecordAmax.cs create mode 100644 csharp/App/DeligreenBatteryCommunication/SalimaxDevice.cs diff --git a/csharp/App/DeligreenBatteryCommunication/DeviceState.cs b/csharp/App/DeligreenBatteryCommunication/DeviceState.cs new file mode 100644 index 000000000..4fac5fc9d --- /dev/null +++ b/csharp/App/DeligreenBatteryCommunication/DeviceState.cs @@ -0,0 +1,8 @@ +namespace InnovEnergy.App.DeligreenBatteryCommunication; + +public enum DeviceState +{ + Disabled, + Measured, + Computed +} \ No newline at end of file diff --git a/csharp/App/SodiStoreMax/src/SaliMaxRelays/RelaysDeviceAmax.cs b/csharp/App/DeligreenBatteryCommunication/RelaysDeviceAmax.cs similarity index 83% rename from csharp/App/SodiStoreMax/src/SaliMaxRelays/RelaysDeviceAmax.cs rename to csharp/App/DeligreenBatteryCommunication/RelaysDeviceAmax.cs index c5cbbd010..9adef3106 100644 --- a/csharp/App/SodiStoreMax/src/SaliMaxRelays/RelaysDeviceAmax.cs +++ b/csharp/App/DeligreenBatteryCommunication/RelaysDeviceAmax.cs @@ -1,10 +1,10 @@ using InnovEnergy.Lib.Devices.Amax5070; using InnovEnergy.Lib.Protocols.Modbus.Channels; +using InnovEnergy.Lib.Utils; +namespace InnovEnergy.App.DeligreenBatteryCommunication; -namespace InnovEnergy.App.SodiStoreMax.SaliMaxRelays; - -public class RelaysDeviceAmax +public class RelaysDeviceAmax { private Amax5070Device AmaxDevice { get; } @@ -12,13 +12,14 @@ public class RelaysDeviceAmax public RelaysRecordAmax? Read() { + try { return AmaxDevice.Read(); } catch (Exception e) { - $"Failed to read from {nameof(RelaysDeviceAmax)}\n{e}".LogError(); + $"Failed to read from {nameof(RelaysDeviceAmax)}\n{e}".WriteLine(); return null; } } @@ -31,7 +32,7 @@ public class RelaysDeviceAmax } catch (Exception e) { - $"Failed to write to {nameof(RelaysDeviceAmax)}\n{e}".LogError(); + $"Failed to write to {nameof(RelaysDeviceAmax)}\n{e}".WriteLine(); } } } \ No newline at end of file diff --git a/csharp/App/DeligreenBatteryCommunication/RelaysRecordAmax.cs b/csharp/App/DeligreenBatteryCommunication/RelaysRecordAmax.cs new file mode 100644 index 000000000..af77d4ce1 --- /dev/null +++ b/csharp/App/DeligreenBatteryCommunication/RelaysRecordAmax.cs @@ -0,0 +1,98 @@ +using InnovEnergy.Lib.Devices.Amax5070; + +namespace InnovEnergy.App.DeligreenBatteryCommunication; + +public class RelaysRecordAmax +{ + private readonly Amax5070Registers _regs; + + private RelaysRecordAmax(Amax5070Registers regs) => _regs = regs; + + //public UInt16 K0Input + //{ + // get => _regs.DigitalInput; + //} + + + public Boolean K0 + { + get => _regs.DigitalOutput0; + set => _regs.DigitalOutput0 = value; + } + + public Boolean K1 + { + get => _regs.DigitalOutput1; + set => _regs.DigitalOutput1 = value; + } + + public Boolean K2 + { + get => _regs.DigitalOutput2; + set => _regs.DigitalOutput2 = value; + } + + public Boolean K3 + { + get => _regs.DigitalOutput3; + set => _regs.DigitalOutput3 = value; + } + + + public Boolean R0 + { + get => _regs.Relay12; + set => _regs.Relay12 = value; + } + + public Boolean R1 + { + get => _regs.Relay22; + set => _regs.Relay22 = value; + } + + public Boolean R2 + { + get => _regs.Relay32; + set => _regs.Relay32 = value; + } + + public Boolean R3 + { + get => _regs.Relay42; + set => _regs.Relay42 = value; + } + + + /* + public Boolean K1GridBusIsConnectedToGrid => _regs.DigitalInput22; + public Boolean K2IslandBusIsConnectedToGridBus => !_regs.DigitalInput20; + public IEnumerable K3InverterIsConnectedToIslandBus + { + get + { + yield return K3Inverter1IsConnectedToIslandBus; + yield return K3Inverter2IsConnectedToIslandBus; + yield return K3Inverter3IsConnectedToIslandBus; + yield return K3Inverter4IsConnectedToIslandBus; + } + } + + private Boolean K3Inverter1IsConnectedToIslandBus => !_regs.DigitalInput16; + private Boolean K3Inverter2IsConnectedToIslandBus => !_regs.DigitalInput17; + private Boolean K3Inverter3IsConnectedToIslandBus => !_regs.DigitalInput18; + private Boolean K3Inverter4IsConnectedToIslandBus => !_regs.DigitalInput19; + + public Boolean FiWarning => !_regs.DigitalInput21; + public Boolean FiError => !_regs.DigitalInput23;*/ + + //public Boolean K2ConnectIslandBusToGridBus + //{ + // get => _regs.Relay22; + // set => _regs.Relay22 = value; + //} + + + public static implicit operator Amax5070Registers(RelaysRecordAmax d) => d._regs; + public static implicit operator RelaysRecordAmax(Amax5070Registers d) => new RelaysRecordAmax(d); +} \ No newline at end of file diff --git a/csharp/App/DeligreenBatteryCommunication/SalimaxDevice.cs b/csharp/App/DeligreenBatteryCommunication/SalimaxDevice.cs new file mode 100644 index 000000000..a31c73a99 --- /dev/null +++ b/csharp/App/DeligreenBatteryCommunication/SalimaxDevice.cs @@ -0,0 +1,13 @@ +using InnovEnergy.Lib.Utils.Net; + +namespace InnovEnergy.App.DeligreenBatteryCommunication; + +public class SalimaxDevice : Ip4Address +{ + public required DeviceState DeviceState { get; init; } + + public override String ToString() => $"{base.ToString()} ({DeviceState})"; + + public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), DeviceState); + +} \ No newline at end of file