Page 1 of 1

MODBUS question about sending value

Posted: Tue Dec 13, 2022 5:46 am
by chikichaka
I'm developing MODBUS slave device.
so I would like to send float value like 0.123.
I tried to send value to master by MODBUS example from IDF.
Is this right?
Whenever I send 0.xxx, master device read like 0.xxxxxx
Is there anyway that I send just 0.xxx
https://ibb.co/M6DtwwB

Re: MODBUS question about sending value

Posted: Mon Dec 19, 2022 2:11 pm
by ESP_alisitsyn
Hello, @chikichaka ,

Unfortunately, it is not possible to get exactly the same floating point value on these two different platforms.
The ModbusPoll is compiled on Windows and uses the Visual Studio floating point library. The ESP-Modbus uses the gcc compiler with its floating point library. The difference can be hidden in floating point library or in the printf() implementations of the used c libraries. The Windows one prints only 17 significant digits or so, and fills with zeros if more are requested. glibc's prints the correctly rounded value.
The result is the 4 byte IEE754 floating point value is represented differently on these two platforms.