29.06.2021, 09:30
Hi,
I have a DSE7320 power generator controller and i need to read some alerts.
I use Modbus mapper to store the alert registers to virtual objects and then decode them with script.
Can someone please verify if this is the most eficient way or sugest something better?
Thank you in advance
George
I have a DSE7320 power generator controller and i need to read some alerts.
I use Modbus mapper to store the alert registers to virtual objects and then decode them with script.
Code:
dword ='0x'.. event.datahex
myobject = grp.find(event.dstraw)
function getbit(value, nr)
value = bit.rshift(value, nr)
return bit.band(value, 1)
end
for i = 0, 15, 4 do
obj=math.floor((i+1)/4)
msg=''
val=''
for x = 0, 3, 1 do
ix=i+x
val = getbit(dword,ix)..val
end
bin = string.reverse(val)
local sum = 0
for i = 1, string.len(bin) do
num = string.sub(bin, i,i) == "1" and 1 or 0
sum = sum + num * math.pow(2, i-1)
end
msg=msg .. ' Bin:'..val..' Dec:'.. sum
obj=obj..msg
alert(myobject.name..'-'..obj)
end
Can someone please verify if this is the most eficient way or sugest something better?
Thank you in advance
George