EmuMeter V2

This commit is contained in:
ig 2023-06-13 12:54:06 +02:00
parent 8b846c01c2
commit a2f5286e45
3 changed files with 33 additions and 9 deletions

View File

@ -18,4 +18,32 @@ public class EmuMeterDevice: ModbusDevice<EmuMeterRegisters>
{ {
} }
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);
}
}
} }

View File

@ -10,7 +10,7 @@ using Float32 = Single;
[AddressOffset(-2)] // why? [AddressOffset(-2)] // why?
public record EmuMeterRegisters : IAc3Meter public class EmuMeterRegisters : IAc3Meter
{ {
[HoldingRegister<Float32>(9002)] private Float32 _ActivePowerL1; [HoldingRegister<Float32>(9002)] private Float32 _ActivePowerL1;
[HoldingRegister<Float32>(9004)] private Float32 _ActivePowerL2; [HoldingRegister<Float32>(9004)] private Float32 _ActivePowerL2;

View File

@ -1,6 +1,6 @@
using System.Text.Json;
using InnovEnergy.Lib.Protocols.Modbus.Channels; using InnovEnergy.Lib.Protocols.Modbus.Channels;
using InnovEnergy.Lib.Protocols.Modbus.Clients; using InnovEnergy.Lib.Protocols.Modbus.Clients;
using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Utils; using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.Devices.EmuMeter; namespace InnovEnergy.Lib.Devices.EmuMeter;
@ -9,20 +9,16 @@ public static class Program
{ {
public static Task Main(string[] args) 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 cl = new ModbusTcpClient(ch, 1);
var d = new EmuMeterDevice(cl); var d = new EmuMeterDevice(cl);
while (true) while (true)
{ {
var x = d.Read(); var x = d.Read();
x.ToCsv().WriteLine();
//x.WriteLine();
var options = new JsonSerializerOptions { WriteIndented = true };
(x, options).Apply(JsonSerializer.Serialize).WriteLine();
} }
} }
} }