Logic Machine Forum
modbus variable with 4 memory locations - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: modbus variable with 4 memory locations (/showthread.php?tid=1942)



modbus variable with 4 memory locations - camilo - 04.03.2019

hi.

I currently have a meter that has a modbus variable with 4 memory locations, someone knows how I can convert that variable to 32 bit format or higher
Code:
-- init modbus on first script execution
if not mb then
    require('luamodbus')
    mb = luamodbus.rtu()
    mb:open('/dev/ttyS2', 9600, 'E', 8, 1, 'H')
    mb:connect()
end

-- sets slave ID to read/write data from/to
mb:setslave(20)

-- read 3-phase system voltage from 32-bit register
r1, r2 = mb:readregisters(0x1000, 2)
result = bit.lshift(r1, 16) + r2
grp.write('5/5/1',result)

-- read 3-phase system current from 32-bit register
r1, r2 = mb:readregisters(0x100E, 2)
result = bit.lshift(r1, 16) + r2
grp.write('5/5/2',result)

I was looking at this example, but I can not find out how I can do it 

thank you


RE: modbus variable with 4 memory locations - admin - 04.03.2019

For ModBus the recommended approach is to use mapper with profiles. It supports all kind of numeric values up to 64 bits.


RE: modbus variable with 4 memory locations - camilo - 07.03.2019

Well, I'm new to this, you can explain to me how I could do that or if there is an example that I can take as a reference.


RE: modbus variable with 4 memory locations - admin - 07.03.2019

Check this thread: https://forum.logicmachine.net/showthread.php?tid=839