20.02.2024, 09:38
(20.02.2024, 09:01)admin Wrote: This example writes a numeric value in double floating point format using raw datatype. If the resulting value is incorrect try removing the line with reverse() call.
Code:val = 123456.67890
ffi = require('ffi')
dst = ffi.new('unsigned char[8]')
src = ffi.new('double[1]')
src[ 0 ] = tonumber(val) or 0
ffi.copy(dst, src, 8)
res = ffi.string(dst, 8)
res = res:reverse()
grp.write('2/2/2', res, dt.raw)
Thank you admin, it worked with reverse() call removed.
Now how can I use this script to be able to process a table?
I want to use the table from the original script because I have around 50 values to process.
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
How this would be then?