Logic Machine Forum
Split Modbus register - Printable Version

+- Logic Machine 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: Split Modbus register (/showthread.php?tid=4736)



Split Modbus register - Joep - 26.04.2023

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

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()



RE: Split Modbus register - Daniel - 26.04.2023

Use value_bitmask in profile
https://forum.logicmachine.net/showthread.php?tid=839&pid=6729#pid6729


RE: Split Modbus register - Joep - 26.04.2023

(26.04.2023, 13:40)Daniel Wrote: Use value_bitmask in profile
https://forum.logicmachine.net/showthread.php?tid=839&pid=6729#pid6729

As i'm still facing Invalid CRC errors (see my other thread https://forum.logicmachine.net/showthread.php?tid=4735) So i prefer to use my own Modbus script instead of a Modbus profile. The profile is not getting all the registers as it stops from the first one when receiving an Invalid CRC. The script is still running true so i get the info mostly.


RE: Split Modbus register - Daniel - 26.04.2023

Try this then
https://forum.logicmachine.net/showthread.php?tid=3948&pid=25477#pid25477