47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
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
|
|
{
|
|
return Modbus
|
|
.ReadInputRegisters(Constants.BaseAddress, Constants.NoOfRegisters)
|
|
.ParseBatteryStatus();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message + " Battery ");
|
|
Modbus.CloseConnection();
|
|
return null;
|
|
}
|
|
}
|
|
} |