Innovenergy_trunk/csharp/Lib/Protocols/Modbus/Clients/ModbusClient.cs

38 lines
1.6 KiB
C#
Raw Normal View History

2023-05-04 07:32:35 +00:00
using InnovEnergy.Lib.Protocols.Modbus.Channels;
using InnovEnergy.Lib.Protocols.Modbus.Protocol.Frames.Accessors;
2023-02-16 12:57:06 +00:00
namespace InnovEnergy.Lib.Protocols.Modbus.Clients;
2023-05-04 07:32:35 +00:00
using Booleans = IReadOnlyCollection<Boolean>;
using UInt16s = IReadOnlyCollection<UInt16>;
2023-02-16 12:57:06 +00:00
// TODO: ModbusClient = Framer(TCP/RTU) + Connection(Serial/TCP) + Encoder(binary/ascii) + quirk(+1/0)
// Transport
public abstract class ModbusClient
{
2023-05-04 07:32:35 +00:00
internal Channel Channel { get; }
internal Byte SlaveId { get; }
internal Endian Endian { get; }
2023-03-07 10:19:15 +00:00
2023-02-16 12:57:06 +00:00
// TODO: add additional functions: coils...
2023-05-04 07:32:35 +00:00
public abstract MbData ReadCoils (UInt16 readAddress, UInt16 nValues);
public abstract MbData ReadDiscreteInputs (UInt16 readAddress, UInt16 nValues);
public abstract MbData ReadInputRegisters (UInt16 readAddress, UInt16 nValues);
public abstract MbData ReadHoldingRegisters(UInt16 readAddress, UInt16 nValues);
public abstract UInt16 WriteCoils (UInt16 writeAddress, Booleans coils);
public abstract UInt16 WriteRegisters (UInt16 writeAddress, UInt16s values);
2023-05-04 07:32:35 +00:00
public abstract MbData ReadWriteRegisters (UInt16 readAddress,
UInt16 nbToRead,
UInt16 writeAddress,
UInt16s registersToWrite);
2023-02-16 12:57:06 +00:00
2023-05-04 07:32:35 +00:00
protected ModbusClient(Channel channel, Byte slaveId, Endian endian = Endian.Little)
2023-02-16 12:57:06 +00:00
{
2023-05-04 07:32:35 +00:00
Channel = channel;
SlaveId = slaveId;
Endian = endian;
2023-02-16 12:57:06 +00:00
}
}