2023-02-16 12:57:06 +00:00
|
|
|
using InnovEnergy.Lib.Protocols.Modbus.Clients;
|
|
|
|
using InnovEnergy.Lib.Protocols.Modbus.Connections;
|
|
|
|
|
|
|
|
namespace InnovEnergy.Lib.Devices.Battery48TL;
|
|
|
|
|
|
|
|
public class Battery48TlDevice
|
|
|
|
{
|
|
|
|
private ModbusClient Modbus { get; }
|
|
|
|
|
|
|
|
public Battery48TlDevice(String device, Byte nodeId)
|
|
|
|
{
|
|
|
|
var serialConnection = new ModbusSerialConnection(device,
|
|
|
|
Constants.BaudRate,
|
|
|
|
Constants.Parity,
|
|
|
|
Constants.DataBits,
|
|
|
|
Constants.StopBits,
|
|
|
|
Constants.Timeout);
|
|
|
|
|
|
|
|
Modbus = new ModbusRtuClient(serialConnection, nodeId);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Battery48TlDevice(ModbusClient modbus) // TODO : remove nullable
|
|
|
|
{
|
|
|
|
Modbus = modbus;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Battery48TlDevice Fake() // TODO : remove nullable
|
|
|
|
{
|
|
|
|
return new Battery48TlDevice(null!);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Battery48TLStatus? ReadStatus() //Already try catch is implemented
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-03-01 09:41:13 +00:00
|
|
|
return Modbus
|
|
|
|
.ReadInputRegisters(Constants.BaseAddress, Constants.NoOfRegisters)
|
|
|
|
.ParseBatteryStatus();
|
2023-02-16 12:57:06 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2023-02-23 12:45:09 +00:00
|
|
|
Console.WriteLine(e.Message + " Battery ");
|
2023-02-16 12:57:06 +00:00
|
|
|
Modbus.CloseConnection();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|