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 mappings automation
#1
Hi,

I strive to add a funtion to automatically map modbus registers to selected group addresses.

Code:
function mapModbusRegisterToKnx(knxGA, regNum, regType, valueBitmask)

local sql = string.format(
  "SELECT id FROM modbus_mapping WHERE type='%s' AND address=%d",
  regType, reg
)
local rows = db:getall(sql)
if not rows or #rows == 0 then
  return false
end
local updateFields = {
  bus_address  = gaDec,
  bus_write    = 1,
  value_delta  = 0.1,
  value_custom = "rfid"
}
if valueBitmask ~= nil then
  updateFields.value_bitmask = valueBitmask
end

for _, rec in ipairs(rows) do
  db:update("modbus_mapping", updateFields, { id = rec.id })
  log((" Zaktualizowano Modbus %s[%d] → KNX %s (id=%d)%s")
    :format(
      regType, reg, knxGA, rec.id,
      valueBitmask and (", bitmask=" .. tostring(valueBitmask)) or ""
    )
  )
end
end

The problem it works for registers without bitmask:
Code:
mapModbusRegisterToKnx("60/0/93",1299,"register")


but I can't figure out how to make it to work with bitmasks:
Code:
mapModbusRegisterToKnx("60/0/94",1300,"register", "0x01")
mapModbusRegisterToKnx("60/0/95",1300,"register", "0x02")
Reply


Messages In This Thread
Modbus mappings automation - by pawel200388 - 21.07.2025, 09:54
RE: Modbus mappings automation - by admin - 21.07.2025, 10:04
RE: Modbus mappings automation - by admin - 21.07.2025, 12:54

Forum Jump: