14.02.2020, 12:47
(14.02.2020, 12:15)admin Wrote: Example can be changed to accept any number of input objects.
If you want to convert boolean value to a number you can do this via an event script (1/1/2 is output object):
Code:value = event.getvalue()
out = value and 1 or 0
grp.write('1/1/2', out)
Sorry, I explain all my situation so I can understand all better.
I have created a script that read all the bit of a register (in this case the register 1280):
Code:
require("user.GetBit")
local value
local Status
local Byte -- Matrice di valori
--- Modbus ---
mb = require('mbproxy').new()
mb:setslave(1)
-- Lettura variabili ——
Status= mb:readregisters(1280) ---- Byte
--log (Status)
if Status ~= nil then
Byte = {getbit(Status, 0),
getbit(Status, 1),
getbit(Status, 2),
getbit(Status, 3),
getbit(Status, 4),
getbit(Status, 5),
getbit(Status, 6),
getbit(Status, 7),
getbit(Status, 8),
getbit(Status, 9),
getbit(Status, 10),
getbit(Status, 11),
getbit(Status, 12),
getbit(Status, 13),
getbit(Status, 14),
getbit(Status, 15)
}
log (Status)
for i=0, 16, 1 do
grp.update ('Stato.reg.1280_Bit' .. i ,Byte[i+1])
end
end
mb:close()
Now I have to command the Bit0 of the register n°1280 with a boolean value.
Can you please write me all the script, so I can write it for the other commands.
Thank you very much and sorry for bothering you.