25.12.2022, 09:42
Hi.
Is it possible to write this if condition in a modbus profile for automatic scale the values dependent on how big it is, for easier reading it?
Is it possible to write this if condition in a modbus profile for automatic scale the values dependent on how big it is, for easier reading it?
Code:
-- Total power ever
r1, r2, r3, r4 = mb:readregisters(509, 4)
if r1 then
value = r1 * 0x1000000000000 + r2 * 0x100000000 + r3 * 0x10000 + r4
currentvalue = grp.getvalue('32/1/55')
if tonumber(currentvalue) ~= value then
if value > 999999999 then
units = 'GWh'
value = value / 1000000000
elseif value > 999999 then
units = 'MWh'
value = value / 1000000
else
units = 'KWh'
value = value / 1000
end
value = string.format('%.2f', value) .. units
grp.checkupdate('32/1/55', value)
end
end