This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Combine Modbus High Byte and Low Byte
#1
Hi,
We are trying to read a float 4 byte temperature point from a modbus tcp device. We can read via other modbus plc's like 32, 11 degree. 
But when we use LM we are getting high byte and low byte from different registers. Our temperature registers are 0 , 2, 4. But we are getting values from both 0 and 1. 
Example :
Register 0 : 16896
Register 1 : 30915
We realized that those are high and low byte of our  4 byte point. If we combine them as a float manually in excel, it's : 3,2117931E+01 and that is our temperature.

In our profile , point type float32 and point type register.

What we can do ? How we can read as a single point ?

Regards,
Reply
#2
There's a built-in conversion function that can be used. The more simple way is to use a profile and set "datatype" field to "float32".
Code:
require('luamodbus')
value = luamodbus.convert('float32', 16896, 30915)
log(value)
Reply
#3
Hi , we already use float32 in profile. But we will try one more time.
Reply
#4
Hi there,

We can read the correct temperature value using modbus tool with display float32 - big endian mode. (Please see Attached float32modbuspool.jpg )
Using your script, we can combine 2 values. But we dont want use 1000 scripts.

Our modbus profile is :

{ "name": "Group1_BLine1_Node001_L2H_Temp", "bus_datatype": "float32", "type": "register", "address": 0  },

How we can read using only profile method ?

Regards,

Attached Files Thumbnail(s)
   
Reply
#5
You must set datatype field as well:
Code:
{ "name": "V1", "bus_datatype": "float32", "datatype": "float32", "type": "register", "address": 0  },
{ "name": "V2", "bus_datatype": "float32", "datatype": "float32", "type": "register", "address": 2  },
{ "name": "V3", "bus_datatype": "float32", "datatype": "float32", "type": "register", "address": 4  }
Keep in mind that float32 value uses 2 registers so the next value address is previous + 2.
Reply


Forum Jump: