From a2f5286e451dd20fc53cf8972291fd5eece0f3a0 Mon Sep 17 00:00:00 2001 From: ig Date: Tue, 13 Jun 2023 12:54:06 +0200 Subject: [PATCH] EmuMeter V2 --- csharp/Lib/Devices/EmuMeter/EmuMeterDevice.cs | 28 +++++++++++++++++++ .../Lib/Devices/EmuMeter/EmuMeterRegisters.cs | 2 +- csharp/Lib/Devices/EmuMeter/Program.cs | 12 +++----- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/csharp/Lib/Devices/EmuMeter/EmuMeterDevice.cs b/csharp/Lib/Devices/EmuMeter/EmuMeterDevice.cs index 7ca06419d..9bf0ec45b 100644 --- a/csharp/Lib/Devices/EmuMeter/EmuMeterDevice.cs +++ b/csharp/Lib/Devices/EmuMeter/EmuMeterDevice.cs @@ -18,4 +18,32 @@ public class EmuMeterDevice: ModbusDevice { } + + public new EmuMeterRegisters? Read() + { + try + { + return base.Read(); + } + catch (Exception e) + { + // TODO: Log + Console.WriteLine(e); + return null; + } + } + + + public new void Write(EmuMeterRegisters 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/EmuMeter/EmuMeterRegisters.cs b/csharp/Lib/Devices/EmuMeter/EmuMeterRegisters.cs index 2b9839892..d27007bf9 100644 --- a/csharp/Lib/Devices/EmuMeter/EmuMeterRegisters.cs +++ b/csharp/Lib/Devices/EmuMeter/EmuMeterRegisters.cs @@ -10,7 +10,7 @@ using Float32 = Single; [AddressOffset(-2)] // why? -public record EmuMeterRegisters : IAc3Meter +public class EmuMeterRegisters : IAc3Meter { [HoldingRegister(9002)] private Float32 _ActivePowerL1; [HoldingRegister(9004)] private Float32 _ActivePowerL2; diff --git a/csharp/Lib/Devices/EmuMeter/Program.cs b/csharp/Lib/Devices/EmuMeter/Program.cs index 5eb94aa52..604671b5d 100644 --- a/csharp/Lib/Devices/EmuMeter/Program.cs +++ b/csharp/Lib/Devices/EmuMeter/Program.cs @@ -1,6 +1,6 @@ -using System.Text.Json; using InnovEnergy.Lib.Protocols.Modbus.Channels; using InnovEnergy.Lib.Protocols.Modbus.Clients; +using InnovEnergy.Lib.Units; using InnovEnergy.Lib.Utils; namespace InnovEnergy.Lib.Devices.EmuMeter; @@ -9,20 +9,16 @@ public static class Program { public static Task Main(string[] args) { - var ch = new TcpChannel("localhost", 5003); + var ch = new TcpChannel("localhost", 5004); var cl = new ModbusTcpClient(ch, 1); var d = new EmuMeterDevice(cl); while (true) { var x = d.Read(); - - //x.WriteLine(); - var options = new JsonSerializerOptions { WriteIndented = true }; - (x, options).Apply(JsonSerializer.Serialize).WriteLine(); - + x.ToCsv().WriteLine(); } - + } } \ No newline at end of file