47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
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.PLVario2Meter;
|
|
|
|
public class PlVarioMeterDevice: ModbusDevice<PlVarioMeterRegisters>
|
|
{
|
|
public PlVarioMeterDevice(String hostname, UInt16 port = 502, Byte slaveId = 2) : this(new TcpChannel(hostname, port), slaveId)
|
|
{
|
|
}
|
|
|
|
public PlVarioMeterDevice(Channel channel, Byte slaveId = 2) : base(new ModbusTcpClient(channel, slaveId))
|
|
{
|
|
}
|
|
|
|
public PlVarioMeterDevice(ModbusClient client) : base(client)
|
|
{
|
|
}
|
|
|
|
public new PlVarioMeterRegisters? Read()
|
|
{
|
|
try
|
|
{
|
|
return base.Read();
|
|
}
|
|
catch
|
|
{
|
|
"Failed to read data from PLVario-II meter".WriteLine();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public new void Write(PlVarioMeterRegisters registers)
|
|
{
|
|
try
|
|
{
|
|
base.Write(registers);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// TODO: Log
|
|
Console.WriteLine(e);
|
|
}
|
|
}
|
|
} |