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
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:

mb = luamodbus.rtu()
mb:open('/dev/RS485-1', 9600, 'N', 8, 1, 'H')
res, err = mb:connect()
if res then
  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)
  log('Umm !!, connection failed : '.. err)

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.
Default swap is "w", try it instead of "n".
(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.
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.
In the script you are reading holding registers not input registers as in the profile. Use mb:readinputregistervalue()
admin, magic, thank you. 
Completely missed that setting

Forum Jump: