EasyModbusTCP.NET icon indicating copy to clipboard operation
EasyModbusTCP.NET copied to clipboard

There are differences between index of modbus server register array and index of modbus client register array

Open aigefjk opened this issue 4 years ago • 3 comments

When I test V5.5 library,I found there are differences between Modbus server register index and Modbus client register index.

Index of registers Modbus client class used is from 0 , while index of registers Modbus server class used is from 1.

e.g:

If you want to get value in holding register 0, you need pass index 0 to modbus client method but in modbus server method you must pass index 1 to the method.

public void WriteSingleRegister(int Addr, short Value) { MyServer.holdingRegisters.localArray[Addr + 1] = Value; }

aigefjk avatar Sep 09 '21 07:09 aigefjk

For historical reasons, user reference numbers were expressed as decimal numbers with a starting offset of 1. However MODBUS uses the more natural software interpretation of an unsigned integer index starting at zero.

So a MODBUS message requesting the read of a register at offset 0 would return the value known to the application programmer as found in register 4:00001 (memory type 4 = output register, reference 00001).

Padanian avatar Sep 09 '21 08:09 Padanian

For historical reasons, user reference numbers were expressed as decimal numbers with a starting offset of 1. However MODBUS uses the more natural software interpretation of an unsigned integer index starting at zero.

So a MODBUS message requesting the read of a register at offset 0 would return the value known to the application programmer as found in register 4:00001 (memory type 4 = output register, reference 00001).


Modbus client myClient.WriteSingleRegister(0, Value) update value in register 4:00001, but in modbus server localArray[1] presents 4:00001 , that not keep the same style.

aigefjk avatar Sep 09 '21 09:09 aigefjk