ModTest Manual v2.14 - D. Limits on Modbus message sizes

Download manual: PDF HTML

D. Limits on Modbus message sizes

Limits on the size of Modbus messages are confusing and have a chequered history. Take the Write Multiple Coils request (function code 15) as an example:

  • The Write Multiple Coils request contains a count of the number of bytes of data to be written. This byte count is stored in a single byte of the request, and so cannot exceed 255. Each byte of data can contain 8 bits (coils), so at most 2040 (255 * 8) coils can be written.

  • The original Modbus specification imposed no other limits on the size of a Write Multiple Coils request, and so implicitly allowed 2040 coils to be written. However, an appendix listed implementation limits for Modicon controllers, which varied from 32 to 800 coils.

  • The Modbus/TCP specification introduced arbitrary limits on the counts of some Modbus requests. It specified a limit of 800 coils in a Write Multiple Coils request.

  • Version 1 of the current Modbus specification introduced the term "PDU", and imposed arbitrary limits on the PDU size. The PDU for serial communications was limited to 253 bytes, and the PDU for TCP communications was limited to 249 bytes. The PDU for a Write Multiple Coils request requires 6 bytes for the function code, starting address, etc. For serial comms, this leaves 247 (253 - 6) bytes of coil data, which allows 1976 (247 * 8) coils to be written. For TCP comms, there could be 242 (249 - 6) bytes of coil data, which allows 1936 (242 * 8) coils to be written.

    The arbitrary count limit on the Write Multiple Coils request was increased from 800 to 1968 coils.

  • Version 1.1b of the current Modbus specification changed the TCP PDU limit to 253 bytes, making it the same as the serial PDU limit. This would allow 1976 coils to be written using TCP, if it were not for the arbitrary count limit (still at 1968).

Some recommendations for dealing with this confusion:

  • If you want ModTest to conform to the current Modbus specification, set the Max PDU Size to 253, and select the Check Count Limits checkbox.

  • If you are designing a Modbus slave, ignore the arbitrary limits on counts and the PDU size (for example, you should allow 2040 coils to be written in a Write Multiple Coils request - if the device has that many coils). This will allow your slave to work with the maximum number of Modbus masters.

    In order to test the slave, set ModTest's Max PDU Size to 265 or greater, and deselect the Check Count Limits checkbox.

  • If you are designing a Modbus master, you should, by default, conform to the arbitrary count and PDU limits of the current Modbus specification. You will probably also need to provide an option or options for reducing request sizes, since many slave devices cannot cope with large request sizes.