From 0d9135ba06b0b4b704e174780ae5b6cccfcb4de9 Mon Sep 17 00:00:00 2001 From: atef Date: Wed, 11 Jun 2025 15:59:26 +0200 Subject: [PATCH] add doepke to the device config and to our ems --- .../src/SystemConfig/DeviceConfig.cs | 1 + csharp/Lib/Devices/Doepke/DoepkeDevice.cs | 32 +++++++++++++++++-- csharp/Lib/Devices/Doepke/DoepkeRegisters.cs | 1 - 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/csharp/App/SodiStoreMax/src/SystemConfig/DeviceConfig.cs b/csharp/App/SodiStoreMax/src/SystemConfig/DeviceConfig.cs index aed893168..3393b6b83 100644 --- a/csharp/App/SodiStoreMax/src/SystemConfig/DeviceConfig.cs +++ b/csharp/App/SodiStoreMax/src/SystemConfig/DeviceConfig.cs @@ -16,6 +16,7 @@ public class DeviceConfig public required SalimaxDevice PvOnDc { get; init; } public required SalimaxDevice LoadOnDc { get; init; } public required SalimaxDevice TruConvertDcIp { get; init; } + public required SalimaxDevice DoepkeIp { get; init; } public required SalimaxDevice BatteryIp { get; init; } public required Int32[] BatteryNodes { get; init; } } diff --git a/csharp/Lib/Devices/Doepke/DoepkeDevice.cs b/csharp/Lib/Devices/Doepke/DoepkeDevice.cs index b67bd58a2..b35ca7e7a 100644 --- a/csharp/Lib/Devices/Doepke/DoepkeDevice.cs +++ b/csharp/Lib/Devices/Doepke/DoepkeDevice.cs @@ -1,19 +1,47 @@ using InnovEnergy.Lib.Protocols.Modbus.Channels; using InnovEnergy.Lib.Protocols.Modbus.Clients; using InnovEnergy.Lib.Protocols.Modbus.Slaves; +using InnovEnergy.Lib.Utils; namespace InnovEnergy.Lib.Devices.Doepke; public class DoepkeDevice : ModbusDevice { - public DoepkeDevice(String hostname, Byte slaveId, UInt16 port = 502) : + public DoepkeDevice(String hostname, Byte slaveId = 0, UInt16 port = 502) : this(new TcpChannel(hostname, port), slaveId) { } - public DoepkeDevice(Channel channel, Byte slaveId) : base(new ModbusTcpClient(channel, slaveId)) + public DoepkeDevice(Channel channel, Byte slaveId = 0) : base(new ModbusTcpClient(channel, slaveId)) { } + + public new DoepkeRegisters? Read() + { + try + { + return base.Read(); + } + catch + { + "Failed to read data from EmuMeter".WriteLine(); + return null; + } + } + + + public new void Write(DoepkeRegisters registers) + { + try + { + base.Write(registers); + } + catch (Exception e) + { + // TODO: Log + Console.WriteLine(e); + } + } } \ No newline at end of file diff --git a/csharp/Lib/Devices/Doepke/DoepkeRegisters.cs b/csharp/Lib/Devices/Doepke/DoepkeRegisters.cs index ad1c34015..a9f0cedca 100644 --- a/csharp/Lib/Devices/Doepke/DoepkeRegisters.cs +++ b/csharp/Lib/Devices/Doepke/DoepkeRegisters.cs @@ -39,7 +39,6 @@ public class DoepkeRegisters [HoldingRegister(35)] public UInt16 SaveCurrentSettings { get; set; } // 0 = Successful, 1= Save, 2= Error [HoldingRegister(36)] public UInt16 DeviceTest { get; set; } // 0 = Successful, 1= Test active, 2= Error - //*Bit coding alarm status/activation // Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0