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.

Reading 8 coil points as a 1 byte in Modbus
#3
Hi I got an error when i use this script in log screen.
* table:[2] * string: broadcast read not allowed

What could be the reason ?

Quote:It's not possible to do this via a profile, you will have to use scripts. You can access the same RS485 port from both profiles and scripts using mbproxy.

You can read multiple coils/inputs via a script and convert to a number.
Code:
function bitstonumber(bits)
  local res = 0

  for bnum, bval in ipairs(bits) do
    if bval then
      res = bit.bor(res, bit.lshift(1, bnum - 1))
    end
  end

  return res
end

mb = require('mbproxy').new()
mb:setslave(1)

bits = { mb:readcoils(8, 8) }
if #bits == 8 then
  mode = bitstonumber(bits)
  log(mode)
else
  log(bits)
end

The addressing probably starts from 0 so you have to subtract 1 from the documented addresses.
Temperature will not work with "value_multiplier": 0.1, try using "datatype": "float16" and "bus_datatype": "float16" without "value_multiplier".
Reply


Messages In This Thread
RE: Reading 8 coil points as a 1 byte in Modbus - by savaskorkmaz - 22.12.2021, 12:27

Forum Jump: