Search code examples
memorymodbus

Modbus register adress space not linear?


I'm currently developing a modbus server to control a device.

The device manual says about holding registers:

Adress 6000: ValueA, 2 Byte
Adress 6001: ValueB, 1 Byte; ValueC, 4 Byte; ValueD, 4 Byte 
Adress 6005: ValueE, 2 Byte

The only supported read function is FC 03 / Read Multiple Holding Registers

To my knowledge, one can see the register as a memory block of numbered 16Bit values, and could read it in one go by reading 6 registers / 12 Byte beginning at 6000.

I think the 1Byte-value isn't an issue, the register simply contains a value not exceeding 255.

But expanding the table above gives:

Adress 6000:      ValueA, 2 Byte
Adress 6001:      ValueB, 1 Byte
Adress 6002-6003: ValueC, 4 Byte
Adress 6004-6005: ValueD, 4 Byte 
Adress 6005:      ValueE, 2 Byte

so, there is an overlap last line at 6005.

My device manual is full of such occurences, and meanwhile, I'm thinking that modbus registers ain't such a simple, linear memory as I thought.

Does anybody know if modbus registers are linear, or not?


Solution

  • I stumbled across a similar situation and asked about it in a more specialized forum. The "to long, didn`t read" was, that the address space is linear most of the time, but not always.

    Check out the following example: Example showcasing how registers don't always be linear.

    Excuse the German parts, but what you can see here, is that register address 0x2021 holds data made up of eight words or eight 16-bit blocks. Following your above logic you would expect the second word to be stored in the register 0x2022, but I checked on my local device and they are not the same. So, in summary, there are some devices out there which decide, that they give one register more memory than it's ought to have. So, register 0x2021 really holds 8 words on his own and does not use register 0x2022 to hold memory. you might have a similar case.