18.09.2021, 12:15
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
mbetslave(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.
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
mbetslave(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.