19.02.2024, 23:40
Hello Admin,
I have multiple modbus energy meters iEM3150 / 3350 where the energy values are int64 in Wh. Although this datatype can be nicely handled by the LM, I would like to present those values on a visualization device that supports int32 or 8byte double (which probably is a f64 value) and or 14byte string. Now as a quick solution I can apply the code below to divide the value by 1000 so get kWh in the end and write it as string to show it in the visualization.
I am wondering since the int64 has a max value of 9223372036854774784 which consists of 19 bytes and - 3 bytes because of /1000 to get value as kWh, leaves us with 16 bytes, there are two bytes that are lost in the string 14bytes translation. Is there a solution to this issue or can we translate the int64 to f64 somehow?
I have multiple modbus energy meters iEM3150 / 3350 where the energy values are int64 in Wh. Although this datatype can be nicely handled by the LM, I would like to present those values on a visualization device that supports int32 or 8byte double (which probably is a f64 value) and or 14byte string. Now as a quick solution I can apply the code below to divide the value by 1000 so get kWh in the end and write it as string to show it in the visualization.
Code:
if not values then
values = {
{ input = '32/1/24', output = '10/0/24' },
{ input = '32/1/25', output = '10/0/25' },
{ input = '32/1/26', output = '10/0/26' }
}
end
for _, value in ipairs(values) do
Wh = grp.getvalue(value.input)
kWh = tostring(Wh / 1000)
grp.checkwrite(value.output, kWh)
end
I am wondering since the int64 has a max value of 9223372036854774784 which consists of 19 bytes and - 3 bytes because of /1000 to get value as kWh, leaves us with 16 bytes, there are two bytes that are lost in the string 14bytes translation. Is there a solution to this issue or can we translate the int64 to f64 somehow?