26.04.2023, 13:07
Hello all,
I need to split a Modbus register to different bits as you can see from the attached manual starting at page 5 for register 0x0107.
Below the script so far. For example register 0x0107 pH status now returns a number which makes sense as it need to be split to different bits i assume.
Modbus Manual
I need to split a Modbus register to different bits as you can see from the attached manual starting at page 5 for register 0x0107.
Below the script so far. For example register 0x0107 pH status now returns a number which makes sense as it need to be split to different bits i assume.
Modbus Manual
Code:
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485', 19200, 'N', 8, 1, 'H')
mb:connect()
mb:setslave(1)
--Hydrolyse Percentage
value = mb:readregisters(0x0101)
if value then
value = value * 0.1
--log(value)
grp.write('10/0/1', value)
end
--pH waarde
value = mb:readregisters(0x0102)
if value then
value = value * 0.01
--log(value)
grp.write('10/0/2', value)
end
--Rx waarde
value = mb:readregisters(0x0103)
if value then
--log(value)
grp.write('10/0/3', value)
end
--pH status
value = mb:readregisters(0x0107)
if value then
--log(value)
grp.write('10/0/4', value)
end
--Rx status
value = mb:readregisters(0x0108)
if value then
--log(value)
grp.write('10/0/5', value)
end
--Water temperatuur
value = mb:readregisters(0x0106)
if value then
value = value * 0.1
--log(value)
grp.write('10/0/6', value)
end
mb:close()