Search code examples
modbus

Can a holding register in the middle of readable holding registers be an "IllegalDataAddress"?


While unit testing a Modbus driver I'm writing I experienced the following:

  1. I can read holding registers 0 to 1022.
  2. I can't read holding registers 1022 to 13000. I get an illegal data address error code.
  3. I can read holding registers 13000 to 25000.

I would have expected devices supporting Modbus to behave in one of the following two ways:

  1. Every device supports the full range of addresses from 0x0000 to 0xFFFF.
  2. Every device supports a range of addresses from 0x0000 to N, where N < 0xFFFF.

Do any of you more experienced people know:

  1. Is Assumption 1 or 2 about the expected behavior of Modbus devices correct?
  2. Are there other reasons beside being out of bounds for an address to be an illegal data address?

Solution

  • Both assumptions are false. It's completely up to the device to decide which registers to support. Some devices are nice and support a wide range of registers, even if they're unused. Most that I've used don't, though. They'll use groups of registers, like your device.

    Also, not all Modbus devices support all the Modbus function codes. Just because it's defined by the Modbus protocol standard doesn't necessarily mean the device will support it.

    The key thing is to stick to the addresses defined in the device's manual. The manual is usually required reading, otherwise you'll just be guessing at the ranges, units, and scaling.