Logic Machine Forum
Event Scripting - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Event Scripting (/showthread.php?tid=4654)



Event Scripting - Ibrahim - 17.03.2023

Hello,

I have 160 modbus points and I am using an event script to combine in groups of two as below. Do I need to write this script to each point or is there a short way to do this?

Thanks.

Code:
value1 = event.getvalue()
value2 = grp.getvalue('34/1/15')

if (value1 == 0 ) then
grp.write('34/1/35', 0)

elseif (value1 == 1 and value2 == 0) then
  grp.write('34/1/35', 1)

elseif (value1 == 1 and value2 == 85) then
  grp.write('34/1/35', 2)
end



RE: Event Scripting - admin - 17.03.2023

It can be a single event script mapped to a tag. All related group addresses must follow a certain pattern so other addresses can be calculated from the address that triggered the event. The easiest way is to use a different middle group address. Like in this example: https://forum.logicmachine.net/showthread.php?tid=4484&pid=28970#pid28970


RE: Event Scripting - Ibrahim - 17.03.2023

Hi admin,

Thanks for your reply. How can be an event script mapped to a tag?


RE: Event Scripting - Erwin van der Zwart - 17.03.2023

Add a tag to your object(s), create an event based script and attach it to the TAG in the dropdown box, they are all the way at the bottom under the object addresses


RE: Event Scripting - Ibrahim - 17.03.2023

I could not do it. Can you do an example for my group addresses below;

g1-input1:34/1/1
g1-input2:34/1/15
g1-output:34/1/35
---
g2-input1:34/1/2
g2-input2:34/1/16
g2-output:34/1/36
-----
g3-input1:34/1/51
g3-input2:34/1/65
g3-output:34/1/85
-----
g4-input1:34/1/52
g4-input2:34/1/66
g4-output:34/1/86


RE: Event Scripting - admin - 17.03.2023

event.dstraw can be used for this. Be careful not to create am infinite script loop. Only input1 objects must be mapped to the event script tag.
Code:
value1 = event.getvalue()

addr2 = event.dstraw + 14
value2 = grp.getvalue(addr2)

outaddr = event.dstraw + 34

if value1 == 0 then
  grp.write(outaddr, 0)
elseif value1 == 1 and value2 == 0 then
  grp.write(outaddr, 1)
elseif value1 == 1 and value2 == 85 then
  grp.write(outaddr, 2)
end



RE: Event Scripting - Ibrahim - 17.03.2023

Thanks admin,

Last thing is if only the value2 changes when value1 is 1, the output should change but now not changing. How can this be added?


RE: Event Scripting - admin - 17.03.2023

You will need another similar script mapped to input 2 groups.
Code:
value2 = event.getvalue()

addr1 = event.dstraw - 14
value1 = grp.getvalue(addr1)

outaddr = event.dstraw + 20

if value1 == 0 then
  grp.write(outaddr, 0)
elseif value1 == 1 and value2 == 0 then
  grp.write(outaddr, 1)
elseif value1 == 1 and value2 == 85 then
  grp.write(outaddr, 2)
end



RE: Event Scripting - Ibrahim - 17.03.2023

Thank you for your support.
Regards.