diff --git a/csharp/Lib/Protocols/Modbus/Conversions/ModbusRegisters.Bit.cs b/csharp/Lib/Protocols/Modbus/Conversions/ModbusRegisters.Bit.cs index e2e02ed7e..2ab1061dc 100644 --- a/csharp/Lib/Protocols/Modbus/Conversions/ModbusRegisters.Bit.cs +++ b/csharp/Lib/Protocols/Modbus/Conversions/ModbusRegisters.Bit.cs @@ -1,4 +1,5 @@ using System.Collections; +using InnovEnergy.Lib.Utils; namespace InnovEnergy.Lib.Protocols.Modbus.Conversions; @@ -8,7 +9,7 @@ public partial class ModbusRegisters { var offset = index - StartRegister; - var byteArray = BitConverter.GetBytes(Registers[offset]).Reverse().ToArray(); + var byteArray = Registers[offset].Apply(BitConverter.GetBytes).Reverse().ToArray(); var bitArray = new BitArray(byteArray); return bitArray.Get(bitIndex); @@ -18,7 +19,7 @@ public partial class ModbusRegisters { var offset = index - StartRegister; - var byteArray = BitConverter.GetBytes(Registers[offset]).Reverse().ToArray(); + var byteArray = Registers[offset].Apply(BitConverter.GetBytes).Reverse().ToArray(); var bitArray = new BitArray(byteArray); bitArray.Set(bitIndex, value); diff --git a/csharp/Lib/Protocols/Modbus/Conversions/ModbusRegisters.Single.cs b/csharp/Lib/Protocols/Modbus/Conversions/ModbusRegisters.Single.cs index a6408185e..26f5776e6 100644 --- a/csharp/Lib/Protocols/Modbus/Conversions/ModbusRegisters.Single.cs +++ b/csharp/Lib/Protocols/Modbus/Conversions/ModbusRegisters.Single.cs @@ -9,7 +9,7 @@ public partial class ModbusRegisters var bytearray = BitConverter.GetBytes(value).Reverse().ToArray(); var value32 = BitConverter.ToUInt32(bytearray); - Registers[index - StartRegister] = (UInt16)(value32 >> 16); + Registers[index - StartRegister ] = (UInt16)(value32 >> 16); Registers[index - StartRegister + 1] = (UInt16)(value32 & 0xFFFF); } diff --git a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/Accessors.cs b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/Accessors.cs index 583ad6979..92282070e 100644 --- a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/Accessors.cs +++ b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/Accessors.cs @@ -9,8 +9,8 @@ public static class Accessors public static MbWord WordAt (this ArraySegment data, Byte i) => new MbWord(data, i); public static MbAddress AddressAt(this ArraySegment data, Byte i) => new MbAddress(data, i); - public static MbWords WordsAt(this ArraySegment data, Byte i) => new MbWords(data, i); - public static MbBits BitsAt (this ArraySegment data, Byte i) => new MbBits(data, i); + public static MbRegisters RegistersAt(this ArraySegment data, Byte i) => new MbRegisters(data, i); + public static MbBits BitsAt (this ArraySegment data, Byte i) => new MbBits(data, i); public static MbByte ByteAt(this ArraySegment data,Byte i) where T : struct, IConvertible => new MbByte(data, i); diff --git a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Commands/ReadWriteRegistersCommandFrame.cs b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Commands/ReadWriteRegistersCommandFrame.cs index 1e4c8366f..57f86d379 100644 --- a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Commands/ReadWriteRegistersCommandFrame.cs +++ b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Commands/ReadWriteRegistersCommandFrame.cs @@ -16,7 +16,7 @@ internal class ReadWriteRegistersCommandFrame : ModbusFrame public MbAddress WriteAddress => Data.AddressAt(6); public MbWord NbToWrite => Data.WordAt(8); public MbByte ByteCount => Data.ByteAt(10); - public MbWords RegistersToWrite => Data.WordsAt(11); + public MbRegisters RegistersToWrite => Data.RegistersAt(11); public Int32 ExpectedResponseSize => ReadWriteRegistersResponseFrame.ExpectedSize(NbToRead); diff --git a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Commands/WriteRegistersCommandFrame.cs b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Commands/WriteRegistersCommandFrame.cs index af925ff9e..8eb4ca915 100644 --- a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Commands/WriteRegistersCommandFrame.cs +++ b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Commands/WriteRegistersCommandFrame.cs @@ -14,7 +14,7 @@ internal class WriteRegistersCommandFrame : ModbusFrame public MbAddress WriteAddress => Data.AddressAt(2); public MbWord NbOfRegisters => Data.WordAt(4); public MbByte ByteCount => Data.ByteAt(6); - public MbWords RegistersToWrite => Data.WordsAt(7); + public MbRegisters RegistersToWrite => Data.RegistersAt(7); public Int32 ExpectedResponseSize => WriteRegistersResponseFrame.ExpectedSize(); diff --git a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadHoldingRegistersResponseFrame.cs b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadHoldingRegistersResponseFrame.cs index 7fcd77983..ba8b3e707 100644 --- a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadHoldingRegistersResponseFrame.cs +++ b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadHoldingRegistersResponseFrame.cs @@ -11,7 +11,7 @@ internal class ReadHoldingRegistersResponseFrame : ModbusFrame internal new const Int32 MinSize = 3; public MbByte ByteCount => Data.ByteAt(2); - public MbWords RegistersRead => Data.WordsAt(3); + public MbRegisters RegistersRead => Data.RegistersAt(3); public ReadHoldingRegistersResponseFrame(Byte slave, UInt16s registersRead) : base(ExpectedSize(registersRead.Count)) diff --git a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadInputRegistersResponseFrame.cs b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadInputRegistersResponseFrame.cs index 29cebda39..bb301e638 100644 --- a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadInputRegistersResponseFrame.cs +++ b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadInputRegistersResponseFrame.cs @@ -12,7 +12,7 @@ internal class ReadInputRegistersResponseFrame : ModbusFrame internal new const Int32 MinSize = 3; public MbByte ByteCount => Data.ByteAt(2); - public MbWords RegistersRead => Data.WordsAt(3); + public MbRegisters RegistersRead => Data.RegistersAt(3); public ReadInputRegistersResponseFrame(Byte slave, UInt16s registersRead) : base(ExpectedSize(registersRead.Count)) { diff --git a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadWriteRegistersCommandFrame.cs b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadWriteRegistersCommandFrame.cs index 43eed5e21..ce7ecf2da 100644 --- a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadWriteRegistersCommandFrame.cs +++ b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/ReadWriteRegistersCommandFrame.cs @@ -12,7 +12,7 @@ internal class ReadWriteRegistersResponseFrame : ModbusFrame internal new const Int32 MinSize = 3; public MbByte ByteCount => Data.ByteAt(2); - public MbWords RegistersRead => Data.WordsAt(3); + public MbRegisters RegistersRead => Data.RegistersAt(3); public ReadWriteRegistersResponseFrame(Byte slave, UInt16s registersRead) : base(ExpectedSize(registersRead.Count)) {