21.07.2025, 12:46
Hello admin,
thank you for your fast response. This code is part of a larger solution, in which in the first step I add group addresses, in the second I create a modbus device and attach a status object to it, and in the third I map selected points. It's a kind of "wizard" for my customers.
1. Ok, perfect. I changed it to:
and it works smootly.
2. In fact I tried it as a hex. Now I have conversions, so both versions are OK
3. I know, it was temporary. It's a kind of note that shows me where changes in the database have been saved and where they haven't.
4. Unfortunately I know. For now 1 device is enough, but in the future I'l have to rebuild the code to support more modbus devices. I assume I'll use the device column somehow.
Lastly...
5. Is there any simple way to clear modbus_mapping table?
I have some rubbish left there.
6. As I can see modbus doesn't start on its own. For now my solution was to automatically reboot it, but maybe there is other way?
thank you for your fast response. This code is part of a larger solution, in which in the first step I add group addresses, in the second I create a modbus device and attach a status object to it, and in the third I map selected points. It's a kind of "wizard" for my customers.
1. Ok, perfect. I changed it to:
Code:
(...)
if valueBitmask ~= nil then
sql = string.format(
"SELECT id FROM modbus_mapping WHERE type='%s' AND address=%d AND value_bitmask='%s'",
regType, regNum, valueBitmask
)
else
sql = string.format(
"SELECT id FROM modbus_mapping WHERE type='%s' AND address=%d",
regType, regNum
)
end
(...)
local rows = db:getall(sql)
2. In fact I tried it as a hex. Now I have conversions, so both versions are OK

3. I know, it was temporary. It's a kind of note that shows me where changes in the database have been saved and where they haven't.
4. Unfortunately I know. For now 1 device is enough, but in the future I'l have to rebuild the code to support more modbus devices. I assume I'll use the device column somehow.
Lastly...
5. Is there any simple way to clear modbus_mapping table?

6. As I can see modbus doesn't start on its own. For now my solution was to automatically reboot it, but maybe there is other way?