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.

https://cdn.chipkin.com/assets/uploads/2022/Feb/image_21-16-33-13.png

>
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;

https://cdn.chipkin.com/assets/uploads/2022/Feb/image_21-16-33-56.png

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

https://cdn.chipkin.com/assets/uploads/2022/Feb/image_21-16-34-32.png

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;

https://cdn.chipkin.com/assets/uploads/2022/Feb/image_21-16-35-31.png

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;

https://cdn.chipkin.com/assets/uploads/2022/Feb/image_21-16-36-06.png

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


https://cdn.chipkin.com/assets/uploads/2022/Feb/image_21-16-37-08.png

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:

https://cdn.chipkin.com/assets/uploads/2022/Apr/QS-3XX0-2xx0-1XX0-SQ-NB 500pxls_13-18-44-12.png

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
Message Sent Successfully