Innovenergy_trunk/csharp/Lib/Devices/Kaco92L3/KacoDevice.cs

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