The Modbus protocol was designed to operate with devices of 16-bit register length. Consequently, special considerations are required when implementing 32-bit data elements. Most implementations use two consecutive 16-bit registers to represent 32 bits of data, or 4 bytes of data. Within these 4 bytes, single-precision, floating-point data can be encoded into a Modbus RTU message.
Modbus itself does not define floating-point data types, but it is widely accepted that it implements 32-bit floating-point data using the IEEE-754 standard. However, the IEEE standard has no clear definition of the byte order. Therefore, the most important consideration when dealing with 32-bit data is that the data be addressed in the correct order.
The following table shows two adjacent 16-bit registers conversion to a 32-bit floating point or 32-bit integer values:
Register suffix |
Swap mode |
16 – bit registers |
32 – registers floating point or integer |
– |
N/A |
[a b][c d] |
[a b c d] |
s |
Byte and word swap |
[a b][c d] |
[d c b a] |
sb |
Byte swap |
[a b][c d] |
[b a d c] |
sw |
Word swap |
[a b][c d] |
[c d a b] |
The following section describes the 32-bit data types implementation to the mySCADA application.