Commit 8d008e4b authored by Andreas Müller's avatar Andreas Müller Committed by GitHub

Merge pull request #4 from hmarius/master

Fix for Modbus.Tcp.ModbusServer HandleWriteMultipleRegisters 
parents 64361c55 7f777d98
Pipeline #28 passed with stage
in 49 seconds
......@@ -146,7 +146,7 @@ namespace AMWD.Modbus.Tcp.Protocol
var fn = (byte)Function;
if (IsError)
{
fn = (byte)(fn & Consts.ErrorMask);
fn = (byte)(fn | Consts.ErrorMask);
buffer.AddByte((byte)ErrorCode);
}
else
......
......@@ -932,7 +932,8 @@ namespace AMWD.Modbus.Tcp.Server
{
var response = new Response(request);
if (request.Count < Consts.MinCount || request.Count > Consts.MaxRegisterCountWrite || request.Count * 2 != request.Data.Length)
//request.Data contains [byte count] [data]..[data]
if (request.Count < Consts.MinCount || request.Count > Consts.MaxRegisterCountWrite || request.Count * 2 != request.Data.Length - 1)
{
response.ErrorCode = ErrorCode.IllegalDataValue;
}
......@@ -948,7 +949,7 @@ namespace AMWD.Modbus.Tcp.Server
for (int i = 0; i < request.Count; i++)
{
var addr = (ushort)(request.Address + i);
var val = request.Data.GetUInt16(i * 2);
var val = request.Data.GetUInt16(i * 2 + 1);
var register = new Register { Address = addr, Value = val };
SetHoldingRegister(request.DeviceId, register);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment