23.09.2017, 08:10
(This post was last modified: 23.09.2017, 08:22 by Erwin van der Zwart.)
Hi,
Try this: ( i think your second port is RS485-2 but please check this )
BR,
Erwin
Try this: ( i think your second port is RS485-2 but please check this )
Code:
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-2', 9600, 'N', 8, 1, 'H')
mb:connect()
mb:setslave(1)
-- L1 - N
r1, r2 = mb:readinputregisters(0, 2)
if r1 then
value = lmcore.inttohex(r1, 2) .. lmcore.inttohex(r2, 2)
value = knxdatatype.decode(value, dt.float32)
currentvalue = grp.getvalue('32/1/1')
if currentvalue ~= value then
grp.update('32/1/1', value)
end
end
-- L2 - N
r1, r2 = mb:readinputregisters(2, 2)
if r1 then
value = lmcore.inttohex(r1, 2) .. lmcore.inttohex(r2, 2)
value = knxdatatype.decode(value, dt.float32)
currentvalue = grp.getvalue('32/1/2')
if currentvalue ~= value then
grp.update('32/1/2', value)
end
end
-- L3 - N
r1, r2 = mb:readinputregisters(4, 2)
if r1 then
value = lmcore.inttohex(r1, 2) .. lmcore.inttohex(r2, 2)
value = knxdatatype.decode(value, dt.float32)
currentvalue = grp.getvalue('32/1/3')
if currentvalue ~= value then
grp.update('32/1/3', value)
end
end
mb:close()
BR,
Erwin