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.

Modbus Float32
#1
Hi all need some with a float32 issue. 
When using Modbus profiles like: 
{
"product_code": "Socket Meter",
  "mapping": [
{"name": " Active Power", "bus_datatype": "float32", "datatype": "float32","units": "kWh", "type": "inputregister", "address": 52},
{"name": "Total System", "bus_datatype": "float32", "datatype": "float32","units": "kW", "type": "inputregister", "address": 72}],
  "manufacturer": "Eastron",
  "name": "1Phase Smart Meter",
  "product_range": "SDM-M",
  "description": "Modbus 3 Phase Meter Direct Connect"
}


Works fine and we get the correct values.

But we need to use modbus scripting rather than profiles, so using:

require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-1', 9600, 'N', 8, 1, 'H')
res, err = mb:connect()
if res then
  mbConfusedetslave(1)
  value1 = mb:readregistervalue(52,"float32","n")  --Meter (n=no swap, w=word swap, b=byte swap, bw=byte and word swap)   
  value2 = mb:readregistervalue(72,"float32","n")
log('V1: ' .. value1 .. ' and V2: '..value2)
else
  log('Umm !!, connection failed : '.. err)
end
mb:close()


But not getting any figures (0 only), So I am assuming there must be a conversion problem with bus data type, I need to do as well.
Any suggestion's would be appreciated.
Reply
#2
Default swap is "w", try it instead of "n".
Reply
#3
(18.09.2021, 12:16)admin Wrote: Default swap is "w", try it instead of "n".

Unfortunately, changing n to w didn't sort the problem, any other suggestions.
Reply
#4
Hi admin
Have tried the Read Test using Input Register (#4) Address 52 Data Type Float32 Read Swap Word (CDAB) and all works as expected, but still cant get he script to correctly produce the correct value.

Do you have any other suggestions, or I have missed something in the script.
Reply
#5
In the script you are reading holding registers not input registers as in the profile. Use mb:readinputregistervalue()
Reply
#6
admin, magic, thank you. 
Completely missed that setting
Reply


Forum Jump: