diff --git a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/Accessors.cs b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/Accessors.cs index 92282070e..45f8f8b6a 100644 --- a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/Accessors.cs +++ b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/Accessors.cs @@ -8,10 +8,7 @@ public static class Accessors public static MbByte ByteAt (this ArraySegment data, Byte i) => new MbByte(data, i); 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 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 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 MbByte ByteAt(this ArraySegment data,Byte i) where T : struct, IConvertible => new MbByte(data, i); } \ No newline at end of file diff --git a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/MbRegisters.cs b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/MbWords.cs similarity index 71% rename from csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/MbRegisters.cs rename to csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/MbWords.cs index a2124a9fa..fdc7be0c2 100644 --- a/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/MbRegisters.cs +++ b/csharp/Lib/Protocols/Modbus/Protocol/Frames/Accessors/MbWords.cs @@ -3,20 +3,18 @@ using InnovEnergy.Lib.Utils; namespace InnovEnergy.Lib.Protocols.Modbus.Protocol.Frames.Accessors; -public readonly struct MbRegisters : IReadOnlyList +public readonly struct MbWords : IReadOnlyList { private readonly ArraySegment _Data; - internal MbRegisters(ArraySegment data, Byte startIndex) : this(data, startIndex, CountWords(data, startIndex)) + internal MbWords(ArraySegment data, Byte startIndex) : this(data, startIndex, CountWords(data, startIndex)) { } - - - internal MbRegisters(ArraySegment data, Byte startIndex, UInt16 wordCount) : this(data.Array!, startIndex, wordCount) + internal MbWords(ArraySegment data, Byte startIndex, UInt16 wordCount) : this(data.Array!, startIndex, wordCount) { } - internal MbRegisters(Byte[] data, Byte startIndex, UInt16 wordCount) + internal MbWords(Byte[] data, Byte startIndex, UInt16 wordCount) { _Data = new ArraySegment(data, startIndex, wordCount * 2); } @@ -62,6 +60,8 @@ public readonly struct MbRegisters : IReadOnlyList public UInt16 this[Int32 index] { + // a single register is always big endian (according to standard) + get { var i = index * 2; @@ -71,5 +71,12 @@ public readonly struct MbRegisters : IReadOnlyList return (UInt16) (hi | lo); } + + set + { + var i = index * 2; + _Data[i + 0] = (Byte)(value >> 8); + _Data[i + 1] = (Byte)(value & 0xFF); + } } } \ No newline at end of file