How to Convert 32-bit IEEE754 Floats in Modbus TCP Using Little Endian - Byte Swap

Question:

Hello, I am currently working on a project involving a Power meter that supports Modbus TCP, with each signal being a 32-bit Float. After testing the float in Modbus Poll, I discovered that the standard used is Little Endian - Byte swap. I have been searching various forums for a solution on how to convert the data, but have not been successful so far. The code I have been using for converting to 32-bit is as follows: ArrayToInt[0] :=MBTCP_1.DATA.ReadData[360]; ArrayToInt[1] :=MBTCP_1.DATA.ReadData[361]; CPS(ArrayToInt[1],DesInt,2); test_real:=DestInt. If anyone has a solution or can provide guidance on this matter, it would be greatly appreciated.

Top Replies

Could you provide an example of two Modbus register values (INT or UINT) in hexadecimal format, along with your estimation of the corresponding REAL value (within Β±10% margin)? It would be even more helpful if you could offer multiple examples of different REAL values.

Can you specify the environment in which the Structured Text is running, such as the manufacturer and model of the PLC being used?

Thank you, @drbitboy, for your interest in my thread. The value is 237,863 with HEX1 at 0x3372 and HEX2 at 0x436E, indicating a voltage range of approximately 236-238 volts. Snapshot 2 shows HEX1 at 0x0EC8 and 0x436E, while Snapshot 3 displays HEX1 at 0xAD46 and 0x436D. I am working on structuring text in Compact Logix L36ER - 32.011, with the Prosoft MBTCP card communicating with the PLC via INT.

Do these data originate from a ProSoft module? If so, along with integer and real values, which Swap Code is currently active (ideally None)?

Yes, that is the correct model, the MVI69E. It has been tested using MBTCP client AOI from Rockwell, with no swaps involved.

It seems like you're trying to convert 32-bit Float Little Endian data to an integer directly, which might be causing issues. I'd suggest doing the following - Instead of converting to an integer, initially decode the data into a 4-byte array where each byte is a part of the float. After rearranging the byte array according to Little Endian, you should use a Float Interpretation Function to convert this byte array to floating point. This should give you the correct float value for your Power meter readings.

From the information you've shared, it seems like you might be experiencing difficulties due to the endianness of your Modbus TCP power meter. Modbus uses Big Endian format, so when your power meter sends the data as Little Endian, it might cause confusion. I suggest swapping the bytes of the 32-bit float from Little Endian to Big Endian before proceeding with data conversion. There are various functions that can help with this byte-swapping process. Please share your coding language so more targeted help can be provided.

More Replies β†’

Streamline Your Asset Management
See How Oxmaint Works!!

βœ…   Work Order Management

βœ…   Asset Tracking

βœ…   Preventive Maintenance

βœ…   Inspection Report

We have received your information. We will share Schedule Demo details on your Mail Id.

To add a comment, please sign in or register if you haven't already..   

Frequently Asked Questions (FAQ)

FAQ: 1. What is the issue with converting 32-bit IEEE754 floats in Modbus TCP using Little Endian - Byte Swap?

Answer: - The issue arises when the standard used for the data is Little Endian - Byte Swap, which requires special handling during conversion.

FAQ: 2. What does the provided code snippet for converting to 32-bit involve?

Answer: - The code snippet involves reading data from Modbus TCP, handling the byte order for Little Endian, and converting it to a 32-bit float.

FAQ: 3. How can one successfully convert 32-bit floats in Modbus TCP with Little Endian - Byte Swap?

Answer: - To successfully convert, one needs to ensure proper byte order manipulation and conversion steps are implemented in the code.

FAQ: 4. Are there any existing solutions or guidance available for handling this conversion challenge?

Answer: - While the user has been searching various forums for a solution, specific guidance or solutions tailored to this exact scenario may be limited. Further collaboration or expert advice might be necessary.

FAQ: 5. What can I do if I encounter difficulties converting 32-bit IEEE754 floats in Modbus TCP with Little Endian - Byte Swap?

Answer: - If facing challenges, consider seeking help from forums, communities, or experts specializing in Modbus TCP and data conversion for guidance and solutions.

Ready to Simplify Maintenance?

Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.

Request Demo  β†’