Innovenergy_trunk/csharp/Lib/Protocols/Modbus/Protocol/Frames/Replies/WriteCoilsResponseFrame.cs

39 lines
1.2 KiB
C#

using InnovEnergy.Lib.Protocols.Modbus.Protocol.Frames.Accessors;
using InnovEnergy.Lib.Utils;
using static InnovEnergy.Lib.Protocols.Modbus.Protocol.FunctionCode;
namespace InnovEnergy.Lib.Protocols.Modbus.Protocol.Frames.Replies;
public class WriteCoilsResponseFrame : ModbusFrame
{
private const Int32 Size = 6;
public MbWord WriteAddress => Data.WordAt(2);
public MbWord NbWritten => Data.WordAt(4);
internal static Int32 ExpectedSize() => Size;
public WriteCoilsResponseFrame(Byte slave, UInt16 writeAddress, UInt16 nbWritten) : base(Size)
{
SlaveAddress .Set(slave);
FunctionCode .Set(WriteMultipleCoils);
WriteAddress .Set(writeAddress);
NbWritten .Set(nbWritten);
}
private WriteCoilsResponseFrame(Byte[] data) : this (new ArraySegment<Byte>(data) )
{ }
private WriteCoilsResponseFrame(ArraySegment<Byte> data) : base(data)
{
AssertFunctionCode(WriteMultipleCoils);
if (data.Count != Size)
throw new ArgumentException($"Expecting an array of size {Size}", nameof(data));
}
public static WriteCoilsResponseFrame Parse(Byte[] data) => new WriteCoilsResponseFrame(data);
}