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.

Modbus slave address/bit
#1
How do I define a bit number to an address?

51/0/0 should be bit 1
51/0/1 should be bit 2

mb.setswap('w')
mb.setfloat16precision(2)

mb.setmapping({
  ['*'] = {
    registers = {
      [12288] = '51/0/0',
      [12288] = '51/0/1',
    }
  }
})
Reply
#2
For bits you should use coli.
------------------------------
Ctrl+F5
Reply
#3
I´m trying to replicate exact modbuss points for a client, so we don´t have to change anything on their end.
We have 10 points first one 1288bit1 second 12288bit2 etc but how do I define that in the modbus slave script?
Reply
#4
Register is just 2 byte value regardless of what value you write. This script allows only using numeric objects for registers so you must use extra script which will convert your bits into single value you use on this register.
------------------------------
Ctrl+F5
Reply
#5
You don't have a script where I can set the bit mask in a register?
So that i write a boolean value to a single bit in a holding register instead of converting to an int?
Reply
#6
For master mode use profile together with value_bitmask and write_bitmask fields.
Reply
#7
But I can't set the LM up as SLAVE and define a bool value to bitmask in holding register?
Reply
#8
Use this, fill the bits table as needed (keys are from 0 to 15 for a single register):
Code:
bits = {
  [0] = '0/0/1',
  [1] = '0/0/2',
  [2] = '0/0/3',
}

res = 0

for nr, addr in pairs(bits) do
  val = grp.getvalue(addr)
  if val then
    res = res + bit.lshift(1, nr)
  end
end

grp.checkwrite('0/0/5', res)

Add a common tag to all input group addresses and map an event script to this.
Reply


Forum Jump: