3
\$\begingroup\$

MODBUS function code 16 is "Write Holding Registers". The function command structure is:

Address (1 byte)
Function code (1 byte)
First register address (2 bytes)
Number of registers to write (2 bytes)
Number of bytes to follow (1 byte)
Data (N bytes)
CRC (2 bytes)

If registers are always 2 bytes long, then aren't the number of registers and number of bytes redundant pieces of information? Under what circumstances would

number of bytes = number of registers * 2

not be true?

If I were to receive a command where this was not the case, should I reject the command?

\$\endgroup\$
4
\$\begingroup\$

It is redundant and if you look at the MODBUS Application Protocol Specification figure 22 on page 31, it specifies to check for:(0x0001 ≤ Quantity of Registers ≤ 0x007B) AND (Byte Count == Quantity of Registers x 2), if not true then return ExceptionCode 03 (ILLEGAL DATA VALUE).

I would guess that they were trying to follow a consistent format which in this case resulted in the redundancy.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.