48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using InnovEnergy.Lib.Protocols.Modbus.Clients;
|
|
using InnovEnergy.Lib.Protocols.Modbus.Connections;
|
|
using static InnovEnergy.Lib.Devices.Battery48TL.Constants;
|
|
|
|
namespace InnovEnergy.Lib.Devices.Battery48TL;
|
|
|
|
public class Battery48TlDevice
|
|
{
|
|
private ModbusClient Modbus { get; }
|
|
|
|
public Battery48TlDevice(String device, Byte nodeId)
|
|
{
|
|
var serialConnection = new ModbusSerialConnection(device,
|
|
BaudRate,
|
|
Parity,
|
|
DataBits,
|
|
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
|
|
{
|
|
return Modbus
|
|
.ReadInputRegisters(BaseAddress, NoOfRegisters)
|
|
.ParseBatteryStatus();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message + " Battery ");
|
|
Modbus.CloseConnection();
|
|
return null;
|
|
}
|
|
}
|
|
} |