How to convert integer value coming from modbus to float value

Hi i am using energy meter and reading float type value but it is comming as integer in two different byte i want to convert this to float value to make this value usable
Thanks

Look at your flow. You are debugging the modbus node pin 1 but you have connected buffer parser to pin 2.

I am now able to get the values after parser but it is not showing correct like i am reading frequency which is 49.567 hz but value after parser showing wrong value i have tried with 16bit 32bit uint int etc but not getting correct value i am not understanding how to set parser configurition according to our need

For anyone to help, you need to provide the input data and expected output value(s).

You can grab a copy of the input data by using the "copy value" button on the debug output of the modbus data.

Also, show us a screen shot of the buffer parser.

Lastly, do you have a link to the manual and the modbus address you are using? Some modbus devices do not pack the data in IEEE formats (instead use a custom data format)

Hi,
kindly see the parser setting and value which i want to read from energy meter
DPM-C530 Operation Manual (deltronics.ru)


Hi .. and how have you configured the Modbus node ?

One thing i notice from that table is that the first column .. the hex representation of the address
142 hex in decimal is 322 and 143 hex is 323 dec

So as a test can you start reading the two registers needed for the Hz from 322 and Quantity 2

image

and in Buffer parser set as a float

I have successful in getting frequency data by following setting

There should be no need to byte swap the data if you use float BE.

Hi i have displayed this frequency data to dashboard but it is not looking much fancy and showing frequency with its label too i want wo make good visual any one can suggest how to do that or how to correct value upto 4 decimal places
Thanks



text editor setting

  1. Instead of using msg.payload you should be using msg.payload.item1
  2. To format the number on the dashboard use angular pipes How to limit temp display on dashboard to 2 decimals - #3 by Steve-Mcl

Thanks, is ther any batter dashboard or other application which i can use with node red to make its look batter

You can write your own web pages if you wish using whatever web technology you are capable of using. But that is a whole other question. If you are finished with this question then please mark the solution. If you want to ask more about dashboards, please start a new thread.

I wnat to know that how we decide wethere use int16be or float(be) of uint etc in parser the concept is not clear to me
Thanks

To understand that you need to understand the endianess of the modbus device and the byte packing order the device programmer uses.

For example, if the device is supposed to return the hexadecimal value 0x1234 and you get 0x3412 then it is little-endian (or LE)

There are thousands of articles around the internet if you want to go farther down the rabbit hole.

In truth, you often do not know what processor or encoding a device manufacturer uses - so look at the data using BE functions, if it looks wrong try LE or SWAP16 etc until you get sensible data.

This depends on what you are reading and how the device was programmed to provide values. Typically the manual will state "INT" or "INT16" then it will be int16be or int16le. If the manual states "unsigned int" or "unsigned integer" or "UINT" etc then typically chose the UINT16be function. If the manual states float or IEEE 754 then use float (be) or float (le) etc.

A lot of this comes down to experience and training. I have spent more years than I care to mention working with PLCs and hardware devices. If you wish to understand more, then you need to read, read, read & try, try, try.

1 Like

Hi, i have configured the voltage reading too on node red and it was showing correct value but i then restarted my laptop and run nodered now it is showing error on voltage parser see pic and error for referednce
error : Error: data is not an array or a buffer



Same as last time - look at the image you posted...

Also, are you reading values close to each other in modbus?

If you are reading registers 240-241 AND registers 256-257 then I strongly recommend you read all registers from 240~257 in one MODBUS node and use the parser to pick out the values of interest. This has the following advantages....

  1. values are read at the same scan of the device (and are therefore consistent)
  2. reading 1 modbus poll of 28 items is faster than 2 modbus polls. This will only get worse with each additional single read/poll.
  3. Individual modbus comms lead to contention on the wire (and eventually timeouts - search the forum - covered many times)

PS, as I said before...

if i use from 240 to 257 then how to pic perticular two address in parser because i didnt fint any selection there,
Also what is this second dot for in modbus read node as you told i just change dot connection and it is working

Use the offset to access other bytes,

MB address Returns offset byte
240 16 bit integer (2 bytes) 0
241 16 bit integer (2 bytes) 2
242 16 bit integer (2 bytes) 4
243 16 bit integer (2 bytes) 6
244 16 bit integer (2 bytes) 8
245 16 bit integer (2 bytes) 10
246 16 bit integer (2 bytes) 12
247 16 bit integer (2 bytes) 14
248 16 bit integer (2 bytes) 16
249 16 bit integer (2 bytes) 18
250 16 bit integer (2 bytes) 20
251 16 bit integer (2 bytes) 22
252 16 bit integer (2 bytes) 24
253 16 bit integer (2 bytes) 26
254 16 bit integer (2 bytes) 28
255 16 bit integer (2 bytes) 30
256 16 bit integer (2 bytes) 32
257 16 bit integer (2 bytes) 34

e.g...


The second output is for "i dont know but pretty sure it is documented in the built in help for that node" :slight_smile:

1 Like