Extensions of the Modbus protocol to handle large values
The official Modbus protocol (in both the original Modbus specification and the current specification) only allows 1-bit and 16-bit integer values to be transferred. Many manufacturers have extended the protocol to allow 32-bit and 64-bit values, and also to allow floating-point values. Fortunately, everyone seems to have used the IEEE format for floating-point numbers, but that is where the agreement ends.
Our Modbus products can be configured to handle all implementations of 32/64-bit values that we know of using three settings:
- Little endian
- Word registers
- Word count
Little endian. Modbus is a "big-endian" protocol: that is, the more significant byte of a 16-bit value is sent before the less significant byte. It seems obvious that 32-bit and 64-bit values should also be transferred using big-endian order. However, some manufacturers have chosen to treat 32-bit and 64-bit values as being composed of 16-bit words, and transfer the words in little-endian order. For example, the 32-bit value 0x12345678 would be transferred as 0x56 0x78 0x12 0x34. You should check the Little endian checkbox to use this mixed ordering.
Word registers. Each register in the Modbus protocol holds a single (16-bit) value. The simplest way to extend the protocol to handle 16-bit and 32-bit values is to allow registers that contain these larger values. However, some manufacturers have chosen to keep to the 16-bit register size, and use 2 registers to hold a 32-bit value, and 4 registers to hold a 64-bit value. For example, if a 32-bit value is stored at address 100, then register 100 would hold one half of the value and register 101 would hold the other half of the value. Some devices will actually allow you to access the halves of the value independently; others will only allow accesses that transfer the complete value (thus making address 101 in the example an invalid address). You should check the Word registers checkbox to use multiple registers to store large values, and leave the checkbox unchecked to use a single register to hold each value. Note that when you use the Word registers option, our products will only allow access to complete values, and you should add definitions only for the first register used for each value (in the above example, you should define register 100, but not register 101).
Word count. Some Modbus requests (e.g function 3 Read Holding Registers, and function 16 Preset Multiple Registers) include a count of how many registers/values are to be transferred. There are three possible interpretations for this count:
- The number of values to be transferred
- The number of 16-bit words to be transferred
- The number of registers to be transferred
In the official Modbus protocol, these three interpretations are equivalent, since all values and all registers are 16-bit. When 32-bit and 64-bit values and/or registers are allowed, the three interpretations become distinct. However, the third interpretation will be equivalent to one or other of the first two, depending on the Word registers setting, so our producst only deal directly with the first two interpretations. You should check the Word count checkbox if the count is to be interpreted as the number of 16-bit words to be transferred. You should leave the Word count checkbox unchecked if the count is to be interpreted as the number of values to be transferred.
These three options (Little-endian, Word-registers, and Word-count) allow 8 possible variations of 32/64-bit value handling. At least 5 of these variations have actually been used in devices, so you may need to carefully read documentation, or to experiment, to determine which variation a particular device uses.