Possible mistake in Modbus App. Protocol Spec. document V1.1b

V

Thread Starter

Volkan Celik

Hello,

For ILLEGAL DATA ADDRESS Exception Code, on page 49 of 'Modbus Application Protocol Specification V1.1b' document, it says that

"... For a controller with 100 registers, the PDU addresses the first register as 0, and the last one as 99. If a request is submitted with a starting register address of 96 and a quantity of registers of 4, then this request will successfully operate (address-wise at least) on registers 96, 97, 98, 99. ...".

There is 'Write Multiple Registers state diagram' on page 31 of the same document and it says that if 'Starting Address and Starting Address + Quantity of Registers' are OK, Modbus Server won't give the exception code 0x02.

For the same example above, if I execute 96 + 4 (Starting Address + Quantity of Registers), it gives 100. And 100 isn't a suitable address. So Modbus has to give an exception code 0x02 according to state diagram. But according to page 49, it is not a problem because server writes on registers 96, 97, 98, 99 successfully and I agree with this.

My suggestion is; in the state diagram on page 31, the comparison has to change into this:

If 'Starting Address and Starting Address + Quantity of Registers - 1' are OK, Modbus Server won't give the exception code 0x02. I mean
Starting Address = = OK AND Starting Address + Quantity of Registers - 1 = = OK .

Am I wrong? What do you think?
 
There is no contradiction between the two pages. Page 31 says "Starting Address + Quantity of Registers == OK". That is a logical equation, not a mathematical formula. "OK" means "correct" by whatever means you determine it to be.

For your example, you would calculate it as:

A = starting address.
Q = quantity of registers.
M = maximum register address.

OK = M <= (A + Q - 1)

giving:

OK = 99 <= (96 + 4 - 1)

The result is OK == true, because 99 is less than or equal to 99.

You have to subtract 1 because register addressing starts at 0. This is a *very* common thing to deal with in most programming languages where array indexing starts at 0.

I'm not sure what software you are writing, but you may want to have a look through your code for any other "off by one" errors you might have.
 
Top