diff --git a/Modbus/IO/ModbusRtuTransport.cs b/Modbus/IO/ModbusRtuTransport.cs index 9955783..8563d89 100644 --- a/Modbus/IO/ModbusRtuTransport.cs +++ b/Modbus/IO/ModbusRtuTransport.cs @@ -66,7 +66,8 @@ public static int ResponseBytesToRead(byte[] frameStart) Modbus.ReadCoils or Modbus.ReadInputs or Modbus.ReadHoldingRegisters or - Modbus.ReadInputRegisters + Modbus.ReadInputRegisters or + Modbus.ReadWriteMultipleRegisters => frameStart[2] + 1, Modbus.WriteSingleCoil or @@ -134,4 +135,4 @@ internal override byte[] ReadRequest() return frame; } -} \ No newline at end of file +} diff --git a/Modbus/Message/AbstractModbusMessage.cs b/Modbus/Message/AbstractModbusMessage.cs index cf689ab..4c96960 100644 --- a/Modbus/Message/AbstractModbusMessage.cs +++ b/Modbus/Message/AbstractModbusMessage.cs @@ -39,7 +39,7 @@ public byte SlaveAddress set => MessageImpl.SlaveAddress = value; } - public byte[] MessageFrame => + public virtual byte[] MessageFrame => MessageImpl.MessageFrame; public virtual byte[] ProtocolDataUnit => @@ -62,4 +62,4 @@ public void Initialize(byte[] frame) } protected abstract void InitializeUnique(byte[] frame); -} \ No newline at end of file +} diff --git a/Modbus/Message/ReadWriteMultipleRegistersRequest.cs b/Modbus/Message/ReadWriteMultipleRegistersRequest.cs index 5de8923..c0afb71 100644 --- a/Modbus/Message/ReadWriteMultipleRegistersRequest.cs +++ b/Modbus/Message/ReadWriteMultipleRegistersRequest.cs @@ -28,6 +28,20 @@ public ReadWriteMultipleRegistersRequest( writeData); } + public override byte[] MessageFrame + { + get + { + byte[]? pdu = ProtocolDataUnit; + MemoryStream frame = new(1 + pdu.Length); + + frame.WriteByte(SlaveAddress); + frame.Write(pdu, 0, pdu.Length); + + return frame.ToArray(); + } + } + public override byte[] ProtocolDataUnit { get @@ -86,4 +100,4 @@ protected override void InitializeUnique(byte[] frame) ReadRequest = ModbusMessageFactory.CreateModbusMessage(readFrame); WriteRequest = ModbusMessageFactory.CreateModbusMessage(writeFrame); } -} \ No newline at end of file +}