Introduce Endianness to Modbus lib
This commit is contained in:
parent
270d78b75f
commit
479cdd03ba
|
@ -0,0 +1,10 @@
|
|||
namespace InnovEnergy.Lib.Protocols.Modbus.Clients;
|
||||
|
||||
[Flags]
|
||||
public enum Endianness
|
||||
{
|
||||
LittleEndian32BitIntegers = 0,
|
||||
LittleEndian32Floats = 0,
|
||||
BigEndian32BitIntegers = 1,
|
||||
BigEndian32Floats = 2,
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
using System.Threading.Channels;
|
||||
using InnovEnergy.Lib.Protocols.Modbus.Connections;
|
||||
using InnovEnergy.Lib.Protocols.Modbus.Conversions;
|
||||
using static InnovEnergy.Lib.Protocols.Modbus.Clients.Endianness;
|
||||
|
||||
namespace InnovEnergy.Lib.Protocols.Modbus.Clients;
|
||||
|
||||
|
@ -13,6 +13,7 @@ public abstract class ModbusClient
|
|||
{
|
||||
protected ModbusConnection Connection { get; }
|
||||
protected Byte SlaveId { get; }
|
||||
protected Endianness Endianness { get; }
|
||||
|
||||
|
||||
// TODO: add additional functions: coils...
|
||||
|
@ -40,11 +41,11 @@ public abstract class ModbusClient
|
|||
return WriteRegisters(writeAddress, (IReadOnlyList<UInt16>)values);
|
||||
}
|
||||
|
||||
|
||||
protected ModbusClient(ModbusConnection connection, Byte slaveId)
|
||||
protected ModbusClient(ModbusConnection connection, Byte slaveId, Endianness endianness = LittleEndian32BitIntegers | LittleEndian32Floats)
|
||||
{
|
||||
Connection = connection;
|
||||
SlaveId = slaveId;
|
||||
Endianness = endianness;
|
||||
}
|
||||
|
||||
public void CloseConnection() => Connection.Close();
|
||||
|
|
|
@ -4,13 +4,13 @@ using InnovEnergy.Lib.Protocols.Modbus.Conversions;
|
|||
using InnovEnergy.Lib.Protocols.Modbus.Protocol.Frames.Commands;
|
||||
using InnovEnergy.Lib.Protocols.Modbus.Protocol.Frames.Replies;
|
||||
using InnovEnergy.Lib.Protocols.Modbus.Tcp;
|
||||
using static InnovEnergy.Lib.Protocols.Modbus.Clients.Endianness;
|
||||
|
||||
namespace InnovEnergy.Lib.Protocols.Modbus.Clients;
|
||||
|
||||
using UInt16s = IReadOnlyList<UInt16>;
|
||||
using Coils = IReadOnlyList<Boolean>;
|
||||
|
||||
|
||||
public class ModbusTcpClient : ModbusClient
|
||||
{
|
||||
public const UInt16 DefaultPort = 502;
|
||||
|
@ -20,7 +20,7 @@ public class ModbusTcpClient : ModbusClient
|
|||
private UInt16 NextId() => unchecked(++_Id);
|
||||
|
||||
|
||||
public ModbusTcpClient(ModbusConnection connection, Byte slaveId) : base(connection, slaveId)
|
||||
public ModbusTcpClient(ModbusConnection connection, Byte slaveId, Endianness endianness = LittleEndian32BitIntegers | LittleEndian32Floats) : base(connection, slaveId, endianness)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue