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

39 lines
1.2 KiB
C#
Raw Permalink Normal View History

2023-02-16 12:57:06 +00:00
using InnovEnergy.Lib.Protocols.Modbus.Protocol.Frames.Accessors;
2023-06-13 11:03:36 +00:00
using InnovEnergy.Lib.Utils;
2023-02-16 12:57:06 +00:00
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;
2023-03-10 12:46:46 +00:00
public MbWord WriteAddress => Data.WordAt(2);
public MbWord NbWritten => Data.WordAt(4);
2023-02-16 12:57:06 +00:00
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)
{
2023-06-13 11:03:36 +00:00
AssertFunctionCode(WriteMultipleCoils);
2023-02-16 12:57:06 +00:00
if (data.Count != Size)
throw new ArgumentException($"Expecting an array of size {Size}", nameof(data));
}
2023-05-04 07:32:35 +00:00
public static WriteCoilsResponseFrame Parse(Byte[] data) => new WriteCoilsResponseFrame(data);
2023-02-16 12:57:06 +00:00
}