Posts: 200
Threads: 60
Joined: Jun 2015
Reputation:
7
Hi,
Is there an grp. script command that will update the value of an object that does not write to the TP or IP bus under any condition. It ONLY changes the value of the object no matter the value of the object. I know you have grp.update and grp.checkupdate.
When you have resident scripts that should change other objects on the event that an groupwrite telegram has been sent to that object AND they also act as the status object. These scripts will continuously run. Both grp.update and grp.checkupate send back a groupwrite telegram. Is there something else just to change the value, without messing with the underlying DB.
Many thanks
Roger
Posts: 8071
Threads: 43
Joined: Jun 2015
Reputation:
470
Can you provide an example of what you are trying to achieve?
Posts: 200
Threads: 60
Joined: Jun 2015
Reputation:
7
Hi
I have the following resident script running, to give the status of a group of lights ( room ). The second script is an event script for controlling that group of lights. Now right now I have to use a separate object which responds with the status.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
if not client then
groups = {
{
tag =
'cinema' ,
output =
'5/2/5' ,
mode =
'avg' },
{
tag =
'living' ,
output =
'5/3/5' ,
mode =
'avg' },
{
tag =
'kitchen' ,
output =
'5/4/5' ,
mode =
'avg' },
{
tag =
'master' ,
output =
'5/5/5' ,
mode =
'avg' }
}
updatedelay =
0.5
values = {}
datatypes = {}
grp.checkupdate =
function (
alias ,
value )
if values [
alias ] ~=
value then
grp.update (
alias ,
value )
end
end
calc = {}
calc [
'tempavg' ] =
function (
group )
local result ,
count ,
value =
0 ,
0 ,
0
for _ ,
address in ipairs (
group.objects )
do
value =
values [
address ]
if type (
value ) ==
'number' then
result =
result +
value
count =
count +
1
end
end
if count >
0 then
result = ((
result /
count )*
9 /
5 ) +
32
local fahren =
math.floor (
result +
0.5 )
grp.checkupdate (
group.output ,
fahren )
end
end
calc [
'avg' ] =
function (
group )
local result ,
count ,
switch ,
value =
0 ,
0 ,
0
for _ ,
address in ipairs (
group.objects )
do
value =
values [
address ]
if type (
value ) ==
'number' then
result =
result +
value
if value >
0 then
count =
count +
1
end
elseif type (
value ) ==
'boolean' then
if toboolean (
value )
then
switch =
switch +
1
end
end
end
if count >
0 then
if result >
0 then
result =
math.floor (
result /
count +
0.5 )
end
grp.checkupdate (
group.output ,
result )
elseif switch >
0 then
grp.checkupdate (
group.output ,
100 )
else
grp.checkupdate (
group.output ,
0 )
end
end
calc [
'and' ] =
function (
group )
local result =
true
for _ ,
address in ipairs (
group.objects )
do
result =
result and toboolean (
values [
address ])
end
grp.checkupdate (
group.output ,
result )
end
calc [
'or' ] =
function (
group )
local result =
false
for _ ,
address in ipairs (
group.objects )
do
result =
result or toboolean (
values [
address ])
end
grp.checkupdate (
group.output ,
result )
end
for _ ,
group in ipairs (
groups )
do
object =
grp.find (
group.output )
values [
object.address ] =
object.data
datatypes [
object.address ] =
object.datatype
group.output =
object.address
group.objects = {}
objects =
grp.tag (
group.tag )
for _ ,
object in ipairs (
objects )
do
values [
object.address ] =
object.data
datatypes [
object.address ] =
object.datatype
table.insert (
group.objects ,
object.address )
end
group.timer =
0
group.fn =
calc [
group.mode ]
end
function eventhandler (
event )
local dst ,
datatype
dst =
event.dst
datatype =
datatypes [
event.dst ]
if not datatype then
return
end
values [
dst ] =
dpt.decode (
event.datahex ,
datatype )
for _ ,
group in ipairs (
groups )
do
for _ ,
address in ipairs (
group.objects )
do
if address ==
dst then
group.timer =
updatedelay
end
end
end
end
require (
'genohm-scada.eibdgm' )
client =
eibdgm :
new ({
timeout =
0.25 })
client :
sethandler (
'groupwrite' ,
eventhandler )
end
tsec ,
tusec =
os.microtime ()
client :
step ()
delta =
os.udifftime (
tsec ,
tusec )
for _ ,
group in ipairs (
groups )
do
timer =
group.timer
if timer then
timer =
timer -
delta
if timer <=
0 then
group.fn (
group )
timer =
nil
end
group.timer =
timer
end
end
Event script
Code:
1 2 3 4 5 6 7 8 9 10 11
if (
event.type ==
'groupread' )
then
grp.response (
event.dst ,
grp.getvalue (
event.dst ))
elseif (
event.type ==
'groupwrite' )
then
grp.write (
'0/2/104' ,
grp.getvalue (
event.dst ),
dt.scale )
grp.write (
'0/2/105' ,
grp.getvalue (
event.dst ),
dt.scale )
if (
event.getvalue ()==
0 )
then
grp.write (
'0/0/107' ,
false ,
dt.bool )
else
grp.write (
'0/0/107' ,
true ,
dt.bool )
end
end
Posts: 4936
Threads: 28
Joined: Aug 2017
Reputation:
225
When you use Virtual groups then the value is not sent to TP or IP. For normal objects write will send to TP and IP , where update will send to IP but not to TP.
------------------------------
Ctrl+F5
Posts: 8071
Threads: 43
Joined: Jun 2015
Reputation:
470
You can also use grp.sender / event.sender to block event script execution when a different script changed the value. See this:
https://forum.logicmachine.net/showthrea...5#pid29215