21.07.2025, 09:54
Hi,
I strive to add a funtion to automatically map modbus registers to selected group addresses.
The problem it works for registers without bitmask:
but I can't figure out how to make it to work with bitmasks:
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")