25.02.2021, 07:35
It's strange that you get "invalid data" first. This might indicate that the device is faulty.
I've made a mistake in the previous test script so it does not log communication in case of an error. Run this and post what you get in Logs tab:
I've made a mistake in the previous test script so it does not log communication in case of an error. Run this and post what you get in Logs tab:
Code:
if not mb then
require('luamodbus')
mb = luamodbus.tcp()
mb:setresponsetimeout(5)
mb:open('10.36.0.25', 502)
res, err = mb:connect()
if res then
buffer = {}
mb:setdebug(function(msg)
buffer[ #buffer + 1 ] = msg
end)
else
log('modbus connect failed ' .. tostring(err))
mb:close()
mb = nil
end
end
if mb then
reg10240, reg10241, reg10242, reg10243, reg10244, reg10245, reg10246, reg10247 = mb:readregisters(10240, 8)
if reg10240 then
mains_l1_voltage = reg10240 / 10
mains_l2_voltage = reg10242 / 10
mains_l3_voltage = reg10244 / 10
genset_l1_voltage = reg10246 / 10
log('voltage values', mains_l1_voltage, mains_l2_voltage, mains_l3_voltage, genset_l1_voltage)
else
log('modbus read failed ' .. tostring(reg10241))
mb:close()
mb = nil
end
log(table.concat(buffer))
buffer = {}
end