This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Split Modbus register
#1
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()
Reply
#2
Use value_bitmask in profile
https://forum.logicmachine.net/showthrea...29#pid6729
------------------------------
Ctrl+F5
Reply
#3
(26.04.2023, 13:40)Daniel Wrote: Use value_bitmask in profile
https://forum.logicmachine.net/showthrea...29#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.
Reply
#4
Try this then
https://forum.logicmachine.net/showthrea...7#pid25477
------------------------------
Ctrl+F5
Reply


Forum Jump: