Add Iem3KGridMeter project stub

This commit is contained in:
ig 2023-07-11 14:06:53 +02:00
parent 44a2488b07
commit ba8bce65bd
7 changed files with 144 additions and 0 deletions

View File

@ -75,6 +75,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Lib\Logging\Logg
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adam6360D", "Lib\Devices\Adam6360D\Adam6360D.csproj", "{A3C79247-4CAA-44BE-921E-7285AB39E71F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IEM3kGridMeter", "Lib\Devices\IEM3kGridMeter\IEM3kGridMeter.csproj", "{1391165D-51F1-45B4-8B7F-042A20AA0277}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -190,6 +192,10 @@ Global
{A3C79247-4CAA-44BE-921E-7285AB39E71F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3C79247-4CAA-44BE-921E-7285AB39E71F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3C79247-4CAA-44BE-921E-7285AB39E71F}.Release|Any CPU.Build.0 = Release|Any CPU
{1391165D-51F1-45B4-8B7F-042A20AA0277}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1391165D-51F1-45B4-8B7F-042A20AA0277}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1391165D-51F1-45B4-8B7F-042A20AA0277}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1391165D-51F1-45B4-8B7F-042A20AA0277}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CF4834CB-91B7-4172-AC13-ECDA8613CD17} = {145597B4-3E30-45E6-9F72-4DD43194539A}
@ -223,5 +229,6 @@ Global
{B816BB44-E97E-4E02-B80A-BEDB5B923A96} = {DDDBEFD0-5DEA-4C7C-A9F2-FDB4636CF092}
{1A56992B-CB72-490F-99A4-DF1186BA3A18} = {AD5B98A8-AB7F-4DA2-B66D-5B4E63E7D854}
{A3C79247-4CAA-44BE-921E-7285AB39E71F} = {4931A385-24DC-4E78-BFF4-356F8D6D5183}
{1391165D-51F1-45B4-8B7F-042A20AA0277} = {4931A385-24DC-4E78-BFF4-356F8D6D5183}
EndGlobalSection
EndGlobal

Binary file not shown.

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../InnovEnergy.Lib.props" />
<PropertyGroup>
<RootNamespace>InnovEnergy.Lib.Devices.IEM3kGridMeter</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../Utils/Utils.csproj" />
<ProjectReference Include="../../Protocols/Modbus/Modbus.csproj" />
<ProjectReference Include="../../StatusApi/StatusApi.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,50 @@
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.IEM3kGridMeter;
public class Iem3KGridMeterDevice: ModbusDevice<Iem3KGridMeterRegisters>
{
public Iem3KGridMeterDevice(String hostname, UInt16 port = 502, Byte slaveId = 1) : this(new TcpChannel(hostname, port), slaveId)
{
}
public Iem3KGridMeterDevice(Channel channel, Byte slaveId = 1) : base(new ModbusTcpClient(channel, slaveId))
{
}
public Iem3KGridMeterDevice(ModbusClient client) : base(client)
{
}
public new Iem3KGridMeterRegisters? Read()
{
try
{
return base.Read();
}
catch
{
// TODO: Log
$"Failed to read data from {nameof(Iem3KGridMeterDevice)}".WriteLine();
return null;
}
}
public new void Write(Iem3KGridMeterRegisters registers)
{
try
{
base.Write(registers);
}
catch
{
// TODO: Log
$"Failed to write data to {nameof(Iem3KGridMeterDevice)}".WriteLine();
}
}
}

View File

@ -0,0 +1,73 @@
using InnovEnergy.Lib.Protocols.Modbus.Reflection.Attributes;
using InnovEnergy.Lib.StatusApi.DeviceTypes;
using InnovEnergy.Lib.Units.Composite;
#pragma warning disable CS0649
namespace InnovEnergy.Lib.Devices.IEM3kGridMeter;
using Float32 = Single;
[AddressOffset(-2)] // why?
public class Iem3KGridMeterRegisters : IAc3Meter
{
// TODO
// The registers below are kept as example (from EmuMeter)
// replace with actual registers from datasheet
[HoldingRegister<Float32>(9002)] private Float32 _ActivePowerL1;
[HoldingRegister<Float32>(9004)] private Float32 _ActivePowerL2;
[HoldingRegister<Float32>(9006)] private Float32 _ActivePowerL3;
[HoldingRegister<Float32>(9012)] private Float32 _ReactivePowerL1;
[HoldingRegister<Float32>(9014)] private Float32 _ReactivePowerL2;
[HoldingRegister<Float32>(9016)] private Float32 _ReactivePowerL3;
[HoldingRegister<Float32>(9022)] private Float32 _ApparentPowerL1;
[HoldingRegister<Float32>(9024)] private Float32 _ApparentPowerL2;
[HoldingRegister<Float32>(9026)] private Float32 _ApparentPowerL3;
[HoldingRegister<Float32>(9102)] private Float32 _CurrentL1;
[HoldingRegister<Float32>(9104)] private Float32 _CurrentL2;
[HoldingRegister<Float32>(9106)] private Float32 _CurrentL3;
[HoldingRegister<Float32>(9200)] private Float32 _VoltageL1N;
[HoldingRegister<Float32>(9202)] private Float32 _VoltageL2N;
[HoldingRegister<Float32>(9204)] private Float32 _VoltageL3N;
[HoldingRegister<Float32>(9310)] private Float32 _Frequency;
public Ac3Bus Ac => Ac3Bus.FromPhasesAndFrequency
(
l1: AcPhase.FromVoltageCurrentActiveReactiveApparent
(
_VoltageL1N,
_CurrentL1,
_ActivePowerL1,
_ReactivePowerL1,
_ApparentPowerL1
),
l2: AcPhase.FromVoltageCurrentActiveReactiveApparent
(
_VoltageL2N,
_CurrentL2,
_ActivePowerL2,
_ReactivePowerL2,
_ApparentPowerL2
),
l3: AcPhase.FromVoltageCurrentActiveReactiveApparent
(
_VoltageL3N,
_CurrentL3,
_ActivePowerL3,
_ReactivePowerL3,
_ApparentPowerL3
),
frequency: _Frequency
);
}