LogicMachine Forum
Modbus profile - read_count - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: Modbus profile - read_count (/showthread.php?tid=6118)



Modbus profile - read_count - bguillerey - 15.09.2025

Hi,

How to use the read_counter into a MODBUS profile file?

I have a MODBUS water-meter where I can only read the 4 register in one shot.

Register definition is like this:

   

Yeap, I's crazy. Not sure if I can do it by using profile, or I have to use a LUA script...

Thanks

Ben


RE: Modbus profile - read_count - admin - 15.09.2025

You can read multiple registers via a profile but this decimal data type is not supported.
First, use read test to find the correct register address. It can be 40001, 40000 or 0.

Use this script for reading. Keep the relevant RTU port enabled in the Modbus tab. Change device id (2) and address (40001) as needed.
Code:
mbproxy = require('mbproxy')
mb = mbproxy.new()
mb:setslave(2)

r1, r2, r3, r4 = mb:readregisters(40001, 4)

-- read ok
if r1 then
  consumption = r1 + r2 / 10000
  flowrate = r3 + r4 / 10000

  log(consumption, flowrate)
else
  log('read failed', r2)
end