I need some guidance about floating point numbers coming from modbus RTU, I'm working with RS485 serial interface.
No issues with modbus read. if i just read the values with the modbus read function, i have v1=36260 v2=17056 (??)
m = modbus('serialrtu','COM6','Timeout',5)
It seems that the final value is according the (IEEE 754) but is splited into 2 registers of 16bit. As i'm reading through internet, this is common in modbus protocol since is the maximum a register can hold is 16bit, so they use 2 registers with more and less significant order.
This is information from the datasheet of the metering device.
ModBUS address R/W Description Length (byte) Default value Meaning
140 R VRMS ABC (MSB) [float – 32 bit] 2 0.0 Three-phase RMS voltage [Vrms] (Upper part)
141 R VRMS ABC (LSB) [float – 32 bit] 2 0.0 Three-phase RMS voltage [Vrms] (Lower part)
All values in 32bits are stored into 2 consecutive registers, for example:
VRMS A in floating point 32 bits is stored into registers 40140 and 40141, the Most significant word is the register 40140, the less significant word is the 40141.
So the 32bits value is obtained by the following relation: ???? ?=???40141+(???40140×216)
note! 40140 = read only holding register 140. [same thing in modbus language]
“MS” = Most significant
“LS” = Less significant
“MSB” = Most significant Byte
“LSB” = Less significant Byte
“MSW” = Most significant Word (16 bits)
“LSW” = Less significant Word (16 bits)
“R” = Read only register
“RW” = Read and write register
“Unsigned 16 bits” = Unsigned 16 bits register
“Signed 16 bits” = 16 bits register with sign
“Float 32 bits” = Floating point single precision 32 bits (IEEE 754) register
“0x” = Hexadecimal Value
if i just read the values with the modbus read function, i have v1=36260 v2=17056 (??)
Final comment is that i used for test a modbus poll app https://www.modbustools.com/modbus_poll.html and it represents correctly the value if i change the view settings to Float Inverse - Description: Use this command to display data in floating point format. 2 Registers are used. Hi and Lo registers are swapped. IEEE 754 specification is used. This is representing the value correctly !!
How to get the correct value in matlab as a double numeric value with some decimals? For example 238.34985