Innovenergy_trunk/csharp/Lib/Devices/EmuMeter/EmuMeterDevice.cs

49 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.EmuMeter;
public class EmuMeterDevice: ModbusDevice<EmuMeterRegisters>
{
public EmuMeterDevice(String hostname, UInt16 port = 502, Byte slaveId = 1) : this(new TcpChannel(hostname, port), slaveId)
{
}
public EmuMeterDevice(Channel channel, Byte slaveId = 1) : base(new ModbusTcpClient(channel, slaveId))
{
}
public EmuMeterDevice(ModbusClient client) : base(client)
{
}
public new EmuMeterRegisters? Read()
{
try
{
return base.Read();
}
catch
{
"Failed to read data from Inverters".WriteLine();
return null;
}
}
public new void Write(EmuMeterRegisters registers)
{
try
{
base.Write(registers);
}
catch (Exception e)
{
// TODO: Log
Console.WriteLine(e);
}
}
}