Update the sodistoremax with old Amax and Adam6063D
This commit is contained in:
parent
1a47c8884d
commit
43520c9041
|
|
@ -0,0 +1,72 @@
|
||||||
|
using InnovEnergy.Lib.Devices.Adam6360D;
|
||||||
|
using InnovEnergy.Lib.Devices.Amax5070;
|
||||||
|
using InnovEnergy.Lib.Protocols.Modbus.Channels;
|
||||||
|
|
||||||
|
namespace InnovEnergy.App.SodiStoreMax.SaliMaxRelays;
|
||||||
|
|
||||||
|
public class RelaysDevice
|
||||||
|
{
|
||||||
|
private Adam6360DDevice AdamDevice { get; }
|
||||||
|
|
||||||
|
public RelaysDevice(String hostname) => AdamDevice = new Adam6360DDevice(hostname, 2);
|
||||||
|
public RelaysDevice(Channel channel) => AdamDevice = new Adam6360DDevice(channel, 2);
|
||||||
|
|
||||||
|
|
||||||
|
public RelaysRecord? Read()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return AdamDevice.Read();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
$"Failed to read from {nameof(RelaysDevice)}\n{e}".LogError();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(RelaysRecord r)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
AdamDevice.Write(r);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
$"Failed to write to {nameof(RelaysDevice)}\n{e}".LogError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class RelaysDeviceAmax
|
||||||
|
{
|
||||||
|
private Amax5070Device AmaxDevice { get; }
|
||||||
|
|
||||||
|
public RelaysDeviceAmax(Channel channel) => AmaxDevice = new Amax5070Device(channel);
|
||||||
|
|
||||||
|
public RelaysRecordAmax? Read()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return AmaxDevice.Read();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
$"Failed to read from {nameof(RelaysDeviceAmax)}\n{e}".LogError();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(RelaysRecordAmax r)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
AmaxDevice.Write(r);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
$"Failed to write to {nameof(RelaysDeviceAmax)}\n{e}".LogError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
using InnovEnergy.Lib.Devices.Adam6360D;
|
||||||
|
using InnovEnergy.Lib.Devices.Amax5070;
|
||||||
|
namespace InnovEnergy.App.SodiStoreMax.SaliMaxRelays;
|
||||||
|
|
||||||
|
public interface IRelaysRecord
|
||||||
|
{
|
||||||
|
Boolean K1GridBusIsConnectedToGrid { get; }
|
||||||
|
Boolean K2IslandBusIsConnectedToGridBus { get; }
|
||||||
|
IEnumerable<Boolean> K3InverterIsConnectedToIslandBus { get; }
|
||||||
|
Boolean FiWarning { get; }
|
||||||
|
Boolean FiError { get; }
|
||||||
|
Boolean K2ConnectIslandBusToGridBus { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RelaysRecord : IRelaysRecord
|
||||||
|
{
|
||||||
|
private readonly Adam6360DRegisters _Regs;
|
||||||
|
|
||||||
|
private RelaysRecord(Adam6360DRegisters regs) => _Regs = regs;
|
||||||
|
|
||||||
|
public Boolean K1GridBusIsConnectedToGrid => _Regs.DigitalInput6;
|
||||||
|
public Boolean K2IslandBusIsConnectedToGridBus => !_Regs.DigitalInput4;
|
||||||
|
|
||||||
|
public IEnumerable<Boolean> K3InverterIsConnectedToIslandBus
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
yield return K3Inverter1IsConnectedToIslandBus;
|
||||||
|
yield return K3Inverter2IsConnectedToIslandBus;
|
||||||
|
yield return K3Inverter3IsConnectedToIslandBus;
|
||||||
|
yield return K3Inverter4IsConnectedToIslandBus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean K3Inverter1IsConnectedToIslandBus => !_Regs.DigitalInput0;
|
||||||
|
public Boolean K3Inverter2IsConnectedToIslandBus => !_Regs.DigitalInput1;
|
||||||
|
public Boolean K3Inverter3IsConnectedToIslandBus => !_Regs.DigitalInput2;
|
||||||
|
public Boolean K3Inverter4IsConnectedToIslandBus => !_Regs.DigitalInput3;
|
||||||
|
|
||||||
|
public Boolean FiWarning => !_Regs.DigitalInput5;
|
||||||
|
public Boolean FiError => !_Regs.DigitalInput7;
|
||||||
|
|
||||||
|
public Boolean K2ConnectIslandBusToGridBus { get => _Regs.Relay0; set => _Regs.Relay0 = value;}
|
||||||
|
|
||||||
|
public static implicit operator Adam6360DRegisters(RelaysRecord d) => d._Regs;
|
||||||
|
public static implicit operator RelaysRecord(Adam6360DRegisters d) => new RelaysRecord(d);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RelaysRecordAmax : IRelaysRecord
|
||||||
|
{
|
||||||
|
private readonly Amax5070Registers _Regs;
|
||||||
|
|
||||||
|
private RelaysRecordAmax(Amax5070Registers regs) => _Regs = regs;
|
||||||
|
|
||||||
|
public Boolean K1GridBusIsConnectedToGrid => _Regs.DigitalInput22;
|
||||||
|
public Boolean K2IslandBusIsConnectedToGridBus => !_Regs.DigitalInput20;
|
||||||
|
|
||||||
|
public IEnumerable<Boolean> K3InverterIsConnectedToIslandBus
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
yield return K3Inverter1IsConnectedToIslandBus;
|
||||||
|
yield return K3Inverter2IsConnectedToIslandBus;
|
||||||
|
yield return K3Inverter3IsConnectedToIslandBus;
|
||||||
|
yield return K3Inverter4IsConnectedToIslandBus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean K3Inverter1IsConnectedToIslandBus => !_Regs.DigitalInput16;
|
||||||
|
public Boolean K3Inverter2IsConnectedToIslandBus => !_Regs.DigitalInput17;
|
||||||
|
public Boolean K3Inverter3IsConnectedToIslandBus => !_Regs.DigitalInput18;
|
||||||
|
public Boolean K3Inverter4IsConnectedToIslandBus => !_Regs.DigitalInput19;
|
||||||
|
|
||||||
|
public Boolean FiWarning => !_Regs.DigitalInput21;
|
||||||
|
public Boolean FiError => !_Regs.DigitalInput23;
|
||||||
|
|
||||||
|
public Boolean K2ConnectIslandBusToGridBus { get => _Regs.Relay23; set => _Regs.Relay23 = value;}
|
||||||
|
|
||||||
|
public static implicit operator Amax5070Registers(RelaysRecordAmax d) => d._Regs;
|
||||||
|
public static implicit operator RelaysRecordAmax(Amax5070Registers d) => new RelaysRecordAmax(d);
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue