j2mod Illegal Data Address: Resolving Register Reads

Daniel Price1 min read
ModbusOther ManufacturerTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

The read request spans two holding-register offsets, but the process image defines only one. The slave contains offset 47; readMultipleRegisters(1, 47, 2) requests offsets 47 and 48. Because offset 48 is absent, the request returns an Illegal Data Address exception.

Diagnose the requested Modbus range

The arguments identify unit 1, starting offset 47, and a quantity of 2. Modbus applies the quantity across consecutive offsets, so every requested register must exist in the slave process image.

Item Configured or requested value Result
Process-image unit 1 Matches the master request
Defined register Offset 47, value 251 Available
Read range Offset 47, quantity 2 Requests offsets 47 and 48
Missing register Offset 48 Causes the range to be invalid

Correct the register definition or read quantity

Choose the correction that matches the intended data model:

  1. If the master needs only the value at offset 47, change the quantity to 1:
    Register[] data1 = tcpMaster.readMultipleRegisters(1, 47, 1);
  2. If the master needs two values, add a register at offset 48 before opening the slave, then retain the quantity of 2:
    SimpleProcessImage spi = new SimpleProcessImage(1);
    spi.addRegister(47, new SimpleRegister(251));
    spi.addRegister(48, new SimpleRegister(secondValue));
    slave.addProcessImage(1, spi);

Keep the addressing interpretation consistent

Treat 47 in this code as the process-image offset requested by the API. Do not silently substitute a display-style register number from another Modbus application. The evidence shows that another simulator accepts the request, but it does not establish whether that simulator predefines offset 48 or applies a different address presentation.

Verify the correction

Reconnect the master and repeat the read with either quantity 1 or both offsets defined. Confirm that the request completes without Illegal Data Address and that the first returned register contains 251. For a two-register read, also confirm that the second returned element corresponds to offset 48.

FAQ

Why does j2mod return Illegal Data Address for register 47?

The request starts at offset 47 but asks for 2 registers, so it also requires offset 48. Only offset 47 is defined in the process image.

How do I read only j2mod register 47?

Use readMultipleRegisters(1, 47, 1). The final argument is the quantity of consecutive registers, not an ending address.

How do I make the two-register j2mod read succeed?

Add registers at both offsets 47 and 48 to process image 1, then call readMultipleRegisters(1, 47, 2).

Back to blog