Encode floating-point and 32-Bit data in Modbus RTU Messages

In Data Conversion, incoming data manipulation is a necessary step to create outgoing data. This is done by either joining smaller data types to create a larger data type or splitting larger data types to deliver smaller data types.

In Modbus, 16-bit registers are used to transfer a 32-bit floating-point value. Upon receipt of these two registers, the FieldServer needs to join the integers to extract the floating-point value.

Functions Available for Type Casting:
  • Join_Float , Split_Float
  • Join_Int16, Split_Int16
  • Join_Int32, Split_Int32
  • Swapped versions of the above (Big Endian vs Little Endian)
  • Bit_Extract, Bit_Pack, Bit_Move

The following legacy functions have been replaced by the functions listed above. They are simply presented in the table below for reverse compatibility.


>
Example 1

Moving a preloaded float;

In the data array offset 90, the value stored is 6584.567.

DA_FLOAT, 6584.567 , float, 90

To move this from the server-side to the User’s end we would use the function 1.float-2.i16-sw which takes one float value and splits it to two unsigned 16-bit integers.

DA_FLOAT , 90 , DA_UINT16 , 90 , 44 , 1.float-2.i16-sw

The results on the user end will be two split 16-bit integers represented in hexadecimal as;


To confirm this is right, Chipkin provides its own calculator IEE 754 Calculator FREE


If the data was served as;

DA_FLOAT , 90 , DA_UINT16 , 90 , 44 , 1.float-2.i16

The split 16-bit integers would be swapped as;


Chipkin offers a free Modbus TRU Parser that can be used to check this.

Example 2

In the data array offset 94, the value stored is 2500.2.

DA_FLOAT , 2500.2 , float , 94

The function 1.float-2.i16-sw below takes one float value and splits it to two unsigned 16-bit integers.

DA_FLOAT , 90 , DA_UINT16 , 90 , 44 , 1.float-2.i16-sw

The results on the user end will be two split 16-bit integers represented in hexadecimal as;


Using Chipkin’s IEEE-754 calculator, the results obtained is similar as;



Did you know that we also do Modbus Integration Solutions?

Chipkin has Modbus solutions for almost every situation. We are experts in Modbus RTU/TCP communication and carry a wide variety of Modbus products:

Contact Us

Contact us via phone (+1 866-383-1657) or leave a detailed message below for sales, support, or any other needs

*Required Field
*Required Field
I'd like to receive the newsletter. *Check email for confirmation.
*Required Field
8:00am - 12:00pm 12:00pm - 5:00pm