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

49 lines
1.1 KiB
C#
Raw Normal View History

2023-05-06 13:41:39 +00:00
using InnovEnergy.Lib.Protocols.Modbus.Channels;
2023-02-16 12:57:06 +00:00
using InnovEnergy.Lib.Protocols.Modbus.Clients;
2023-05-06 13:41:39 +00:00
using InnovEnergy.Lib.Protocols.Modbus.Slaves;
using InnovEnergy.Lib.Utils;
2023-02-16 12:57:06 +00:00
namespace InnovEnergy.Lib.Devices.EmuMeter;
2023-05-06 13:41:39 +00:00
public class EmuMeterDevice: ModbusDevice<EmuMeterRegisters>
2023-02-16 12:57:06 +00:00
{
2023-05-06 13:41:39 +00:00
public EmuMeterDevice(String hostname, UInt16 port = 502, Byte slaveId = 1) : this(new TcpChannel(hostname, port), slaveId)
2023-02-16 12:57:06 +00:00
{
}
2023-05-06 13:41:39 +00:00
public EmuMeterDevice(Channel channel, Byte slaveId = 1) : base(new ModbusTcpClient(channel, slaveId))
2023-02-16 12:57:06 +00:00
{
}
2023-03-01 12:35:33 +00:00
2023-05-06 13:41:39 +00:00
public EmuMeterDevice(ModbusClient client) : base(client)
2023-02-16 12:57:06 +00:00
{
}
2023-06-13 10:54:06 +00:00
public new EmuMeterRegisters? Read()
{
try
{
return base.Read();
}
catch
2023-06-13 10:54:06 +00:00
{
2023-07-10 08:34:51 +00:00
"Failed to read data from EmuMeter".WriteLine();
2023-06-13 10:54:06 +00:00
return null;
}
}
public new void Write(EmuMeterRegisters registers)
{
try
{
base.Write(registers);
}
catch (Exception e)
{
// TODO: Log
Console.WriteLine(e);
}
}
2023-02-16 12:57:06 +00:00
}